0% found this document useful (0 votes)
63 views

A 'C' Progamming Laanguage File

The document contains 32 code snippets demonstrating the use of while and do-while loops in C programming. The snippets show examples of using loops to check if a number is Armstrong, convert between binary and decimal, find digit sums and products, check even/odd, print Fibonacci series, calculate factorials, grade calculation, comparison of numbers, check leap years, multiplication, number series, palindrome checks, positive/negative checks, exponents, prime checking, number reversal, and number table printing.

Uploaded by

Raj Aman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

A 'C' Progamming Laanguage File

The document contains 32 code snippets demonstrating the use of while and do-while loops in C programming. The snippets show examples of using loops to check if a number is Armstrong, convert between binary and decimal, find digit sums and products, check even/odd, print Fibonacci series, calculate factorials, grade calculation, comparison of numbers, check leap years, multiplication, number series, palindrome checks, positive/negative checks, exponents, prime checking, number reversal, and number table printing.

Uploaded by

Raj Aman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

1. WAP to check whether a number is Armstrong or not.

#include<stdio.h>

#include<conio.h>

main()

clrscr();

int n,on,r,rn=0;

printf("enter any number");

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

printf("no is not armstrong");

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;

printf("enter any number");

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

printf("no is not armstrong");

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;

printf("enter the no. in binary");

scanf("%d",&n);

nsave=n;

while(n>0)

rem=n%10;

d=rem+j;

dec=dec+d;

j=j*2;

n=n/10;

printf("binary number=%d, decimal number=%d\n",nsave,dec);

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;

printf("enter the no. in binary");

scanf("%d",&n);

nsave=n;

do

rem=n%10;

d=rem+j;

dec=dec+d;

j=j*2;

n=n/10;

}while(n>0);

printf("binary number=%d, decimal number=%d\n",nsave,dec);

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;

printf("enter any number");

scanf("%d",n);

while (n>0)

r=n%10;

mul=mul*r;

n=n/10;

printf("product of above digits=%d",mul);

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;

printf("enter any number");

scanf("%d",n);

do

r=n%10;

mul=mul*r;

n=n/10;

}while (n>0);

printf("product of above digits=%d",mul);

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;

printf("Enter any five digit number");

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;

printf("Enter any five digit number");

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;

printf("enter any number");

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;

printf("enter any number");

scanf("%d",&n);

while(i<=n)

printf("%d",a);

c=a+b;

a=b;

b=c;
i++;

getch();

11. WAP to print Fibonacci series using do while loop.

#include<stdio.h>

#include<conio.h>

main()

clrscr();

int n,c,i=1,a=0,b=1;

printf("enter any number");

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;

printf("enter the number");

scanf("%d",&n);

do

fact=fact*n;

n--;

}while(n>0);

printf("factorial of given no.=%d",fact);


getch();

13. WAP to print factorial of the given number using while loop.

#include<stdio.h>

#include<conio.h>

main()

clrscr();

int n,fact=1;

printf("enter any number");

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;

printf("enter five subjects marks");

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;

printf("enter any two numbers");

scanf("%d%d",&a,&b);

if (a>b)

printf("a is greater than b");

else

printf("b is greater than a");

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;

printf("enter the year");

scanf("%d",&yr);

if(yr%100==0)

if (yr%400==0)
printf("century leap year");

else

printf("not century leap year");

else

if (yr%4==0)

printf("leap year");

else

printf("not leap year");

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;

printf("enter value of a nad b");

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;

printf("enter value of a nad b");

scanf("%d%d",&a,&b);

do

mul=mul+a;

b--;

}while(b>0);

printf("multiplication of above=%d",mul);

getch();

19. WAP to print the series of numbers 1 to 10 using do while loop.


#include<stdio.h>

#include<conio.h>

main()

clrscr();

int i=1;

do

printf("%d\n",i);

i++;

}while(i<=10);

getch();

20. WAP to print the series of numbers 10 to 1 using while loop.

#include<stdio.h>
#include<conio.h>

main()

clrscr();

int i=10;

while (i>=1)

printf("%5d",i);

i--;

getch();

21. WAP to print the series of numbers 10 to 1 using do while loop.

#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;

printf("enter any number");

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

printf("no. is not palindrome");

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;

printf("enter any number");

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

printf("no. is not palindrome");

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;

printf("enter any number");


scanf("%d",&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;

printf("enter the value of a and b");

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;

printf("enter the value of a and b");

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

printf("not prime number");

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

printf("not prime number");

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;

printf("entre value of A");

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;

printf("entre value of A");

scanf("%d",&a);

do

s=s%10;

s=s+(a%10);

a=a/10;

}while (a>0);

printf("reverse number=%d",s);

getch();

31. WAP to print the table of 2 using while loop.


#include<stdio.h>

#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();

You might also like