You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
usingSystem;publicclassExercise8{publicstaticvoidMain(){intnum1,num2,num3;// input dataConsole.Write("Input the 1st number :");num1=Convert.ToInt32(Console.ReadLine());Console.Write("Input the 2nd number :");num2=Convert.ToInt32(Console.ReadLine());Console.Write("Input the 3rd number :");num3=Convert.ToInt32(Console.ReadLine());// conditionif(num1>num2){if(num1>num3){Console.Write("1st Number is the greatest. \n\n");}else{Console.Write("3rd Number is the greatest. \n\n");}}elseif(num2>num3)Console.Write("2nd Number is the greatest. \n\n");elseConsole.Write("3rd Number is the greatest. \n\n");}}
usingSystem;publicclassAreaOfTriangle{publicstaticvoidMain(){Console.Write("Enter the Base:");doubleBase=Convert.ToDouble(Console.ReadLine());Console.Write("Enter the Height:");doubleHeight=Convert.ToDouble(Console.ReadLine());doubleArea=(Base*Height)/2;Console.Write("Area of a Triangle = "+Area);Console.ReadKey();}}
3. Swapping number
usingSystem;namespaceswappin_number{classswapping_number{publicstaticvoidMain(string[]args){inta=5;intb=10;intc=a;a=b;b=c;Console.WriteLine("swapping a :"+a);//swapping : 10Console.WriteLine("swapping b :"+b);//swapping : 5}}}
4. Quadratic equation ax2+bx+c=0
usingSystem;publicclassExercise11{publicstaticvoidMain(){// variable declarationinta,b,c;doubled,x1,x2;Console.Write("Input the value of a : ");a=Convert.ToInt32(Console.ReadLine());Console.Write("Input the value of b : ");b=Convert.ToInt32(Console.ReadLine());Console.Write("Input the value of c : ");c=Convert.ToInt32(Console.ReadLine());// quadratic lawd=b*b-4*a*c;if(d==0){Console.Write("Both roots are equal.\n");x1=-b/(2.0*a);x2=x1;Console.Write("First Root1= {0}\n",x1);Console.Write("Second Root2= {0}\n",x2);}elseif(d>0){Console.Write("Both roots are real and diff-2\n");x1=(-b+Math.Sqrt(d))/(2*a);x2=(-b-Math.Sqrt(d))/(2*a);Console.Write("First Root1= {0}\n",x1);Console.Write("Second Root2= {0}\n",x2);}elseConsole.Write("Root are imeainary;");}}
5. Prime number 1 to 50
usingSystem;publicclassExercise34{publicstaticvoidMain(){//variable declarationintnum,i,ctr,first_num,second_num;//Input prime numberConsole.Write("Input 1st number: ");first_num=Convert.ToInt32(Console.ReadLine());Console.Write("Input 2nd number: ");second_num=Convert.ToInt32(Console.ReadLine());Console.Write("Prime numbers between {0} and {1} are : \n",first_num,second_num);//Condition & Loopfor(num=first_num;num<=second_num;num++){ctr=0;for(i=2;i<=num/2;i++){if(num%i==0){ctr++;break;}}if(ctr==0&&num!=1)Console.Write("{0} ",num);}Console.Write("\n");}}
6. Fibonacci series
usingSystem;publicclassFibonacciExample{publicstaticvoidMain(string[]args){intn1=0,n2=1,n3,i,number;Console.Write("Enter the number of elements: ");number=int.Parse(Console.ReadLine());Console.Write(n1+" "+n2+" ");//printing 0 and 1 for(i=2;i<number;++i)//loop starts from 2 because 0 and 1 are already printed {n3=n1+n2;Console.Write(n3+" ");n1=n2;n2=n3;}}}
7. Factorial number
// C# program to find factorial// of given numberusingSystem;classTest{// method to find factorial// of given numberstaticintfactorial(intn){if(n==0)return1;returnn*factorial(n-1);}// Driver methodpublicstaticvoidMain(){intnum=5;Console.WriteLine("Factorial of "+num+" is "+factorial(5));}}
8. Check any prime number
usingSystem;publicclassPrimeNumberExample{publicstaticvoidMain(string[]args){intn,i,m=0,flag=0;Console.Write("Enter the Number: ");n=int.Parse(Console.ReadLine());m=n/2;for(i=2;i<=m;i++){if(n%i==0){Console.Write("Number is not Prime.");flag=1;break;}}if(flag==0)Console.Write("Number is Prime.");}}
9. Character, number, special character
usingSystem;namespacecharacters_specialChar_number{classcharacters_specialChar_number{publicstaticvoidMain(string[]args){stringstr;intalphabet,number,specialChar,i,l;alphabet=number=specialChar=i=0;Console.Write("Write Somethig : ");str=Console.ReadLine();l=str.Length;while(i<l){if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z')){alphabet++;}elseif(str[i]>='0'&&str[i]<='9'){number++;}else{specialChar++;}i++;}Console.WriteLine("Aphabet is = {0}\n ",alphabet);Console.WriteLine("Number is = {0}\n",number);Console.WriteLine("Special Character is = {0}\n",specialChar);}}}
10. 2+4+6+...n find sum series
usingSystem;classProgram{staticvoidMain(string[]args){intn=10;// change this to the desired value of nintresult=0;for(inti=2;i<=n;i+=2){result+=i;}Console.WriteLine("Summation series: 2+4+6+...+"+n+" = "+result);}}
11. 1+3+5+...n find sum series
usingSystem;classProgram{staticvoidMain(string[]args){intn=10;// change this to the desired value of nintresult=0;for(inti=1;i<=n;i+=2){result+=i;}Console.WriteLine("Summation series: 1+3+5+...+"+n+" = "+result);}}
12. 1+2+3+4+...n find sum series
usingSystem;classProgram{staticvoidMain(string[]args){intn=10;// change this to the desired value of nintresult=0;for(inti=1;i<=n;i++){result+=i;}Console.WriteLine("Summation series: 1+2+3+4+...+"+n+" = "+result);}}
13. 1(3)+2(3)+3(3)+...n find sum series
usingSystem;classProgram{staticvoidMain(string[]args){intn=3;// change this to the desired value of nintresult=0;for(inti=1;i<=n;i++){result+=i*i*i;}Console.WriteLine("Summation series: 1^3 + 2^3 + 3^3 + ... + "+n+"^3 = "+result);}}
14. 1(2)+2(2)+3(2)+...n find sum series
usingSystem;classProgram{staticvoidMain(string[]args){intn=3;// change this to the desired value of nintresult=0;for(inti=1;i<=n;i++){result+=i*i;}Console.WriteLine("Summation series: 1^2 + 2^2 + 3^2 + ... + "+n+"^2 = "+result);}}