Você está na página 1de 26

/* simple program to print Name

Date-19-DEC-2010*/

using System;

class Name
{
public static void Main()

Console.WriteLine("MY NAME IS SUJIT");

OUTPUT:

MY NAME IS SUJIT
/* program to calculate Temperature in celcius
Date-19-DEC-2010*/

using System;

class Con
{
public static void Main()

{
double c,f;

Console.WriteLine("Enter the temperature in Farenhite ");


f=int.Parse(Console.ReadLine());
c=(f-32)/1.8;
Console.WriteLine("Temperature in celcius is = "+c);
}

OUTPUT:

Enter the temperature in Farenhite

22
/*illustrate math function using example
Date-19-DEC-2010*/

using System;

class loan
{
public static void Main()

{
double d;
int ch;
Console.WriteLine("choose 1 for sin");
Console.WriteLine("choose 2 for cos");
Console.WriteLine("choose 3 for tan");
Console.WriteLine("choose 4 for Asin");
Console.WriteLine("choose 5 for Acos");
Console.WriteLine("choose 6 for Atan");

ch=int.Parse(Console.ReadLine());

Console.WriteLine("enter degree");

d=double.Parse(Console.ReadLine());

double rad=d*(Math.PI/180);

switch(ch)
{
case 1:
Console.WriteLine(d+"="+Math.Sin(rad));
break;
case 2:
Console.WriteLine(d+"="+Math.Cos(rad));
break;
case 3:
Console.WriteLine(d+"="+Math.Tan(rad));
break;
case 4:
Console.WriteLine(d+"="+Math.Asin(rad));
goto case 1;
case 5:
Console.WriteLine(d+"="+Math.Acos(rad));
goto case 2;
case 6:
Console.WriteLine(d+"="+Math.Atan(rad));
goto case 3;

}
}
}

OUTPUT:

choose 1 for sin


choose 2 for cos
choose 3 for tan
choose 4 for Asin
choose 5 for Acos
choose 6 for Atan
1
enter degree:90

d =0.89999999
/* loan
Date-22-DEC-2010*/
using System;
class loan
{
public static void Main()

{ string name;
int salary;
Console.WriteLine("enter the name");
name=Console.ReadLine();
Console.WriteLine("enter the salary");
salary=int.Parse(Console.ReadLine());
if(salary<30000)
Console.WriteLine("no loan given");

else if(salary>=30000 && salary<49999)


Console.WriteLine("5 lakh loan");

else if(salary>=50000 && salary<100000)


Console.WriteLine("8 lakh loan");

else if(salary>=100000 && salary<150000)


Console.WriteLine("10 lakh loan");

else if(salary>=150000 && salary<300000)


Console.WriteLine("15 lakh loan");

else if(salary>=300000 && salary<600000)


Console.WriteLine("50 lakh loan");

else if(salary>600000)
Console.WriteLine("30 lakh loan");
}
}
OUTPUT:
Enter the name:SUJIT
Enter the salery :30000
5 lakh loan
/* odd or even method
Date-22-DEC-2010*/

using System;

class num
{
public static void Main()

{
int x;

Console.WriteLine("Enter the number");


x=int.Parse(Console.ReadLine());
if(x%2==0)
{
Console.WriteLine(x +"is an even number");
}

else
{
Console.WriteLine(x +"is an odd number");
}

OUTPUT:

Enter the number


22
22 is an even number
/* Multiple Main method
Date-22-DEC-2010*/

using System;

class Demo
{
public static void Main()

Console.WriteLine("Hi");
}

class Demo1
{

public static int Main()

{
Console.WriteLine("Hello");
return 0;
}

}
NOTE: Save the program such as test.cs and compile using command

csc test.cs /Main: Demo

And now simply right test

OUTPUT: Hi
/* use of aliases for class*/

using A =System.Console; //a is alliase for System.Console

class sample

Public void static Main()

A.WriteLine(“Hello:”);

OUTPUT:

Hello:
/* print the following figure*/

Using System;

Class star

Public static void Main()

for(int i=1;i<=5;i++)

for(int j=1;j<=i;j++)

Console.WriteLine(“ *”);

Console.WriteLine(“\n”);

OUTPUT:

*
* *
* * *
* * * *
* * * * *
/* print the following figure*/

Using System;

Class star1 {

Public static void Main()

for(int i=1;i<4;i++)

for(int k=3;k>i;k--)

Console.Write(“ ”);

for(int j=3;j<i;j++)

Console.Write(“ * ”);

Console.Write(“ ”);

Console.WriteLine(“\n”);

*
* *
* * *
/* print the following figure*/

Using System;

Class star1

Public static void Main()

for(int i=1;i<4;i++)

for(int k=3;k>i;k--)

Console.Write(“ ”);

for(int j=3;j<i;j++)

Console.Write(“ * ”);

Console.Write(“ ”);

Console.WriteLine(“\n”);

}
for(int x=3;x>1;x--)

for(int y=4;y>x;y--)

Console.Write(“ ”);

for(int z=i;z<x;z++)

Console.Write(“ * ”);

Console.Write(“ ”);

Console.WriteLine(“\n”);

OUTPUT:

*
* *
* * *
* *
*
Write a program to accept shopping list on user demand and store them
in the string type array and display them in alphabetical order.

using System;

using System.Collection;

Class shop

Public static void Main()

ArrayList a = new ArrayList();

Console.WriteLine(“enter the products:”);

for(int i=0;i<10;i++)

Console.Write(“product:”+ (i+1)+”(X to exit )”);

String input = Console.ReadLine();

if (input ==”X”)

break;

a.insert(I,input);

a.sort();

foreach(string product in a)

Console.WriteLine(product);

}
OUTPUT:

enter the products:

product:1 X to exit

RICE

product:2 X to exit

CORN FLAKES

product:3 X to exit

CORIENDER

product:4 X to exit

BEANS

product:1 X to exit

BEANS

CORIENDER

CORN FLAKES

RICE
Write a program to split the string ” programming in c# , by balagurusamy!”.

using System;

using System.Text;

using System.Text.RegularExpressions;

Class test

{ Public static void Main()

{ String str;

Str = “programming in c# , by balagurusamy!”;

Regex reg = new Regex(“ |, ”);

StringBuilder sb = new StringBuilder();

Int count =1;

foreach(string sub in reg.Split(str))

sb.AppendFormat(“{0}: {1} \n”,count++ ,sub);

} Console.WriteLine(sb);

} }

OUTPUT:

programming

in

c#

by

balagurusamy
Write a program that count number of words in text documents.

using System;

class count

{ Public static void Main()

String str;

Console.WriteLine(“Enter the Text documents:”);

Str =Console.ReadLine();

String c= “ “;

int count =1;

for(int i=0;i<str.Length;i++)

{ if(str.substring(i,1)==c)

Count++;

Console.WriteLine(“No. of words in text documents is :” +count);

OUTPUT:

Enter the Text documents:

programming in c# by balagurusamy”.

No. of words in text documents is:5


Write a program that count number of occurance of a character in a line .

using System;

class count

{ Public static void Main()

String str;

Console.WriteLine(“Enter the string:”);

Str =Console.ReadLine();

Console.WriteLine(“Enter the character to be searched :”);

String c =Console.ReadLine();

int count =0;

for(int i=0;i<str.Length;i++)

{ if(str.substring(i,1)==c)

Count++;

Console.WriteLine(“occurance of character is :” +count);

OUTPUT: Enter the string:

BALAGURUSAMY

Enter the character to be searched :A

occurance of character is :3
write a program to sort the elements of an array.

/*sorting the elements*/

using System;

class sort

Public static void Main()

int[] number = {55, 40 ,80 ,65,71};

int n =number.Length;

Console.WriteLine(“given list”);

for(int i=0;i<n;i++)

Console.Write(“ ” + number[i]);

Console.WriteLine(“\n”);

for(i=0;i<n;i++)

for(j=i+1;j<n;j++)

if(number[i]<number[j])

int temp = number[i];


number[i]= number[j];

number[j] = temp;

Console.WriteLine(“sorted list:”);

for(int i=0;i<n;i++)

Console.Write(“ ” + number[i]);

Console.WriteLine(“ ” );

OUTPUT:

given list: 55 40 80 65 71

sorted list: 40 55 65 71 80
Write a program to take the name, roll no and marks of a students and display
with the use of structure.

using System;

struct student

Public string name;

Public int roll_no ,marks;

Class test

{ Public static void Main()

Student st;

st.name =”sunil”;

st.roll_no =10422;

st.marks=620;

Console.WriteLine(“student name ”+st.name );

Console.WriteLine(“roll number ”+ st.roll_no );

Console.WriteLine(“ marks”+st.marks );

OUTPUT: student name SUJIT

roll number 10431

marks 620
write a program to calculate the area of rectangle.

using System;

struct rectangle

{ int a,b;

public rectangle(int x, int y)

{ a=x;

b=y;

public int area()

{return (a*b);}

public void display()

{Console.WriteLine(“area = ”+ area());}

Class test

{ Public static void Main()

rectangle rect = new rectangle(10,20);

rect.display();

OUTPUT:

area =200
write a program to calculate area of circle and square with the help of
enumerator.

using System;

class area

public enum Shape

{ circle;

square;

public void areashape(int x ,Shape shape)

double area;

switch(shape)

Case Shape.circle

area = Math.PI*x*x;

Console.WriteLine(“circle area = ”+ area);

break;

Case Shape.square

area = x*x;

Console.WriteLine(“square area = ”+ area);

break;

default:
Console.WriteLine(“invalid input”);

break;

Class test

public static void Main()

Area a = new area();

a.areashape(15,area.Shape.circle);

a.areashape(15,area.Shape.square);

OUTPUT:

circle area =706.8583

square area = 225.0000


Write a program to compute area of circle and square .Illustate the concept of
multiple implementation of interface.

using System;

interface area

double compute(double x)

class square: area

public double compute(double x)

return (x*x);

class square: area

public double compute(double x)

return (Math.PI*x*x);

}
Class test

public static void Main()

square s =new square();

circle c= new circle();

area a;

a = s as area;

Console.WriteLine(“area of square =”+a.compute(10.0));

a = c as area;

Console.WriteLine(“area of circle =”+a.compute(10.0));

OUTPUT:

area of square =100

area of circle = 314.1592


/* print the following figure*/

Using System;

Class star2

{ int m=1;

Public static void Main()

{ for(int i=1;i<5;i++)

{ for(int k=4;k>i;k--)

{ Console.Write(“ ”);

for(int j=1;j<=i;j++)

{ Console.Write(“ m ”);

Console.Write(“ ”);

m =m+1;

Console.WriteLine(“\n”);

OUTPUT:

1
2 3
4 5 6
7 8 9 10

Você também pode gostar