Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

1:WAP to print hello in C#

using System;
class myclass
{
public static void Main()
{
Console.WriteLine("hello");
}
}

2:WAP for command line argument


GAURAV KUMAR SHUKLA

Page 1

using System;

class test
{
public static void Main(String []ar)

{
Console.WriteLine("welcome");
Console.WriteLine(" "+ar[0]);
Console.WriteLine(" "+ar[1]);
}
}

3:WAP for taking input through the keyboard


GAURAV KUMAR SHUKLA

Page 2

using System;
class test
{
public static void Main()
{
Console.WriteLine("Enter your name");
string name=Console.ReadLine();
Console.WriteLine("Hello"+name);
}
}

4:WAP for using multiple main in a single program


GAURAV KUMAR SHUKLA

Page 3

using System;
class first
{
public static void Main()
{
Console.WriteLine("This is first main");
}

}
class second
{
public static void Main()
{
Console.WriteLine("this is second main");
}
}

5:Multi-file program
using System;
GAURAV KUMAR SHUKLA

Page 4

class first
{
Public void disp()
{
Console.WriteLine("Enter your name");
string str=Console.ReadLine();
Console.WriteLine("Welcome"+str);
}
}
using System;
class second
{
public static void Main()
{
first t1=new first();
t1.disp();
Console.WriteLine("thank you");
}
}

6:WAP for swapping numbers


using System;
class swap
GAURAV KUMAR SHUKLA

Page 5

public static void Main()


{
int a=15;
int b=10;
Console.WriteLine("The value of a before swapping ="+a);
Console.WriteLine("the value of b before swapping="+b);
a=a+b;
b=a-b;
a=a-b;
Console.WriteLine("after swapping the value of a="+a);
Console.WriteLine("after swapping the value of b="+b);
}

7:Initialization of variables ion C#


using System;
class first
{
GAURAV KUMAR SHUKLA

Page 6

public static void Main()


{
test t1=new test();
t1.b=1;
test t2=new test();
t2.b=2;
test.a=4;
t1.show();
t2.show();
}
}
class test
{
public static int a;
public int b;
public void show()
{
Console.WriteLine("value of a={0} value of b={1}",a,b);
}
}

8:WAP to find a Armstrong number


using System;
class arm
{
public static void Main()
GAURAV KUMAR SHUKLA

Page 7

{
int n,n1,rem,num=0;
Console.WriteLine("enter the number");
n=int.Parse(Console.ReadLine());
n1=n;
while(n1!=0)

{
rem=n1%10;
num+=rem*rem*rem;
n1/=10;

}
if(num==n)
Console.WriteLine("Number Is armstrong number");
else
Console.WriteLine("number is not armsrtong");
}
}

9:WAP to find sum of digits of a number


using System;
class digit
{
public static void Main()
{
GAURAV KUMAR SHUKLA

Page 8

Console.WriteLine("Enter the number");


int number=int.Parse(Console.ReadLine());
int sum = 0;
int input = number;
while (input != 0)
{
int lastdigit = input % 10;
sum += lastdigit;
input /= 10;
}

Console.WriteLine("Sum of digit is"+sum);


}
}

10:WAP to print Fibonacci series


using System;
class fab
{
public static void Main()
{
int k,r;
GAURAV KUMAR SHUKLA

Page 9

int i=0,j=1,f;

Console.WriteLine("Enter the range");


r=int.Parse(Console.ReadLine());
for(k=2;k<r;k++)
{
f=i+j;
i=j;
j=f;
Console.WriteLine(" "+j);

}
}
}

11:WAP to find palindrome number


using System;
class pal
{
public static void Main()
{
int n,rev=0,rem,temp;
Console.WriteLine("Enter the number");
GAURAV KUMAR SHUKLA

Page 10

n=int.Parse(Console.ReadLine());
temp=n;
while(temp!=0)
{
rem=temp%10;
rev=rev*10+rem;
temp= temp/10;

}
if(rev==n)
Console.WriteLine("palindrome number");
else
Console.WriteLine("not palindrome");

}
}

12:WAP to find a prime number


using System;
class prime
{
public static void Main()
{
int n,i,flag=0;
Console.WriteLine("enter the positive number");
n=int.Parse(Console.ReadLine());
GAURAV KUMAR SHUKLA

Page 11

for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(flag==0)
Console.WriteLine("Prime Number");
else
Console.WriteLine("Not a prime number");
}
}

13:WAP to find reverse of a given number


using System;
class rev
{
public static void Main()
{
int num,r,rev=0;
Console.WriteLine("Enter the number");
num=int.Parse(Console.ReadLine());
while(num>0)
GAURAV KUMAR SHUKLA

Page 12

{
r=num%10;
rev=rev*10+r;
num=num/10;
}
Console.WriteLine("reverse of number"+rev);
}
}

14:WAP print the pattern


using System;
class pat1
{
public static void Main()
{
int i,j;

for(i=1;i<=4;++i)
{
for(j=1;j<=i;++j)
GAURAV KUMAR SHUKLA

Page 13

{
Console.Write("*");
}
Console.Write("\n");
}

}
}

15:WAP to print the pattern


using System;
class pat2
{
public static void Main()
{
int i,space,k=0;

for(i=1;i<=4;++i)
{
for(space=1;space<=4-i;++space)
{
GAURAV KUMAR SHUKLA

Page 14

Console.Write(" ");
}
while(k!=2*i-1)
{
Console.Write("* ");
++k;
}
k=0;
Console.Write("\n");
}

}}

16:WAP to print pattern


using System;
class pat3
{
public static void Main()
{
int i,space,k=0;

for(i=1;i<=4;++i)
{
for(space=1;space<=4-i;++space)
{
Console.Write(" ");
GAURAV KUMAR SHUKLA

Page 15

}
while(k!=2*i-1)
{
Console.Write("* ");
++k;
}
k=0;
Console.Write("\n");
}

}
}

17:WAP to pattern
using System;
class pat5
{
public static void Main()
{
int i,j;
j=1;
for(i=1;i<=4;i++)
{
for(int c=4-i;c>=1;c--)
Console.Write(" ");
for(j=1;j<=i;j++)
Console.Write(j+"");
GAURAV KUMAR SHUKLA

Page 16

for(j=i-1;j>=1;j--)
Console.Write(j+"");

Console.Write("\n");

}
Console.ReadKey();
}
}

GAURAV KUMAR SHUKLA

Page 17

You might also like