C Sharp CODES

STARTING FROM BASIC:

1.
TO WRITE A LINE ON CONSOLE APPLICATION :

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

namespace ConsoleApplication35
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Terrorism has no religion");
        }
    }
}
//////////////////////////////////////////////////end//////////////////////////////////////////////////////////
if we use Console.Write(""); the cursor will not go to the next line ... Explore yourself


2.  OBJECTIVE:
                     WRITE a Programme in a c# by Using Writeline and Readline and print 2nd equation of motion.

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

namespace Home-2
{
    class Program
    {
        static void Main(string[] args)
        {
            int Vi, t;
            const double a = 9.8;
            double S;
            Console.WriteLine(" please enter initial velocity");
            Vi = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("please enter time");
            t = Convert.ToInt32(Console.ReadLine());
            S = Vi + (0.5 * a * t * t);
            Console.WriteLine(" with initial velocity {0} and time {1} , Displacement is {2}", Vi, t, S);
        }
    }
}
/////////////////////////////////////////////////////////////////////////////////////////
3. OBJECTIVE:
                       Write a Programme in c# by using Writeline and Readline and print Area of Rectangle.


CODE:
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;

namespace HomE 4;
{
classProgram
    {
staticvoid Main(string[] args)
        {

int l, W;
double A;
Console.WriteLine("Please enter length");
            l = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please enter width");
            W = Convert.ToInt32(Console.ReadLine());
            A = l * W;
Console.WriteLine("with Length {0}and Width {1}The Area of Rectangle is {2}", 1, W, A);

        }
    }
}

4.   OBJECTIVE:  Write a Programme in C# by using  Writeline and Readline  and  Find Hyp.

CODE:
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;

namespace home_8a
{
classProgram
    {
staticvoid Main(string[] args)
        {

double b, p, h, sqh;
Console.WriteLine("Please enter per");
            p = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Please enter base");
            b = Convert.ToDouble(Console.ReadLine());
sqh = p * p + b * b;
            h = Math.Sqrt(sqh);
Console.WriteLine("hyp is{0}", h);
        }
    }
}


5. OBJECTIVE: Write a programme in C# by using Writeline and Readline and print Quardatic Equation.


CODE:
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;

namespace home_9
{
classProgram
    {
staticvoid Main(string[] args)
        {

double a, b, c, x, y, z;
Console.WriteLine("Please enter a");
            a = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Please enter b");
            b = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Please enter c");
            c = Convert.ToDouble(Console.ReadLine());
            y = Math.Sqrt((b * b) - (4 * a * c))/(2*a);
            x = ((-1) * b + y) / (2 * a);
            z = ((-1) * b + y) / (2 * a);
Console.WriteLine("x is {0}", x);
Console.WriteLine("z is {0}", z);          

        }
    }
}\
/////////////////////////////////

if STATEMENT:


OBJECTIVE:  Write a program in c# and Enter the month name the result will be shown the season that you are enjoying.
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;

namespace ConsoleApplication4
{
classProgram
    {
staticvoid Main(string[] args)
        {
string month;
Console.WriteLine("Enter the month");
month = Convert.ToString(Console.ReadLine());
if((month== "january") || (month == "febuaray") || (month == "march"))
            {
Console.WriteLine("The season is Winter");
            }

if
               ((month== "Aprail")|| (month == "may") || (month == "june"))
            {
Console.WriteLine("The season is Summer");
            }
if ((month== "july")|| (month == "August") || (month == "september"))
            {
Console.WriteLine("The season is Spring");
            }
if((month=="October")|| (month == "Novenber") || (month == "December"))
            {
Console.WriteLine("The season is Autumn");
            }
        }
    }
}

2. OBJECTIVE:  Write a program in c# and find For which field you are eligible to take admission.





CODE:
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;

namespace ConsoleApplication3
{
classProgram
    {
staticvoid Main(string[] args)
        {
double branch, per;
char op;
Console.WriteLine("Please enter have you cleared Inter?");
op = Convert.ToChar(Console.ReadLine());
Console.WriteLine("Please enter Which branch do you belong to? \n for pre engg press 1\n for commerce press 2");
branch = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("percentage?");
per = Convert.ToDouble(Console.ReadLine());
if ((op == 'Y') && (branch == 1) && (per >= 60))
            {
Console.WriteLine("You can take adm in BSE, BS(CS) and BBA");
            }
else
if ((op == 'Y') && (branch == 2) && (per >= 50))
                {
Console.WriteLine("You can take adm only in BBA");
                }
        }
    }
}


No comments:

Post a Comment