Escolar Documentos
Profissional Documentos
Cultura Documentos
Date-19-DEC-2010*/
using System;
class Name
{
public static void Main()
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;
OUTPUT:
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:
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>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;
else
{
Console.WriteLine(x +"is an odd number");
}
OUTPUT:
using System;
class Demo
{
public static void Main()
Console.WriteLine("Hi");
}
class Demo1
{
{
Console.WriteLine("Hello");
return 0;
}
}
NOTE: Save the program such as test.cs and compile using command
OUTPUT: Hi
/* use of aliases for class*/
class sample
A.WriteLine(“Hello:”);
OUTPUT:
Hello:
/* print the following figure*/
Using System;
Class star
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 {
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
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
for(int i=0;i<10;i++)
if (input ==”X”)
break;
a.insert(I,input);
a.sort();
foreach(string product in a)
Console.WriteLine(product);
}
OUTPUT:
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
{ String str;
} Console.WriteLine(sb);
} }
OUTPUT:
programming
in
c#
by
balagurusamy
Write a program that count number of words in text documents.
using System;
class count
String str;
Str =Console.ReadLine();
String c= “ “;
for(int i=0;i<str.Length;i++)
{ if(str.substring(i,1)==c)
Count++;
OUTPUT:
programming in c# by balagurusamy”.
using System;
class count
String str;
Str =Console.ReadLine();
String c =Console.ReadLine();
for(int i=0;i<str.Length;i++)
{ if(str.substring(i,1)==c)
Count++;
BALAGURUSAMY
occurance of character is :3
write a program to sort the elements of an array.
using System;
class sort
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])
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
Class test
Student st;
st.name =”sunil”;
st.roll_no =10422;
st.marks=620;
Console.WriteLine(“ marks”+st.marks );
marks 620
write a program to calculate the area of rectangle.
using System;
struct rectangle
{ int a,b;
{ a=x;
b=y;
{return (a*b);}
{Console.WriteLine(“area = ”+ area());}
Class test
rect.display();
OUTPUT:
area =200
write a program to calculate area of circle and square with the help of
enumerator.
using System;
class area
{ circle;
square;
double area;
switch(shape)
Case Shape.circle
area = Math.PI*x*x;
break;
Case Shape.square
area = x*x;
break;
default:
Console.WriteLine(“invalid input”);
break;
Class test
a.areashape(15,area.Shape.circle);
a.areashape(15,area.Shape.square);
OUTPUT:
using System;
interface area
double compute(double x)
return (x*x);
return (Math.PI*x*x);
}
Class test
area a;
a = s as area;
a = c as area;
OUTPUT:
Using System;
Class star2
{ int m=1;
{ 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