Sie sind auf Seite 1von 29

Name:- Rohan Tandekar And Rohit Gautam

E 1:- Write an algorithm draw a flowchart and develop a C#.Net Console


application to check wheather the entered No. is Even or Odd.

Coding:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a;
Console.Write("Enter any Number:-");
a = int.Parse(Console.ReadLine());
if (a % 2 == 0)
{
Console.Write(a+" is even no.");
Console.Read();
}
else
{
Console.Write(a+" is odd no.");
Console.Read();
}

}
}
}

Output:-
Enter any Number:-5
5 is odd no.

Enter any Number:-10


10 is even no.
Name:- Rohan Tandekar And Rohit Gautam

E 2:-Write an algorithm , draw a flowchar and develop a c#.net console


application to check whether the given number is prime or not.

Coding:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int n, i, m = 0, flag = 0;
Console.Write("Enter the Number to Check Prime : ");
n = int.Parse(Console.ReadLine());
m = n / 2;
for (i = 1; i <= m; i++)
{
if (n % i == 0)
{
Console.WriteLine("Number is not Prime");
flag = 1;
break;
}
}
if (flag == 0)
{
Console.WriteLine("Number is Prime");
}
Console.ReadLine();
}
}
}

Output:-

Enter the Number to Check Prime : 10


Number is not Prime
Enter the Number to Check Prime : 1
Number is Prime
Name:- Rohan Tandekar And Rohit Gautam

E 3:- Write an algorithm draw a flowchart and develop a C#.Net Console


application to calculate reverse of number, to check the given no. is
palindrome or not.

Coding :-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int rem, temp, rev = 0, n;
Console.Write("Enter a number:-");
n = int.Parse(Console.ReadLine());
temp = n;
while (n != 0)
{
rem = n % 10;
rev = rev * 10 + rem;
n /= 10;
}
Console.WriteLine("Reversed Number:" + rev);

if (temp == rev )
{
Console.WriteLine("Number is palindrome");
}
else
{
Console.WriteLine("Number is not palindrome");
}

Console.ReadLine();

}
}
}

Output:-
Enter a number:-2345
Reversed Number:5432
Number is not palindrome

Enter a number:-23432
Reversed Number:23432
Number is palindrome
Name:- Rohan Tandekar And Rohit Gautam

E 4:-Write an algorithm , draw a flowchar and develop a c#.net


console application to print the following pattern:
1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

Coding:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
int n = 5;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write("\t" + j);
}
Console.WriteLine("\n");
}
Console.ReadLine();
}
}
}

Output:-

1 2

1 2 3

1 2 3 4

1 2 3 4 5
Name:- Rohan Tandekar And Rohit Gautam

E 5.Write an algoritham, draw a flowchart and develop a c#.net Console


application to
Print and evaluate the following the series.sum= [(1)+(x)+(x^2/2!)+(x^3/3!)
+(x^4/4!)+..........]

Coding:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication34
{
class Program
{
static void Main(string[] args)

{
double x, sum, no_row;
int i, n;
Console.WriteLine("\nCalculate the sum of series
[1+x+x^2/2!+x^3/3!+x^4/4!+..........]\n");
Console.Write("\n Enter the of x :");
x = double.Parse(Console.ReadLine());
Console.Write("\n Enter the number of terms :-");
n = int.Parse(Console.ReadLine());
sum = 1;
no_row = 1;
for (i=1;i<n;i++)
{
no_row=no_row*x/(float)i;
sum=sum+no_row;
}
Console.WriteLine("\n The Sum of Following series is .......");
Console.Write("(1) +({0})",x);
for (i=2; i<=n;i++)
Console.Write("+ ({0}^{1}/{2}!)", x,i,i);
Console.Write("="+sum);
Console.ReadLine();
}
}
}

Output:-
Calculate the sum of series [1+x+x^2/2!+x^3/3!+x^4/4!+..........]
Enter the of x :3
Enter the number of terms :-4
The Sum of Following series is .......
(1) +(3)+ (3^2/2!)+ (3^3/3!)+ (3^4/4!)=13
Name:- Rohan Tandekar And Rohit Gautam

E 6:-Write an algorithm , draw a flowchar and develop a c#.net


console application toperform assending order sorting using
selection sort method using.

Coding:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
````
namespace ConsoleApplication12
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[10] { 56, 1, 99, 67, 89, 23, 44, 12, 78, 34 };
int n = 10;
Console.WriteLine("Selection Sort");
Console.WriteLine("Initial Array is:");
for (int i = 0; i<n;i++)
Console.Write(a[i] + " ");
int temp, smallest;
for (int i = 0; i < 0; i++)
{
smallest = i;
for (int j = i + 1; j < n; j++)
{
if (a[j] < a[smallest])
smallest = j;
}
temp = a[smallest];
a[smallest] = a[i];
a[i] = temp;
}
Console.WriteLine("\nSorted Array is:");
for (int i = 0; i < n; i++)
Console.Write(a[i] + " ");
Console.ReadLine();
}
}
}

Output:-

Selection Sort
Initial Array is:
56 1 99 67 89 23 44 12 78 34
Sorted Array is:
1 12 23 34 44 56 67 78 89 99
Name:- Rohan Tandekar And Rohit Gautam
E 7:-Write an algorithm , draw a flowchar and develop a c#.net
console application tomultipy two integer float and double number
using method overloading.

Coding:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication10
{
class Multiplication
{
public int multiply(int a, int b)
{
return a * b;
}
public double multiply(float a, float b)
{
return a*b;
}
public double multiply(double a, double b)
{
return a * b;
}
}
class Program
{
static void Main(string[] args)
{
Multiplication mul = new Multiplication();
Console.WriteLine("Enter two Integers:-");
int x1 = int.Parse(Console.ReadLine());
int x2 = int.Parse(Console.ReadLine());
int m1 = mul.multiply(x1, x2);
Console.WriteLine("Multiplication of Two Integer number =" + m1);
Console.WriteLine("------------------------------------------------");
Console.WriteLine("Enter two float number:-");
float y1 = float.Parse(Console.ReadLine());
float y2 = float.Parse(Console.ReadLine());
double m2 = mul.multiply(y1, y2);
Console.WriteLine("Multiplication of Two float number =" + m2);
Console.WriteLine("------------------------------------------------");
Console.WriteLine("Enter two double number:-");
double z1 = double.Parse(Console.ReadLine());
double z2 = double.Parse(Console.ReadLine());
double m3 = mul.multiply(z1,z2);
Console.WriteLine("Multiplication of two double number =" + m3);
Console.ReadLine();
}
}
}
Output:-

Enter two Integers:-


2
4
Multiplication of Two Integer number =8
------------------------------------------------
Enter two float number:-
2.2
4.2
Multiplication of Two float number =9.2399997806549
------------------------------------------------
Enter two double number:-
2.456
4.456
Multiplication of two double number =10.943936
Name:- Rohan Tandekar And Rohit Gautam
E 8:- Write an algorithm,draw a flowchart and develop a c#.net console
application To overload binary operator ‘+’ and perform addition operation
between two complex numbers.

