Entered Number Is Even or Odd. Coding
Entered Number Is Even or Odd. Coding
Entered Number Is Even or Odd. Coding
CODING:-
using System;
namespace even_odd
{
class Program
{
static void Main(string[] args)
{
int i;
Console.Write("Enter the number: ");
i = int.Parse(Console.ReadLine());
if (i % 2 == 0)
{
Console.WriteLine("\nEntered number is even number");
}
else
{
Console.WriteLine("\nEntered number is odd number");
}
Console.ReadKey();
}
}
}
OUTPUT:-
CODING:-
using System;
namespace prime
{
class Program
{
static void Main()
{
int num, i;
Console.Write("Enter the number: ");
num = int.Parse(Console.ReadLine());
if (num == 1)
{
Console.WriteLine(num + " is not prime neither unprime");
}
if (num == 2)
{
Console.WriteLine(num + " is prime");
}
else
{
for (i = 2; i <= num; i++)
{
if (num % i == 0)
{
if (num == i)
{
Console.WriteLine(num + " is prime");
break;
}
else
{
Console.WriteLine(num + " is not prime");
break;
}
}
}
}
Console.ReadKey();
}
}
}
OUTPUT:-
CODING:-
using System;
namespace reverse
{
class Program
{
static void Main()
{
int num, temp, rem, rev = 0;
Console.Write("Enter a Number= ");
num = int.Parse(Console.ReadLine());
temp = num;
while (num > 0)
{
rem = num % 10;
rev=rev*10 + rem;
num = num / 10;
}
Console.WriteLine("Given number is = {0}", temp);
Console.WriteLine("Reverse of a number is= {0}", rev);
if
(temp == rev)
Console.WriteLine("\nGiven number is palindrome");
else
Console.WriteLine("\nGiven number is not palindrome"); Console.ReadKey();
}
}
}
OUTPUT:-
CODING:-
using System;
namespace Epattern
{
class Program
{
static void Main()
{
int i, j;
for (i = 1; i <= 5; i++)
{
for (j = 1; j <= i; j++)
{
Console.Write(j + "\t");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}
OUTPUT:-
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
E5. Write an algorithm, draw a flowchart and develop a C#.Net console application to Print and evaluate
the following series. The series is -----
Sum = (1)+(x)+(x^2/2!) )+(x^3/3!) ) +(x^4/4!) +(x^5/5!) )+....................
CODING:-
using System;
namespace Series
{
class Program
{
int Fact(int n)
{
int fact = 1;
for (int i = 1; i <= n; i++)
{
fact = fact * i;
}
return fact;
}
static void Main()
{
Program p = new Program();
int i, r;
double x, sum = 1;
Console.Write("Enter range: ");
r = int.Parse(Console.ReadLine());
Console.Write("Enter a value of x: ");
x = double.Parse(Console.ReadLine());
for (i = 1; i < r; i++)
{
sum = sum + (Math.Pow(x, i) / p.Fact(i));
}
Console.WriteLine("Sum = " + sum);
Console.ReadKey();
}
}
}
OUTPUT:-
Enter range: 5
Enter a value of x: 2
Sum = 7
E6. Write an algorithm, draw a flowchart and develop a C#.Net console application to perform
ascending order sorting using Selection Sort method of Array.
CODING:-
using System;
namespace sort
{
class Program
{
static void Main()
{
int[] arr = new int[10] { 1, 2, 6, 5, 9, 3, 10, 8, 7, 4 };
int i, j, temp;
Console.WriteLine("Given array:");
for (i = 0; i < 10; i++)
{
Console.Write(arr[i] + "\t");
}
for (i = 1; i < 10; i++)
{
for (j = i + 1; j < 10; j++)
{
if (arr[j] < arr[i])
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
Console.ReadKey();
}
}
}
OUTPUT:-
Given array:
1 2 6 5 9 3 10 8 7 4
After sorting array:
1 2 3 4 5 6 7 8 9 10
E7. Write an algorithm, draw a flowchart and develop a C#.Net console application to multiply two
integer, float and double numbers using method overloading.
CODING:-
using System;
namespace method_overload
{
class Program
{
void multi(int a, int b)
{
int c = a *b;
Console.WriteLine("Multiplication of two integer numbers: \t" + c);
}
void multi(float p, float q)
{
float r = p * q;
Console.WriteLine("Multiplication of two float numbers:\t" + r);
}
void multi(double x, double y)
{
double z = x * y;
Console.WriteLine("Multiplication of two double numbers: \t" +z) ;
}
static void Main()
{
Program p = new Program();
float r1;
double z1;
p.multi(4, 3);
r1 = 1 / 3f;
p.multi(r1, r1);
z1 = 1 / 3d;
p.multi(z1, z1);
Console.ReadKey();
}
}
}
OUTPUT:-
CODING:-
using System;
namespace binary
{
class complex
{
double x, y;
public complex() { }
public complex(double real, double img)
{
x = real;
y = img;
}
public static complex operator +(complex c1, complex c2)
{
complex c3 = new complex();
c3.x = c1.x + c2.x;
c3.y = c1.y + c2.y;
return c3;
}
public void display()
{
Console.Write(x);
if (y >= 0)
{
Console.WriteLine(" + j" + y);
}
else
{
Console.WriteLine(" - j" + (-y));
}
}
}
class Program
{
static void Main()
{
complex a, b, c;
a = new complex(2.5, 3.5);
b = new complex(1.6, 2.7);
c = a + b;
Console.Write("a = ");
a.display();
Console.Write("b = ");
b.display();
Console.Write("c = ");
c.display();
Console.ReadKey();
}
}
}
OUTPUT:-
a = 2.5 + j3.5
b = 1.6 + j2.7
c = 4.1 + j6.2
E9. Write an algorithm, draw a flowchart and develop a C#.Net console application to implement the
concept of Inheritance.
CODING:-
using System.Collections.Generic;
using System.Text;
namespace E9
{
class bases
{
public void bfunc()
{
Console.WriteLine("Base");
}
}
class derived : bases
{
public void dfunc()
{
Console.WriteLine("Derived");
}
}
class Program
{
static void Main(string[] args)
{
derived d = new derived();
d.bfunc();
d.dfunc();
Console.ReadKey();
}
}
}
OUTPUT:-
Base
Derived
E10. Write an algorithm, draw a flowchart and develop a C#.Net console application to implement the
concept of interface.
CODING:-
using System;
namespace CInterface
{
interface IFace1
{
void Func1();
}
interface IFace2
{
void Func2();
}
class Program
{
static void Main()
{
Derived d = new Derived();
IFace1 f1 = (IFace1)d;
f1.Func1();
IFace2 f2 = (IFace2)d;
f2.Func2();
Console.ReadKey();
}
}
}
OUTPUT:-
Interface1
Interface2
W1. Write an algorithm, draw a flowchart and develop a C#.Net console application to check whether
the entered number is positive, negative or Zero.
CODING:-
using System;
using System.Collections.Generic;
using System.Text;
namespace W1
{
class Program
{
static void Main(string[] args)
{
int num;
Console.Write("Enter the number:");
num = int.Parse(Console.ReadLine());
if (num > 0)
{
Console.WriteLine("{0} is a positive number", num);
}
else if (num < 0)
{
Console.WriteLine("{0} is a negative number", num);
}
else
{
Console.WriteLine("{0} is a zero", num);
}
Console.ReadKey();
}
}
}
OUTPUT:-
W2. Write an algorithm, draw a flowchart and develop a C#.Net console application to develop Boxing
and Unboxing concept.
CODING:-
using System;
using System.Collections.Generic;
using System.Text;
namespace W2
{
class Program
{
static void Main(string[] args)
{
int m = 10;
// boxing m
object n = m;
Console.WriteLine("\n Boxing n=" + n);
// unboxing m back to an int
m = (int)n;
Console.WriteLine("\n Unboxing m=" + m);
Console.ReadKey();
}
}
}
OUTPUT:-
Boxing n=10
Unboxing m=10
W3. Write an algorithm, draw a flowchart and develop a C#.Net console application to calculate the sum
of digits of a number.
CODING:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace W3
{
class Program
{
static void Main(string[] args)
{
int num, n, sum = 0;
Console.Write("Enter a number:");
num = int.Parse(Console.ReadLine());
}
}
}
OUTPUT:-
Enter a number:235
Sum = 10
W4. Write an algorithm, draw a flowchart and develop a C#.Net console application to print the
Following Pattern:
1
22
333
4444
55555
CODING:-
using System;
using System.Collections.Generic;
using System.Text;
namespace W4
{
class Program
{
static void Main(string[] args)
{
int i, j;
for (i = 1; i <= 5; i++)
{
for (j = 1; j <= i; j++)
{
Console.Write(i + "\t");
}
Console.WriteLine("\n");
}
Console.ReadKey();
}
}
}
OUTPUT:-
2 2
3 3 3
4 4 4 4
5 5 5 5 5
W5. Write an algorithm, draw a flowchart and develop a C#.Net console application to Print the factorial
of a given number.
CODING:-
using System;
using System.Collections.Generic;
using System.Text;
namespace W5
{
class Program
{
static void Main(string[] args)
{
int i, num, fact = 1;
Console.Write("Enter a number: ");
num = int.Parse(Console.ReadLine());
for (i = 1; i <= num; i++)
{
fact = fact * i;
}
Console.WriteLine("Factorial = " + fact);
Console.ReadKey();
}
}
}
OUTPUT:-
Enter a number: 5
Factorial = 120
W6. Write an algorithm, draw a flowchart and develop a C#.Net console application to search a number
from array using liner search method of Array.
CODING:-
using System;
using System.Collections.Generic;
using System.Text;
namespace W6
{
class Program
{
static void Main(string[] args)
{
int[] arr = new int[10] { 10, 5, 3, 4, 2, 7, 9, 8, 6, 1 };
int i, num;
Console.WriteLine("Given array:");
for (i = 0; i < 10; i++)
{
Console.Write(arr[i] + "\t");
}
Console.Write("\nEnter the seacrh element:");
num = int.Parse(Console.ReadLine());
for (i = 0; i < 10; i++)
{
if (num == arr[i])
{
Console.WriteLine("Element {0} found at location {1}", num, i + 1);
break;
}
else if (num != arr[i] && i == 9)
{
Console.WriteLine("Entered element not found");
break;
}
}
Console.ReadKey();
}
}
}
OUTPUT:-
Given array:
10 5 3 4 2 7 9 8 6 1
Enter the seacrh element:7
Element 7 found at location 6
W7. Write an algorithm, draw a flowchart and develop a C#.Net console application to add two three
and four numbers using method overloading.
CODING:-
using System;
using System.Collections.Generic;
using System.Text;
namespace W7
{
class Addition
{
public void addi(int a, int b)
{
int c;
c = a + b;
Console.WriteLine("Sum of two numbers \t:\t" +c);
}
public void addi(int a, int b, int c)
{
int d;
d = a + b + c;
Console.WriteLine("Sum of three numbers \t:\t" +d);
}
public void addi(int a, int b, int c, int d)
{
int e;
e = a + b + c + d;
Console.WriteLine("Sum of four numbers \t:\t" +e);
}
}
class Program
{
static void Main(string[] args)
{
Addition a = new Addition();
a.addi(1,2);
a.addi(3, 4, 5);
a.addi(7, 8, 9, 10);
Console.ReadKey();
}
}
}
OUTPUT:-
W8. Write an algorithm, draw a flowchart and develop a C#.Net console application to calculate area of
rectangle and area of triangle using the concept of method overriding.
CODING:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace W8
{
class class1
{
public virtual void area() { }
}
class class2:class1
{
public override void area()
{
double l =2.5,b=5.5;
double a=l*b;
Console.WriteLine("Area of rectangle:{0}",a);
double h=3.5,w=5.5;
a=(h*w)/2;
Console.WriteLine("Area of triangle:"+a);
}
}
class Program
{
static void Main(string[] args)
{
class2 c2 = new class2();
c2.area();
Console.ReadKey();
}
}
}
OUTPUT:-
Area of rectangle:13.75
Area of triangle:9.625
W9. Write an algorithm, draw a flowchart and develop a C#.Net console application to implement the
concept of class and object.
CODING:-
using System;
using System.Collections.Generic;
using System.Text;
namespace W9
{
class print
{
public void display()
{
Console.WriteLine("hello user, This is C#.NET Console Application");
}
}
class Program
{
static void Main(string[] args)
{
print p = new print();
p.display();
Console.ReadKey();
}
}
}
OUTPUT:-
hello user, This is C#.NET Console Application
W10. Write an algorithm, draw a flowchart and develop a C#.Net console application to demonstrate
divide by zero exception.
CODING:-
using System;
using System.Collections.Generic;
using System.Text;
namespace W10
{
class Program
{
static void Main(string[] args)
{
int div, n1 = 12, n2 = 0;
Console.WriteLine("n1= {0}\t n2= {1}" ,n1,n2);
Console.WriteLine("division = {0} /{1}" ,n1,n2);
try
{
div = n1 / n2;
Console.WriteLine("\ndivision=" + div);
}
catch (DivideByZeroException)
{
Console.WriteLine("\nThe number can not be divided by zero");
}
Console.ReadKey();
}
}
}
OUTPUT:-
n1= 12 n2= 0
division = 12 /0
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: