Skip to main content

Posts

Showing posts with the label C# Programs

WAP to find odd even, prime_composite, and factorial of a number using function

  using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace function { Class Program { static void main(string[] args) { prime_comp(); factorial(); odd_even(); } static public void odd_even() { int n; Console.WriteLine("Input any number."); n= Convert.ToInt32(Console.ReadLine()); if (n%2==0) { Console.WriteLine("The number is even."); } else { Console.WriteLine("The number is odd."); } Console.ReadLine(); } static public void factorial() { int n, i, fact = 1; Consol.WriteLine("Input any number."): n  = Convert.ToInt32(Console.ReadLine()): for(n==0) { Console.WriteLine("The factorial of 0 is 1"); } else{ for(i=1; i<=n; i++) { fact = fact * i; } Console.WriteLine("The factorial of given number is: {0}",fact); } } static public void prime_comp() { int num, flag = 0; Console.WriteLine("Input any number."); num = Convert.ToInt32(Console.ReadLine()); fo...

WAP to display series as given:

a). 1, 5, 10 ,15, 20 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace series1 { Class Program { static void main(string[] args) { int n, i=1, mul=1; Console.WriteLine("How many number."); n = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("{0}",i); for(i = 1; i<=n ;i++) { mul = i* 5; Console.WriteLine("{0}", mul); } Console.ReadLine(); } } } OUTPUT: How many numbers. 5 1 5 10 15 20 25 b). 0, 2, 4, 6 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace series2 { Class Program { static void main(string[] args) { int n, i; Console.WriteLine("Enter how many terms."); n= Convert.ToInt32(Console.ReadLine()); for(i=0; i<n; i++) { if (i%2 == 0) { Console.WriteLine("{0}", i); } Console.ReadLine(); } } } OUTPUT:  Enter how many terms. 8 0 2 4 6 c). 0, 1, 1, 2, 3, 5,7...... using System...

WAP to find multiplication table of given number

  using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Multiplication_Table { Class Program { static void main(string[] args) { int i, n, mul; Console.WriteLine("Input any number."); n= Convert.ToInt32(Console.ReadLine()): Console.WriteLine("The multiplication table of {0} is : ", n) for(i=1; i<=0; i++) { mul = n* i Console.WriteLine("{0}", mul); } Console.ReadLine(); } } } OUTPUT: Input any number. 5 The multiplication table of 5 is : 5 10 15 20 25 30 35 40 45 50

WAP to find factorial of a given number

  using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace factorial { Class Program { static void main(string[] args) { int fact = 1, i, n; Console.WriteLine("Input any number."); n = Convert.Toint32(Console.ReadLine()); if( n == 0) { Console.WriteLine("The factorial of 0 is 1."); Console.ReadLine(); } else  { for(i=1; i<=n; i++) { fact = fact*i; } Console.WriteLine("The factorial of a given number is: {0}", fact); Console.ReadLine(); } } } } OUTPUT: Input any number.  5 The factorial of a given number is: 120

WAP to swap two numbers

  using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace swap { Class Program { static void main(string[] args) { int A, B, C; Console.WriteLine("Input first number."); A= Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Input second number."); B= Convert.ToInt32(Console.ReadLine()); Console.WriteLine("The number before swapping are : A={0} B= {1}", A,B) C= A; A= B; B = C; Console.WriteLine("The number after swapping are: A={0}  B = {1}", A,B); Console.ReadLine(); } } } OUTPUT: Input first number. 5 Input second number. 6 The number before swapping are : A = 5  B = 6 The number after swapping are : A= 6      B= 5

WAP to find the sum of first five odd numbers

  using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace sum_odd { Class Program { static void main(string[] args) { int i, sum = 0; Console.WriteLine("The first five odd numbers are:"); for(i=1; i<10; i++) { if (i%2 != 0) { Console.WriteLine("{0}",i); sum = sum +i; } } Console.WriteLine("The sum of the first five odd number is :{0}",sum); Console.ReadLine(); } } } OUPUT: The first five odd numbers are: 1 3 5 7 9 The sum of the  first five odd number is : 25

WAP to find the sum of first five even numbers

  using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace sum_even { Class Program { static void main(string[] args) { int i, sum=0; Console.WriteLine("The first  five even numbers are: "); for(i=0; i<12; i++) { if (i%2 == 0) { Console.WriteLine("{0}",i); sum = sum +i; } } Console.WriteLine("The sum of  the first five even numbers is :{0}",sum); Console.ReadLine(); } } } OUTLINE: The first five even numbers are: 2 4 6 8 10 The sum of the first five even numbers is 30

WAP to find sum of 'n' natural numbers

  using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace natural_sum { Class Program { static void main(string[] args) { int n, i, sum= 0; Console.WriteLine("How many numbers."); n = Convert.ToInt32(Console.ReadLine()); for (i= 1; i<= n; i++) { sum = sum +1; } Console.WriteLine("The sum of n natural numbers is : {0}", sum); Console.ReadLine(); } } } Output: How many numbers. 4 The sum of n natural number is: 10

WAP to find reverse of a number

  using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace reverse { Class Program { static void main(string[] args) { int n, reverse=0 , rem; Console.WriteLine("Enter a number"); n= Conver.ToInt32(Console.ReadLine()); while(n!=0) { rem = n%10; reverse = reverse*10 +rem; n = n/10; } Console.WriteLine("The reversed number is : {0}", reverse); Consoel.ReadLine(); } } } OUTPUT: Enter a number 567 The reversed number is : 756 

WAP to display selected days of week

  using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace selected_days { Class Program { static void main(string[] args) { int weeknumber; Console.WriteLine("Enter week number (1-7):"); switch (weeknumber) { case 1: Console.WriteLine("Sunday"); break; case 2: Console.WriteLine("Monday"); break; case 3:  Console.WriteLine("Tuesday"); break; case 4: Console.WriteLine("Wednesday"); break; case 5: Console.WriteLine("Thursday"); break; case 6: Console.WriteLine("Friday"); break; case 7: Console.WriteLine("Saturday"); break; } Console.ReadLine(); } } } OUTPUT: Enter week number (1-7): 5 Thursday

WAP to find addition, subtraction, multiplication and division of two numbers using switch case.

  using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace switch_case { Class Program { static void main(string[] args) { double a, b; Console.WriteLine("Input first number."); a= Convert.Todouble(Console.ReadLine()); Cosole.WriteLine("Input second number."); b= Convert.Todouble(Console.ReadLine()); Console.WriteLine("1.Addition"); Console.WriteLine("2.Subtraction"); Console.WriteLine("3.Multiply"); Console.WriteLine("4.Division"); int c = Convert.ToInt32(Console.ReadLine()); Switch (c) { Case 1: { Console.WriteLine("Addition of two numbers : {0}", (a+b)); break; Case 2: Console.WriteLine("Subtraction of two numbers:{0}", (a-b)); break; Case 3: Console.WriteLine("Multiplication of two numbers : {0}",(a*b)); break; Case 4: Console.WriteLine("Division of two numbers : {0}", (a/b)); break; } Console.ReadLine(); } } } Outp...

WAP to find out the number is negative or positive

  using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace  Positive_negative { Class Program { static void main(string[] args) { double a; Console.WriteLine("Input any number."); a= Convert.ToDouble(Console.ReadLine()); if(a>0) { Console.WriteLine("The number is Positive."); } else { Console.WriteLine("The number is negative."); } Console.ReadLine(); } } } OUTPUT: Input any number. 5 The number is Positive.

WAP to find largest number among 3 numbers

  using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace greatest { Class Program { static void main(string[] args) { double a, b, c; Console.WriterLine("Please input three numbers."); a=Convert.Toint32(Console.ReadLine()); b=Convert.Toint32(Console.ReadLine()); c=Convert.Toint32(Console.ReadLine()); if(a>b && a>c) { Console.WriteLine("The greatest number is:{0}",a); } else if (b>a && b>c) { Console.WriteLine("The greatest number is:{0}",b); } else { Console.WriteLine("The greatest number is: {0}",c); } Console.ReadLine(); } } } OUTPUT: Please input three numbers.  5 6 7 The greatest number is: 7

Program to find given number is divisible by 2 or 3 and divisible 3 and 5

1.Program to find the given number is divisible by 2 or 3   using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace div_2or_3 { Class Program { static void main(string[] args) { int a; Console.WriteLine("Please enter any number:"); a = Convert.ToInt32(Console.ReadLine()); if (a % 2 == 0 || a% 3 == 0) { Console.WriteLine("The number is divisle by 2 or 3:"); } else { Console.WriteLine("The number is neither divisible by 2 or 3 . " ) ; } Console.ReadLine(); } } } OUTPUT: Please enter any number: 8 The number is divisible by 2 or 3. 2.Program to find the given number is divisible by 3 and 5: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace div_3and_5 { Class Program { static void main(string[] args) { int a;  Console.WriteLine("please enter any number."); a = Convert.ToInt32(Console.ReadLine()); if(a%3 == ...