Coding:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication11
{
class Complex
{
int x, y;
public Complex()
{
x = y = 0;
}
public Complex(int i, int j)
{
x = i;
y = j;
}
public void showxy()
{
Console.WriteLine("{0} + i{1}",x, y);
}
public static Complex operator +(Complex c1, Complex c2)
{
Complex temp = new Complex();
temp.x = c1.x + c2.x;
temp.y = c1.y + c2.y;
return temp;
}
}
class Program
{
static void Main(string[] args)
{
int a, b;
Console.WriteLine("Enter the real no. of 1st complex no. ");
a = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the imaginary no. of 1st complex no. ");
b = int.Parse(Console.ReadLine());
Complex c1 = new Complex(a, b);
Console.WriteLine("Enter the real no. of 2nd complex no. ");
a = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the imaginary no. of 2nd complex no. ");
b = int.Parse(Console.ReadLine());
Complex c2 = new Complex(a, b);
Complex result = new Complex();
result = c1 + c2;
Console.Write("c1 = ");
c1.showxy();

Console.Write("c2 = ");
c2.showxy();
Console.Write("c1+c2 = ");
result.showxy();
Console.ReadLine();
}
}
}

Output:-
Enter the real no. of 1st complex no.
50
Enter the imaginary no. of 1st complex no.
16
Enter the real no. of 2nd complex no.
55
Enter the imaginary no. of 2nd complex no.
26
c1 = 50 + i16
c2 = 55 + i26
c1+c2 = 105 + i42
Name:- Rohan Tandekar And Rohit Gautam
E 9:- Write an algorithm,draw a flowchart and develop a c#.net console
application To implement the concept of hierarchical inheritance.

Coding:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
Principal g = new Principal();
Console.WriteLine("By using object of class principal");
g.monitor();
Teacher d = new Teacher();
Console.WriteLine("By using object of class teacher");
d.monitor();
d.teach();
Student s = new Student();
Console.WriteLine("By using object of class student");
s.monitor();
s.learn();
Console.ReadLine();
}
class Principal
{
public void monitor()
{
Console.WriteLine("Monitor");
}
}
class Student : Principal
{
public void learn()
{
Console.WriteLine("Learn");
}
}
class Teacher :Principal
{
public void teach()
{
Console.WriteLine("Teach");
}
}

}
}
Output:-
By using object of class principal
Monitor
By using object of class teacher
Monitor
Teach
By using object of class student
Monitor
Learn
Name:- Rohan Tandekar And Rohit Gautam
E 10:- Write an algorithm, draw a flowchart and develop a C#.Net console
application to implement the concept of interface

Coding:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
interface Addition
{
int Add();
}
interface multiplication
{
int Mul();
}
class Computation : Addition, multiplication
{
int x, y;
public Computation(int x, int y)
{
this.x = y;
this.y = y;
}
public int Add()
{
return (x + y);
}
public int Mul()
{
return (x * y);
}
}

class Program
{
static void Main(string[] args)
{
Computation com = new Computation(10, 10);
Addition add = (Addition)com;
Console.WriteLine("In First object");
Console.WriteLine("Sum=" + add.Add());
multiplication mul = (multiplication)com;
Console.WriteLine("Product" + mul.Mul());
//with another object
Computation com1 = new Computation(50, 50);
Addition add1 = (Addition)com1;
Console.WriteLine("\nIn Second object");
Console.WriteLine("Sum=" + add1.Add());
multiplication mul1 = (multiplication)com1;
Console.WriteLine("Product=" + mul1.Mul());
Console.ReadLine();
}
}

Output:-

In First object
Sum=20
Product100
In Second object
Sum=100
Product=2500
Name:- Rohan Tandekar And Rohit Gautam

W 1:-Write an algorithm , draw a flowchar and develop a c#.net


console application to check whether the enter number is positive,
negaitive or zero.

Coding:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int num;
Console.WriteLine("Input An integer: ");
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 Zero", num);
Console.ReadLine();
}
}
}

Output:-

Input An integer:
7
7 is a positive number

Input An integer:
-7
-7 is a negative number

Input An integer:
0
0 is Zero
Name:- Rohan Tandekar And Rohit Gautam

W 2:- 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.Linq;
using System.Text;

namespace ConsoleApplication1
{
class boxing
{
static void Main(string[] args)
{
int i = 786;
object obj = i;
Console.Write("\n the value type = {0}", i);
Console.WriteLine("\n the object type = {0}", obj);
Console.ReadLine();

i = 945;
Console.Write("\n the value type = {0}", i);
Console.WriteLine("\n the object type = {0}", obj);
Console.ReadLine();
int j = (int)obj;
Console.Write("\n the value type = {0}", j);
Console.ReadLine();
}
}
}

Output :-
the value type = 786
the object type = 786

the value type = 945


the object type = 786

the value type = 786


Name:- Rohan Tandekar And Rohit Gautam

W 3:-Write an algorithm , draw a flowchar 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 ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int n, sum = 0, m;
Console.WriteLine("Enter any Number:");
n = int.Parse(Console.ReadLine());
while (n > 0)
{
m = n % 10;
sum = sum + m;
n = n / 10;
}
Console.WriteLine("Sum of the Digit of Given Number is= " + sum);
Console.ReadLine();
}
}
}

Output:-

Enter any Number:


5621
Sum of the Digit of Given Number is= 14
Name:- Rohan Tandekar And Rohit Gautam

W 4:-Write an algorithm , draw a flowchar and develop a c#.net


console application to print the following pattern:
1

2 2

3 3 3

4 4 4 4

5 5 5 5 5

Coding:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int n = 5;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write("\t" + i);
}
Console.WriteLine("\n");
}
Console.ReadLine();
}
}
}

Output:-

2 2

3 3 3

4 4 4 4

5 5 5 5 5
Name:- Rohan Tandekar And Rohit Gautam

W 5:-Write an algorithm , draw a flowchar and develop a c#.net


console application to Print the factorial of given number.

Coding:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int i, fact = 1, number;
Console.WriteLine("Enter the Any Number: ");
number = int.Parse(Console.ReadLine());
for (i = 1; i <= number; i++)
fact = fact * i;
Console.WriteLine("Factorial of " + number + " is= " + fact);
Console.ReadLine();
}
}
}

Output:-

Enter the Any Number: 5


Factorial of 5 is= 120
Name:- Rohan Tandekar And Rohit Gautam
W 6:-Write an algorithm , draw a flowchar and develop a c#.net
console application to search a number from array using liner serch
method of array.

Coding:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[100];
Console.Write("Enter the number of Element you want to add on Array:
");
int n = int.Parse(Console.ReadLine());
Console.WriteLine("------------------------------");
Console.WriteLine("\nEnter Element in the Array :");
for (int i = 0; i < n; i++)
{
a[i] = int.Parse(Console.ReadLine());
}
Console.WriteLine("---------------------------------");
Console.WriteLine("\nEnter the Element to be search in the Array :");
int key = int.Parse(Console.ReadLine());
int flag = 0;
for (int i=0; i<n; i++)
{
if(a[i] == key)
{
flag = 1;
Console.WriteLine("---------------------------------");
Console.WriteLine("\nSearch Successful");
Console.WriteLine("Element {0} found at the location {1}\n",
key, i+1);
Console.ReadLine();
}
}
if (flag == 0)
{
Console.WriteLine("-------------------------------");
Console.WriteLine("\nEntered element not found.search
unsuccessful");
}
Console.ReadLine();
}
}
}
Output:-

Enter the number of Element you want to add on Array: 5


------------------------------

Enter Element in the Array :


12
13
14
15
16
---------------------------------

Enter the Element to be search in the Array :


15
---------------------------------

Search Successful
Element 15 found at the location 4

Enter the number of Element you want to add on Array: 5


------------------------------

Enter Element in the Array :


12
13
14
15
16
---------------------------------

Enter the Element to be search in the Array :


18
-------------------------------

Entered element not found.search unsuccessful


Name:- Rohan Tandekar And Rohit Gautam

W 7:-Write an algorithm , draw a flowchar and develop a c#.net


console application Add two three or four numbers using method
overloading .

Coding:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication11
{
class Addition
{
public void add(int a, int b)
{
int sum = a + b;
Console.WriteLine("{0} + {1} = {2}", a, b, sum);
}
public void add(int a, int b, int c)
{
int sum = a + b + c;
Console.WriteLine("{0} + {1} + {2} = {3}", a, b, c, sum);
}
public void add(int a, int b, int c, int d)
{
int sum = a + b + c + d;
Console.WriteLine("{0} + {1} + {2} + {3} = {4}", a, b, c, d, sum);
}
}
class Program
{
static void Main(string[] args)
{
Addition a = new Addition();
Console.WriteLine("Implementation of Method Overloading");
Console.WriteLine("-------------------------------------");
a.add(10, 30);
Console.WriteLine("-------------------------------------");
a.add(50, 80, 60);
Console.WriteLine("-------------------------------------");
a.add(40, 100, 56, 23);
Console.ReadLine();
}
}
}

Output:-

Implementation of Method Overloading


-------------------------------------
10 + 30 = 40
-------------------------------------
50 + 80 + 60 = 190
-------------------------------------
40 + 100 + 56 + 23 = 219
Name:- Rohan Tandekar And Rohit Gautam

W8.Write an algoritham, 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 ConsoleApplication33
{
class CalculateArea
{

public double result;


public virtual void area (double length , double width)
{

public void Showresult()


{
Console.WriteLine(" Your Result is {0}", result);
}

}
class Rectangel:CalculateArea
{
public override void area(double length, double width)
{
result = length *width;
}
}
class Triangle:CalculateArea
{
public override void area (double height, double
baseoftriabgle)
{
result=(height*baseoftriabgle)/2;
}
}
class program
{
static void Main(string[] args)
{
double l,w;
Console.WriteLine("Calculate Area of Reactangle");
Console.WriteLine("Enter Length and width of the
Reactangle:");
l=double.Parse(Console.ReadLine());
w=double.Parse(Console.ReadLine());
CalculateArea rect =new Rectangel();
rect.area(l,w);
rect.Showresult();
double h,b;

Console.WriteLine("\n--------------------------------------");
Console.WriteLine("Calculate Area of triangle");
Console.WriteLine("Enter height and base of the
triangle:");
h=double.Parse(Console.ReadLine());
b=double.Parse(Console.ReadLine());
CalculateArea tri=new Triangle();
tri.area(h,b);
tri.Showresult();
Console.ReadLine();

}
}
}

Output:-

Calculate Area of Reactangle


Enter Length and width of the Reactangle:
12
13
Your Result is 156

--------------------------------------
Calculate Area of triangle
Enter height and base of the triangle:
78.9
45.7
Your Result is 1802.865
Name:- Rohan Tandekar And Rohit Gautam

W 9:-Write an algorithm , draw a flowchar and develop a c#.net


console application to implement the concept of class and object.

Coding:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication7
{
class Student
{
public int id;
public String name;
}
class Program
{
static void Main(string[] args)
{
Student s1 = new Student();
s1.id = 101;
s1.name = "Rohit Gautam";
Console.WriteLine("\nImplementation of concept of class and
object\n");
Console.WriteLine("Student id=" +s1.id);
Console.WriteLine("Student name=" + s1.name);
Console.ReadLine();
}
}
}

Output:-

Implementation of concept of class and object


Student id=101
Student name=Rohit Gautam
Name:- Rohan Tandekar And Rohit Gautam

W 10:-Write an algorithm , draw a flowchar and develop a c#.net


console application to demonstrate divide by zero exception.

Coding:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
int a = 10;
int b = 5;
int c = 5;
int x, y;
try
{
x = a / (b - c);
}
catch (DivideByZeroException e)
{
Console.WriteLine(e.Message);
}
y = a / (b + c);
Console.WriteLine("y= " + y);
Console.ReadLine();
}
}
}

Output:-

Attempted to divide by zero.


y= 1

Das könnte Ihnen auch gefallen