Posts

Showing posts from October, 2023

Check Total Days in Month and The Year Is Leap or Not in c# using Switch-Case.

  CODE:  Console.WriteLine("Enter Year:");             int year = Convert.ToInt32(Console.ReadLine());             Console.WriteLine("Enter Month Which Do You Want To Check:");             int month = Convert.ToInt32(Console.ReadLine());             switch (month)             {                 case 1:                     Console.WriteLine("The Month is January Total days in this month is 31");                     break;                 case 2:                     if ((year%4==0 && year%100 !=0)||year%400==0)                     {                         Console.WriteLine("{0} Year is leap",year);                         Console.WriteLine("days in this month is 29");                     }                     else                     {                         Console.WriteLine("{0} Year is not leap", year);                         Console.WriteLine("days in this month is 28");                     }            

Bahria Payment system give discount to selected student in c#. using switch case

 CODE: using System; public class HelloWorld {     public static void Main(string[] args)     {                      Console.WriteLine("\t\"Welcome To Bahria University Payment System\"");             Console.WriteLine("Enter Your Total Fees:");             double fees = double.Parse(Console.ReadLine());             Console.WriteLine("\nSelect Catagory in Which You Belong");             Console.WriteLine("1.Naval Background");             Console.WriteLine("2.Armed Force");             Console.WriteLine("3.Sibling");             Console.WriteLine("4.Orther Students");                        double choose = double.Parse(Console.ReadLine());             double discount=0;             switch (choose)             {                   case 1:                      discount = fees * 0.5;                     break;                 case 2:                      discount = fees * 0.3;                     break;        

Calculate Area of Circle , Rectangle, Triangle, square in switch-case in c#.

 CODE:   using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Switch_Case_practise {     class Program     {         static void Main(string[] args)         {             double area=0;             Console.WriteLine("Choose Shape To Calculate It Area:");             Console.WriteLine("1.Circle");             Console.WriteLine("2.Square");             Console.WriteLine("3.Ractangle");             Console.WriteLine("4.Triangle");             int choise = int.Parse(Console.ReadLine());             switch (choise)             {                 case 1:                     Console.WriteLine("Enter Radius Of Circle:");                     double radius = Convert.ToDouble(Console.ReadLine());                     area = Math.PI * Math.Pow(radius, 2);                     Console.WriteLine("Area of Circle: {0}",area);                     break;            

Repeatedly print the value of the variable xValue, decreasing it by 0.5 each time, as long as xValue remains positive in c#.

 CODE: using System; public class HelloWorld {     public static void Main(string[] args)     {         double xValue;               Console.WriteLine("Enter xValue Which you want to Check:");               xValue = Convert.ToDouble(Console.ReadLine());               for (; xValue > 0; xValue -= 0.5)               {                   Console.WriteLine("The xValue:{0}",xValue);               }               Console.WriteLine("The xValue is no longer Positive ");      } }

Make a game in C#, in which give 5 tries to the user to guess the value of the number.

 CODE: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace For_Loop_lab6 {     class Program     {         static void Main(string[] args)         {             DateTime dt = DateTime.Now;             Console.WriteLine("{0}", dt);              int secnum = 10;             int tries = 5;             int usetries = 0;             for (int i = 1; i <=tries; i++)             {                 Console.WriteLine("Enter Guessed Number:");                 int gesnum = Convert.ToInt32(Console.ReadLine());                 usetries++;                 if (gesnum == secnum)                 {                     Console.WriteLine("\"Congratulation you won this game\"");                     break;                 }                 else                 {                     Console.WriteLine("You Enter Wrong Number try again");                 }                 if(tries==usetr

Print Star Pattern in c# . for Loop.

Image
 

Print the square roots of the first 25 odd positive integers. IN C#

Image
  Print the square roots of the first 25 CODE: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;   namespace For_Loop_lab6 {     class Program     {        static void Main( string [] args)         {        DateTime dt = DateTime.Now;             Console.WriteLine( "{0}" ,dt);            int n = 25;             double result,odd;             for ( int i = 1; i <=25; i++)             {                 odd = 2*i-1;                 result = Math.Sqrt(odd);                 Console.WriteLine( "Square Root of {0} is {1}" ,odd,result);             }           }     } }

Square Series without using power maths function (use For loop) IN C#.

Square Series CODE:  using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace For_Loop_lab6 {     class Program     {         static void Main(string[] args)         {             DateTime dt = DateTime.Now;             Console.WriteLine("{0}",dt);             int num,result;             Console.WriteLine("Enter Random Number:");             num = Convert.ToInt32(Console.ReadLine());             for (int i = 1; i <= num; i++)             {                 result = i*i;                 Console.WriteLine("Cube Root of {0} is {1}",i,result);             }         }     } }

Cube series without using power maths function in c#.

 Cube series: Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace For_Loop_lab6 {     class Program     {         static void Main(string[] args)         {             DateTime dt = DateTime.Now;             Console.WriteLine("{0}",dt);             int num,result;             Console.WriteLine("Enter Random Number:");             num = Convert.ToInt32(Console.ReadLine());             for (int i = 1; i <= num; i++)             {                 result = i*i*i;                 Console.WriteLine("Cube Root of {0} is {1}",i,result);             }         }     } }

Write a Program using nested ifs in c#.

Write a Program using nested ifs in which the user is asked:   code: using System; namespace HelloWorld {   class Program   {     static void Main(string[] args)     {        DateTime dt = DateTime.Now;             Console.WriteLine("{0}", dt);             Console.WriteLine("user wants to play the game /n Guess (yes or no)");             string playgame = Convert.ToString(Console.ReadLine());             if (playgame == "yes")             {                 Console.WriteLine("Enter Your Age:");                 int age = Convert.ToInt32(Console.ReadLine());                 if (age < 5)                 {                     Console.WriteLine("You are too young to play.");                 }                 else                 {                     Console.WriteLine("Enter any number:");                     int usernumber = int.Parse(Console.ReadLine());                     int secretnumber =123;                     if (usernum

Create simple application which will check the vowel using switch case

Image
Create simple application which will check the vowel using switch case    code:  char ch;             Console.WriteLine("Enter Letter To Check:");             ch = Convert.ToChar(Console.ReadLine().ToLower());             switch (ch)             {                 case 'i':                     Console.WriteLine("i is vowel Alphabet");                     break;                 case 'a':                     Console.WriteLine("a is vowel Alphabet");                     break;                 case 'o':                     Console.WriteLine("o is vowel Alphabets");                     break;                 case 'u':                     Console.WriteLine("u is vowel Alphabets");                     break;                 case 'e':                     Console.WriteLine("e is vowel Alphabets");                     break;                 default:                     Console.WriteLine("{0} i

Create a simple calculator using if else condition in which you will take two number as input in c#.

  Create a simple calculator using if else condition in which you will take two number as input and ask user which operation he/she wants to perform. COD E: using System; public class Simple Calculator {     public static void Main(string[] args)     {          DateTime dt = DateTime.Now;             Console.WriteLine("{0}",dt);             Console.WriteLine("=====Simple Calculator=====");             int num1, num2;             Console.WriteLine("Enter First Number:");             num1 = Convert.ToInt32(Console.ReadLine());             Console.WriteLine("Enter Second Number:");             num2 = Convert.ToInt32(Console.ReadLine());             Console.WriteLine("----Arithmetical Operaters----");             Console.WriteLine("1.Addition");             Console.WriteLine("2.Substraction");             Console.WriteLine("3.Multiplication");             Console.WriteLine("4.Division");             c

Create a simple program to check whether the no is even or odd in c#.

Image
 Create a simple program to check whether the no is even or odd: output: code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace lab_5_paractise_if_else_switch_case_ {     class Program     {         static void Main(string[] args)         {             int num = 0, even = 0, odd = 0;             for (int cnt = 0; cnt <= 5; cnt++)             {                 Console.WriteLine("Enter Number:");                 num = Convert.ToInt32(Console.ReadLine());                 if (num % 2 == 0)                 {                     Console.WriteLine("Number is even:{0}", num);                     even++;                 }                 else                 {                     Console.WriteLine("Number is odd:{0}", num);                     odd++;                 }                 Console.WriteLine("Even Number:{0}", even);                 Console.WriteLine("Number is

Comparing Marks of Three Subjects Using If-Else Statement in c#

Image
 Comparing Marks of Three Subjects output: CODE: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace if_else_condition {     class Program     {         static void Main(string[] args)         {             int m, p, c;             Console.WriteLine("Enter marks of Math:");             m = int.Parse(Console.ReadLine());             Console.WriteLine("Enter marks of Physics:");             p = Convert.ToInt32(Console.ReadLine());             Console.WriteLine("Enter marks of Chemistry:");             c = Convert.ToInt32(Console.ReadLine());             if (m > p)             {                 if (m > c)                 {                     Console.WriteLine("Mark of Maths is Highest:{0}", m);                 }                 else { Console.WriteLine("Mark of Chemistry is Highest:{0}", c); }             }             else if (c > p)             {        

Simple Calculator Using Switch Statement in c#.

Image
  Simple Calculator Using c#: output: code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace calculator_using_switch_satement {     class Program     {         static void Main(string[] args)         {             Console.Write("\tDate Time:");             DateTime dt = DateTime.Now;             Console.WriteLine("{0}",dt);             double a,b,choice,result;             Console.WriteLine("Enter first no");             a = double.Parse(Console.ReadLine());             Console.WriteLine("Enter second no");             b = double.Parse(Console.ReadLine());             Console.WriteLine("----Arithmetical Operaters----");             Console.WriteLine("1.Addition");             Console.WriteLine("2.Substraction");             Console.WriteLine("3.Multiplication");             Console.WriteLine("4.Division");             Con

Hypotenuse using Pythagoras theorem c^2 =(a^2 + b^2) in c#.

Image
 using Pythagoras theorem:  CODE: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace simple_calculator { class Program     { static void Main( string [] args)         {   DateTime dt = DateTime.Now;             Console.WriteLine( "{0}" ,dt);             double a, b;             Console.WriteLine( "Enter your first value" );             a = Convert.ToDouble(Console.ReadLine());             Console.WriteLine( "Enter your second value" );             b = Convert.ToDouble(Console.ReadLine());             double c = Math.Sqrt(Math.Pow(a,2)+Math.Pow(b,2));             Console.WriteLine( "Using pythagoras theorem:{0}" ,c);           }      }   } Output:

type float, double and decimal difference in datatype in c#.

Image
CODE:    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace simple_calculator { class Program     {        static void Main( string [] args)         {                float A = 5;             Console.WriteLine( "{0}" ,A);             double B = -5.01 ;             Console.WriteLine( "{0}" , B);             double C = 34.567839023 ;             Console.WriteLine( "{0}" , C);             double D = 12.345;             Console.WriteLine( "{0}" , D);             double E = 8923.1234857;             Console.WriteLine( "{0}" , E);             decimal F = 3456.091124875956542151256683467M ;             Console.WriteLine( "{0}" , F);           }     } } output:

simple calculator using c# all arithmetic and logical operators.

Image
  simple calculator using c# code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace simple_calculator {     class Program     {         static void Main(string[] args)         {              DateTime dt = DateTime.Now;               Console.WriteLine("{0}",dt);               Console.WriteLine("======Simple calculator======");               int num1, num2;                 Console.WriteLine("Enter first number:");                 num1 = Convert.ToInt32(Console.ReadLine());                 Console.WriteLine("Enter second number:");                 num2 = Convert.ToInt32(Console.ReadLine());                 double add = num1 + num2;                 Console.WriteLine("Addition:{0:0.00}", add);                 double sub = num1 - num2;                 Console.WriteLine("Substraction:{0:#.###}", sub);                 double mul = num1 * num2;                

Print Employee Data take input from user in c# program.

Image
 Employee Data: output: Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace employee_data {     class Program     {         static void Main(string[] args)         {             string name;             Console.WriteLine("Enter your name");             name= Console.ReadLine();             string fname;             Console.WriteLine("Enter your Father Name");             fname= Console.ReadLine();             string pno;             Console.WriteLine("Enter your phone no");             pno = Console.ReadLine();             string designation;             Console.WriteLine("your designation");             designation= Console.ReadLine();             string datejoin;             Console.WriteLine("Enter date of hiring");             datejoin= Console.ReadLine();             string salary;             Console.WriteLine("Enter salary");             sal

FORMAT SPECIFIERS IN C# PROGRAM.

Image
 FORMAT SPECIFIERS: OUTPUT: CODE: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Format_Specifiers {     class Program     {         static void Main(string[] args)         {             DateTime dt = DateTime.Now;              Console.WriteLine("Date-Time:{0}",dt);              int i = 1235;              Console.WriteLine("{0:C}",i);              Console.WriteLine("{0:D2}", i);              Console.WriteLine("{0:E}", i);              Console.WriteLine("{0:F}", i);              Console.WriteLine("{0:G}", i);              Console.WriteLine("{0:N}", i);              Console.WriteLine("{0:P}", i);              Console.WriteLine("{0:X}", i);              Console.ReadLine();                                }     } }