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:


Make a c# Class that have Two METHODS getData() And display()....using Classes And Methods

INPUT:


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

namespace ConsoleApplication2
{
    class Program
    {
     
        static void Main(string[] args)
        {
           
            Computer c = new Computer();
            c.GetData();
            c.Display();
          
           
        }
        class Computer
        {
            string Colour;
            int Model;
            int ScreenSize;
            public void GetData()
            {

                Console.WriteLine("Plz Enter Colour");
                Colour = Console.ReadLine();
                Console.WriteLine("Plz Enter Model");
                Model = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Plz Enter The Screen Size");
                ScreenSize = Convert.ToInt32(Console.ReadLine());

            }
           
            public void Display()
            {

              
                Console.WriteLine("Computer Colour in {0}",Colour);
                Console.WriteLine("Computer Model  in {0}", Model);
                Console.WriteLine("Computer Model  in {0}",ScreenSize);
              

            }
        }
    }
}

OUTPUT:


Write a program in C# and find the value of final velocity by using S= (〖Vf〗^2-〖Vi〗^2)/2a.

INPUT:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication20
{   
class myclass
    {
        public double visquare(double vi)
        {
            double s = vi *vi;
            return s;
        }
        public double vfsquare(double vf)
        {
            double s = vf * vf;
            return s;
        }
        public double  s(double  vf,double vi)
    {
        double s = (vfsquare(vf) + visquare(vi)) / (2 * 9.98);
        return s;
    }
        static void Main(string[] args)
        {
            double vf,vi;
            Console.WriteLine("plz enter the final  velocity");
            vf=Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("plz enter the initial velocity ");
            vi= Convert.ToDouble(Console.ReadLine());
            myclass m = new myclass();
         
          Console.WriteLine("vf = (vi2+vf2)/2a = {0}",m.s(vf,vi));
        }  
    }
}

OUTPUT:


Write a program in C# and find the value of final velocity by using Vf=Vi+at using methods.

Solution:

Pseudo Code:

  1. Initialize variable "vi"  (this will hold initial velocity value) 
  2. Initialize variable "t" to (this will hold time value) 
  3. Print message on console to ask user to input Initial velocity.
  4. Read user's input and convert to Double and store that input into variable "vi" that is necessary for velocity formula.
  5. Print message on console to ask user to input Time.
  6. Read user's input and convert to Double and store that input into variable "t" that is necessary for velocity formula.
  7. create a separate function "calculateFinalVelocity" that will calculate velocity on the basis of initial velocity and time values and will return the final velocity, then  call "calculateFinalVelocity(vi,t)" function and pass "vi" and "t".  
  8. Print the return value of  on console to show the final velocity...

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication20
 {
class myclass
    {
        public double  calculateFinalVelocity(double  vi,double t)
        {
            double vf =  vi+t*9.98;
            return vf;
        }
        static void Main(string[] args)
        {
            double vi,t;
            Console.WriteLine("plz enter the initial velocity");
            vi=Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("plz enter the time ");
            t= Convert.ToDouble(Console.ReadLine());
            myclass m = new myclass();
         
          Console.WriteLine("the the final velocity is {0}",m.calculateFinalVelocity(vi,t));
        }
        
    }

}

Output:


Write a program that Calculate areas of rectangle using methods.

INPUT:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication20
{
class myclass
    {
        public double  method(double h,double w)
    {
        double Ar = h * w;
        return Ar;
    }
        static void Main(string[] args)
        {
            double h,w;
            Console.WriteLine("plz enter the height");
            h=Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("plz enter the wdth");
            w= Convert.ToDouble(Console.ReadLine());
            myclass m = new myclass();
         
          Console.WriteLine("the Area of the circle is {0}",m.method(h,w));
        }
        
    }
}


OUTPUT: