Pages

Write A PROGRAMME TO FIND THE FECTORIAL NUM OF THE GIVEN INPUT.(USING FOR LOOP)

Solution:

Pseudo Code:

  1. Initialize variable "num" to 1
  2. Initialize  variable "factorial" to 1
  3. Print message on console to ask user for a number to know its factorial
  4. Read user's input and convert to Integer and store that input into variable "num" that is necessary for factorial calculation 
  5. Start While loop till variable "num" value is grater then 1 (because initial value would be the user's input number)
  6. In each while loop  add the product of   "factorial" and "number" into "factorial"
  7. In each while after adding the factorial value , reduce the variable "num" by 1 so that once variable "num" value would reach to 1 then while loop will end. 
  8. Print the variable "factorial" on console to show the calculated factorial..

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            int num, factorial = 1;
            Console.WriteLine("please enter the num  to whom u want to know the factorial");
            num = Convert.ToInt32(Console.ReadLine());
            while (num > 1)
            {
                factorial = factorial * num;

                num = num - 1;
            }

            Console.WriteLine("the factorial of the num is {0}", factorial);
        }

    }
}


OUTPUT:


Write a programme to take input item price and item quantity and make a voucher slip with discount. USING Arrays

INPUT:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication23
{
    class Program
    {
        static void Main(string[] args)
        {
                        int allpprice, sumarray = 0, loop = 1, summofall = 0;
            string dowhile;
            do
            {
           string[] aritemname = new string[1];
            int[] arunitprice = new int[1];
            int[] arquantity = new int[1];
            int[] aritemprice = new int[1];
                Console.WriteLine("enter the {0} item name ",loop);
                aritemname[0] = Console.ReadLine();

                Console.WriteLine("enter the  unit price of  {0} ", aritemname[0]);
                arunitprice[0] = Convert.ToInt32(Console.ReadLine());

                Console.WriteLine("enter the quantity of  {0}  ", aritemname[0]);
                arquantity[0] = Convert.ToInt32(Console.ReadLine());

               
                aritemprice[0] = arunitprice[0] * arquantity[0];
              

                sumarray = sumarray + aritemprice[0];
                Console.WriteLine("do you want to purchase more items ");
                dowhile = Console.ReadLine();
                loop++;
            }
               while(dowhile!= "n");
           
            allpprice = sumarray;
           
            summofall = summofall + allpprice;
            Console.WriteLine("the total price of all products  {0}",summofall );



        }
    }
}   

OUTPUT:


WRITE A PROGRAMME TO SAVE PLAYERS NAME AND SEARCH THEIR ARAY INDEX NUM: BY LINEAR SEARCHING METHOD

INPUT:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Linear_Searching
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("\t\t\t\tPlayer Find");
            string[] player = new String[5];
            string search;
            for (int X = 0; X < 5; X++)
            {
                Console.WriteLine("Enter The Name Of Player {0}",X+1);
                player[X] = Console.ReadLine();

            }
            Console.WriteLine("Which Position U Want To Search");
            search = Console.ReadLine();
            for (int B = 0; B < 5; B++)
            {
                if (player[B] == search)
                {
                    Console.WriteLine("Player Position {0}", B + 1);
                }
            }
        }
    }
}



OUTPUT: