4.WAP to check whether the given number is even or odd.

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
printf("Enter the number");
scanf("%d",&n);
if(n%2==0)
printf("The given number is even");
else
printf("The given number is odd");
getch();
}

5.WAP to enter two number & find largest among them.

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("Enter two number:");
scanf("%d%d",&a,&b);
if(a>b)
printf("The largest number is %d");
else
printf("The largest number is %d ",b);
getch();
}


6.WAP to find largest number among three number.

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter three number:");
scanf("%d%d%d",&a,&b,&c);
if(a>b&&a>c)
printf("The largest number is %d",a);
else if(b>c)
printf("The largest number is % d",b);
else
printf("The largest number is %d",c);
getch();
}


7.WAP to find middle number among three number.

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter three number:");
scanf("%d%d%d",&a,&b,&c);
if((a>b&&a<c)||(a>c&&a<b))
printf("The middle number is %d",a)
else if((b>a&&b<c)||(b>c&&b<a))
printf("The middle number is % d",b);
else
printf("The largest number is %d",c);
getch();
}

8. WAP that reads marks of five subject & calculate total marks, percent and find division.

#include<stdio.h>
#include<conio.h>
void main()
{
int s1,s2,s3,s4,s5,total;
float per;
printf("Enter five subjects marks:");
scanf("%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5);
total=s1+s2+s3+s4+s5;
per=total/5;
if(s1>=35&&s2>=35&&s3>=35&&s4>=35&&s5>=35)
{
if(per>=75&&per<=100)
printf("Congratulation : Distinction");
else if(per>=60)
printf("First Division");
else if(per>=45)
printf("Second Division");
else
printf("Third Division");
}
else
printf("Failed : Try again later");
gerch();
}

9. WAP which reads two number and calculate sum, different & product of those number by using switch case.

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,ch;
printf("Enter two number:");
scanf("%d%d",&a,&b);
printf("\n1.Sum");
printf("\n2.Different");
printf("\n3.Product");
printf("Enter your choice from above Manu:");
scanf("%d",&ch);
switch(ch)
{
case 1:
c=a+b;
printf("Sum of given number is %d",c);
break;
case 2:
c=a-b;
printf("Different of given number is %d",c);
break;
case 3:
c=a*b;
printf("Product of given number is %d",c);
break;
default:
printf("Wrong choice. Please enter only 1-3");
}
getch();
}


10.WAP to display your name 30 times using three types of loop.

#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
while(i<=30)
{
printf("\n My name is HARI");
i++;
}
getch();
}


11.WAP to calculate factorial of given number.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,fact=1;
printf("Enter a number");
scanf("%d",&n);
for(i=1;i<=n;i++)
fact=fact*i;
printf("The factorial of %d is %d",n,fact);
getch();
}


12.WAP to display multiplication table of given number.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
printf("Enter a number");
scanf("%d",&n);
for(i=1;i<=10;i++)
printf("%d*%d=%d",n,i,n*i);
getch();
}


13.WAP to calculate X*Y using loop.

#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,i,sum=o;
printf("Enter the value of x and y");
scanf("%d%d",&x,&y);
for(i=1;i<=y;i++)
{
sum=sum+x;
}
printf("Sum = %d",sum);
getch();
}


14.WAP to calculate Xn using loop.

#include<stdio.h>
#include<conio.h>
void main()
{
int x,n,i,sum=1;
printf("Enter the value of x and n");
scanf("%d%d",&x,&n);
for(i=1;i<=n;i++)
{
sum=sum*x;
}
printf("Answer = %d",sum);
getch();
}


15.WAP to display the series 3 5 7 9 ………nth terms.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,a=3;
printf("Enter how many terms");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("%d\t",a);
a+2;
}
getch();
}


16.WAP to display the following.
1
12
123
1234
12345

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d\t",j);
}
printf("\n");
}
getch();
}


17. WAP to display the following.
1
22
333
4444
55555

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d\t",i);
}
printf("\n");
}
getch();
}

18.WAP to display following.
1 2 3 4 5……10
2 4 . . . . 3 6 . . . . 4 8 . . . . 5 10 . . . .
. . . . . .
. . . . . . 10 20 . . . 100

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d\t",i*j);
}
printf("\n");
}
getch();
}

19.WAP to display following.
*
**
***
****
*****

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
for(i=1;i<=5;i++)
{
for(k=i;k<=4;i++)
printf(" ");
for(j=1;j<=i;j++)
printf("*");
printf("\n");
}
getch();
}


20.WAP to display following.
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *


#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
for(i=1;i<=5;i++)
{
for(k=i;k<=4;i++)
printf(" ");
for(j=1;j<=2*i-1;j++)
{
printf("*");
printf(" ");
}
printf("\n");
}
getch();
}


21.WAP to display following.
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
5 6 7 8 9

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=0;i<5;i++)
{
for(j=1;j<=5;j++)
{
printf("%d\t",i*j);
}
printf("\n");
}
getch();
}

22.WAP to display following.
5 10 15 20 25
10 15 20 25 30
15 20 25 30 35
20 25 30 35 40
25 30 35 40 45

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=0;i<5;i++)
{
for(j=1;j<=5;j++)
{
printf("%d\t",(i*j)*5);
}
printf("\n");
}
getch();
}


23.WAP to display following.
A
A B
A B C
A B C D
A B C D E

#include<stdio.h>
#include<conio.h>
void main()
{
char i,j,k;
for(i=65;i<=69;i++)
{
for(k=i;k<=68;i++)
printf(" ");
for(j=65;j<=i;j++)
{
printf("%d",i);
printf(" ");
}
printf("\n");
}
getch();
}


24.WAP to display Pascal triangle.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1


#include<stdio.h>
#include<conio.h>
void main()
{
char i,j,k,n,a;
printf("Enter row sizes:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
for(k=i;k<=n-1;i++)
printf(" ");
a=1;
for(j=0;j<=i;j++)
{
printf(" %d",a);
a=a*(i-j)/(j+1);
}
printf("\n");
}
getch();
}

 

25.WAP to display following.
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a=1;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d\t",a);
a++;
}
printf("\n");
}
getch();
}


26.WAP to print fibonacci series 0 1 1 2 3 5 8………n terms.


#include<stdio.h>
#include<conio.h>
void main()
{
int a=0,b,=1,c,n,i;
printf("Enter how many terms:");
scanf("%d",&n);
printf("The Fibonacci series is : %d",a);
for(i=1;i<n;i++)
{
c=a+b;
a=b;
b=c;
prinrf("\t%d",a);
}
getch();
}

27.WAP to calculate sum of given digit number.(Take 4 digit number)

#include<stdio.h>
#include<conio.h>
void main()
{
int n,d,sum=0;
printf("Enter a number");
scanf("%d",&n);
while(n!=0)
{
if(n>=1000&&n<=9999)
{
d=n%10;
sum=sum+d;
n=n/10;
}
}
printf("Sum =%d",sum);
getch();
}

28.WAP to check the given number is palindrome or not.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,d,sum=0,temp;
printf("Enter a number");
scanf("%d",&n);
temp=n;
while(n!=0)
{
d=n%10;
sum=sum*10+d;
n=n/10;
}
if(temp==sum)
printf("The given number is palindrome");
else
printf("The given number is not palindrome");
getch();
}


29.WAP to check the given number is Armstrong number or not.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,d,sum=0,temp;
printf("Enter a number");
scanf("%d",&n);
temp=n;
while(n!=0)
{
d=n%10;
sum=sum+d*d*d;
n=n/10;
}
if(temp==sum)
printf("The given number is Armstrong number ");
else
printf("The given number is not Armstrong number ");
getch();
}


30.WAP to convert the given binary number into equivalent decimal number.

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,d,sum=0,p=0;
printf("Enter a number");
scanf("%d",&n);
while(n!=0)
{
d=n%10;
sum=sum+d*pow(2,p);
n=n/10;
p++;
}
printf("The decimal number is %d",sum);
getch();
}


31.WAP to convert from decimal to binary number.


#include<stdio.h>
#include<conio.h>
void main()
{
int n,d,sum=0,i=1;
printf("Enter a number");
scanf("%d",&n);
while(n!=0)
{
d=n%2;
sum=sum+d*i;
n=n/2;
i*10;
}
printf("The binary number is %d",sum);
getch();
}


32.WAP to check whether given number is prime or not (composite).

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
printf("Enter a number");
scanf("%d",&n);
for(i=2;i<n;i++)
{
if(n%i==0)
{
printf("Not Prime");
break;
}
else
{
printf("Prime");
break;
}
}
getch();
}


33.WAP to print all prime number from 1 to 100.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=1;i<=100;i++)
{
for(j=2;j<i;j++)
{
if(i%j==0)
{
break;
}
}
if(i==j)
printf("%d\t",i);
}
getch();
}


34.WAP to HCF and LCM of two numbers.

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,x,y,s,t,result;
printf("Enter two number:");
scanf("%d%d",&a,&b);
s=a;
t=b;
while(a!=b)
{
if(a>b)
{
x=a-b;
a=b;
b=x;
continue;
}
if(b>a)
{
x=b-a;
b=a;
a=x;
continue;
}
}
printf("HCF=%d",a);
x=s/a;
y=t/a;
result=a*x*y;
printf("LCM=%d",result);
getch();
}

Last edited Dec 4, 2015 at 6:58 AM by vineetchoudhary, version 1