Skip to main content

Posts

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