Beruflich Dokumente
Kultur Dokumente
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int n,on,r,rn=0;
scanf("%d",&n);
on=n;
while(on!=0)
r=on%10;
rn=(r*r*r)+rn;
on=on/10;
if(rn==n)
printf("no is armstrong");
else
getch();
}
2. WAP to check whether a number is Armstrong or not using do while loop.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int n,on,r,rn=0;
scanf("%d",&n);
on=n;
do
{r=on%10;
rn=(r*r*r)+rn;
on=on/10;
}while(on!=0);
if(rn==n)
printf("no is armstrong");
else
getch();
}
3. WAP to convert binary number to decimal number suing while loop.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int n,nsave,rem,d,j=1,dec=0;
scanf("%d",&n);
nsave=n;
while(n>0)
rem=n%10;
d=rem+j;
dec=dec+d;
j=j*2;
n=n/10;
getch();
}
4. WAP to convert binary number to decimal number using do while loop.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int n,nsave,rem,d,j=1,dec=0;
scanf("%d",&n);
nsave=n;
do
rem=n%10;
d=rem+j;
dec=dec+d;
j=j*2;
n=n/10;
}while(n>0);
getch();
}
5. WAP to find the product of the digits of any number using while loop.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int n,r,mul=1;
scanf("%d",n);
while (n>0)
r=n%10;
mul=mul*r;
n=n/10;
getch();
}
6. WAP to find the product of the digit of any number using do while loop.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int n,r,mul=1;
scanf("%d",n);
do
r=n%10;
mul=mul*r;
n=n/10;
}while (n>0);
getch();
}
7. WAP to find the sum of the digits of any number using while loop.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int n,r,sum=0;
scanf("%d",&n);
while (n>0)
r=n%10;
sum=sum+r;
n=n/10;
printf("sum of digits=%d",sum);
getch();
}
8. WAP to find the sum of the digits of any number using do while loop.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int n,r,sum=0;
scanf("%d",&n);
do
r=n%10;
sum=sum+r;
n=n/10;
}while (n>0);
printf("sum of digits=%d",sum);
getch();
}
9. WAP to check whether the number is even or not using if else statement.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int a;
scanf("%d",&a);
if (a%2==0)
printf("number is even");
else
printf("number is odd");
getch();
}
10. WAP to print Fibonacci series using while loop.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int n,c,i=1,a=0,b=1;
scanf("%d",&n);
while(i<=n)
printf("%d",a);
c=a+b;
a=b;
b=c;
i++;
getch();
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int n,c,i=1,a=0,b=1;
scanf("%d",&n);
do
printf("%d",a);
c=a+b;
a=b;
b=c;
i++;
}while(i<=n);
getch();
12. WAP to print factorial of the given number using do while loop.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int n,fact=1;
scanf("%d",&n);
do
fact=fact*n;
n--;
}while(n>0);
13. WAP to print factorial of the given number using while loop.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int n,fact=1;
scanf("%d",&n);
while (n>0)
fact=fact*n;
n--;
printf("factorial=%d",fact);
getch();
14. WAP to find out the grade of a student when the marks of five subjects are given using if else
statement.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int s1,s2,s3,s4,s5;
int tot,per;
char grade;
scanf("%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5);
tot=s1+s2+s3+s4+s5;
per=tot/5;
if(per>=85)
grade='A';
else if(per>=70)
grade='B';
else if (per>=55)
grade='C';
else if (per>=40)
grade='D';
else
grade='E';
printf("\ntotal marks=%d",tot);
printf("\npercentage=%d",per);
printf("\ngrade=%c",grade);
getch();
}
15. WAP to check greater number between two numbers using if else statement.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int a,b;
scanf("%d%d",&a,&b);
if (a>b)
else
getch();
}
16. WAP to check a given year is leap year or not also check the year is century leap year or not
using if else statement.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int yr;
scanf("%d",&yr);
if(yr%100==0)
if (yr%400==0)
printf("century leap year");
else
else
if (yr%4==0)
printf("leap year");
else
getch();
17. WAP to print the multiplication of two numbers using while loop.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int a,b,mul=0;
scanf("%d%d",&a,&b);
while(b>0)
mul=mul+a;
b--;
printf("multiplication of above=%d",mul);
getch();
18. WAP to print the multiplication of two numbers using do while loop.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int a,b,mul=0;
scanf("%d%d",&a,&b);
do
mul=mul+a;
b--;
}while(b>0);
printf("multiplication of above=%d",mul);
getch();
#include<conio.h>
main()
clrscr();
int i=1;
do
printf("%d\n",i);
i++;
}while(i<=10);
getch();
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int i=10;
while (i>=1)
printf("%5d",i);
i--;
getch();
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int i=10;
do
printf("%d\n",i);
i--;
}while (i>=1);
getch();
22. WAP to check whether a number is palindrome or not using while loop.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int n,oi,r,ri=0;
scanf("%d",&n);
oi=n;
while(n!=0)
r=n%10;
ri=ri*10+r;
n=n/10;
if(oi==ri)
printf("no. is palindrome");
else
getch();
}
23. WAP to check whether a number is palindrome or not using do while loop.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int n,oi,r,ri=0;
scanf("%d",&n);
oi=n;
do
r=n%10;
ri=ri*10+r;
n=n/10;
}while(n!=0);
if(oi==ri)
printf("no. is palindrome");
else
getch();
24. WAP to check whether a number is positive or negative using if else statement.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int a;
if (a>=0)
printf("no. is positive");
else
printf("no. is negative");
getch();
25. WAP to find the power of given number using while loop.
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a,b,pow=1;
scanf("%d%d",&a,&b);
while (b>0)
pow=pow*a;
b--;
printf("a^b=%d",pow);
getch();
26. WAP to find the power of given number using do while loop.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int a,b,pow=1;
scanf("%d%d",&a,&b);
do
pow=pow*a;
b--;
}while (b>0);
printf("a^b=%d",pow);
getch();
}
27. WAP to check whether a number is prime number or not using while loop.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int a,i=2,f=0;
printf("enter a number");
scanf("%d",&a);
while (i<=a/2)
if(a%i==0)
f=1;
i++;
if (f==0)
printf("prime number");
else
getch();
}
28. WAP to check whether a number is prime or not using do while loop.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int a,i=2,f=0;
printf("enter a number");
scanf("%d",&a);
do
if(a%i==0)
f=1;
}
i++;
}while (i<=a/2);
if (f==0)
printf("prime number");
else
getch();
29. WAP to print the reverse of the digit of the number using while loop.
#include<stdio.h>
#include<conio.h>
main()
{
int a,s=0;
scanf("%d",&a);
while (a>0)
s=s%10;
s=s+(a%10);
a=a/10;
printf("reverse number=%d",s);
getch();
30. WAP to print the reverse of the digit of the number using do while loop.
#include<stdio.h>
#include<conio.h>
main()
int a,s=0;
scanf("%d",&a);
do
s=s%10;
s=s+(a%10);
a=a/10;
}while (a>0);
printf("reverse number=%d",s);
getch();
#include<conio.h>
main()
clrscr();
int i=2;
while (i<=20)
printf("%d\n",i);
i=i+2;
getch();
}
32. WAP to print the table of 2 using do while loop.
#include<stdio.h>
#include<conio.h>
main()
clrscr();
int i=2;
do
printf("%d\n",i);
i=i+2;
}while (i<=20);
getch();