0% found this document useful (0 votes)
18 views

1-Program To Addition, Subtraction, Multipication, Division: Output

The document contains code snippets for 10 different C# programs that demonstrate various programming concepts like arithmetic operations, variable interchange, sum of even numbers, prime number checking, number series generation, factorials, triangles, inheritance, interfaces, and constructors. Each code snippet is followed by sample output.

Uploaded by

DiveshDutt
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

1-Program To Addition, Subtraction, Multipication, Division: Output

The document contains code snippets for 10 different C# programs that demonstrate various programming concepts like arithmetic operations, variable interchange, sum of even numbers, prime number checking, number series generation, factorials, triangles, inheritance, interfaces, and constructors. Each code snippet is followed by sample output.

Uploaded by

DiveshDutt
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

1-PROGRAM TO ADDITION,SUBTRACTION,MULTIPICATION,DIVISION

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace add_mul_sum_div
{
class Program
{
static void Main(string[] args)
{
int a, b;
a = 10;
b = 4;
Console.WriteLine("Addition={0}", a + b);
Console.WriteLine("Subtraction={0}", a - b);
Console.WriteLine("Multiply={0}", a * b);
Console.WriteLine("Division={0}",(float)a / b);
}
}
}

Output :

2-PROGRAM TO INTERCHANGE VALUE


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace interchange_Num
{
class Program
{
static void Main(string[] args)
{
int a, b;
a = 20;
b = 5;
Console.WriteLine("Before Interchange A = {0} And B = {1}", a, b);
a = a + b;
b = a - b;
a = a - b;
Console.WriteLine("After Interchange A = {0} And B = {1}", a, b);
Console.ReadLine();
}
}
}

Output :

3 -PROGRAM TO SUM OF FIRST TEN EVEN NATURAL NO. SQUARE


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace eventensqure
{
class Program
{
static void Main(string[] args)
{
int sum = 0;
int even = 2;
for (int i = 1; i <= 10; i++)
{
sum = sum + even * even;
Console.WriteLine( "Sum Of even natural number's Square = {0}", sum);
even += 2;
}
Console.ReadLine();
}
}
}

Output :

4 PROGRAM TO PRIME NUMBER


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Primenumber2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the value");
int limit =Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Prime numbers between 1 and " + limit);
for(int i=1; i < limit; i++)
{
Boolean isPrime = true;
for(int j=2; j < i ; j++)
{
if(i % j == 0)
{
isPrime = false;
break;
}
}
if(isPrime)
Console.Write(i + " ");
}
}
}
}

Output :

5 PROGRAM TO SERIES OF NUMBER


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace forbelow
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter The value");
int n = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write("{0,3}", j);
}
Console.ReadLine();
}
}
}
}

Output :

6 PROGRAM TO FACTORIAL OF N
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Dynamic_Factorial
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the number: ");
int a = Convert.ToInt32(Console.ReadLine());
int result= fact(a);
Console.WriteLine("Factorial of the number is: " + result);
}
static int fact(int b)
{
if(b <= 1)
return 1;
else
return b * fact(b-1);
}
}
}

Output :

7 PROGRAM TO TRAINGALE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Triangle
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter the charecter\n");
string str1 = Console.ReadLine();
int i = 0;
char[] arr = new char[10];
foreach (char s in str1)
arr[i++] = s;
for (i = 0; i < str1.Length; i++)
{
for (int j = 0; j <= i; j++)
Console.Write(arr[j]);
Console.ReadLine();
}
}
}
}

Output :

8 PROGRAM TO MULTILEVEL INHERITANCE


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Inheritance
{
class A
{
int i, j;
public void Nand()
{
Console.Write("This is Inheritance \n");
for (i = 0; i < 5; i++)
{
for (j = 5; j > i; j--)
{
Console.Write(j);
}
Console.WriteLine();
}
}
}
class B : A
{
public void Saxena()
{
for (int i = 5; i > 0; i--)
{
for (int j = 0; j < i; j++)
{
Console.Write(j);
}
Console.WriteLine();
}
}
}
class C : B
{
public void Bramha()
{
int i, j;
for ( i = 1; i <= 5; i++)
{
for ( j = i; j >= 1; j--)
{
8

Console.Write(j);
}
Console.WriteLine();
}
}
}
class Program
{
static void Main(string[] args)
{
C obj = new C();
obj.Nand();
obj.Saxena();
obj.Bramha();
Console.Read();
}
}
}

Output :

9 PROGRAM TO INTERFACE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace interface_me
{
interface A
{
void me();
}
interface B
{
void show();
}
class C : B, A
{
public void me()
{
Console.WriteLine("I LOVE MY India");
}
public void show()
{
Console.WriteLine("My Name is B.N.Saxena");
}
}
class Program
{
static void Main(string[] args)
{
C obj = new C();
obj.me();
obj.show();
Console.Read();
}
}}

Output :
10

10 PROGRAM TO DEFAULT & ARGUMENT CONSTRUCTOR


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Argument_Constructor
{
class Mul
{
int a, b;
public Mul()
{
a = 12;
b = 20;
}
public void display()
{
Console.WriteLine("Default Constructor");
Console.WriteLine(a);
Console.WriteLine(b);
}
public Mul(int x, int y)
{
int z = x * y;
Console.WriteLine("This is Argument Constructor");
Console.WriteLine(z);
}
}
class Program
{
static void Main(string[] args)
{
Mul obj = new Mul();
Mul ob = new Mul(4,5);
obj.display();
}
}}

Output :

11

You might also like