1. WAP in c to for factorial of
a given number.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,a,s=1;
clrscr();
printf("\nEnter any
number: ");
scanf("%d",&a);
for(i=1;i<=a;i++)
{
s=s*i;
}
printf("\nfactorial of
%d is %d",a,s);
getch();
}
Output:
2. WAP in c for fibonacci series.
1 1 2 3 5 8 13 21
..........
#include<stdio.h>
#include<conio.h>
void main()
{
int f1=1,f2=1,f3=0,i=1;
clrscr();
printf("Fibonacci
series:");
printf("%d %d ",f1,f2);
while(i<=8)
{
f3=f1+f2;
printf("%d ",f3);
f1=f2;
f2=f3;
i++;
}
getch();
}
Output:
3. WAP in c to check whether a given number is prime or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,f=0;
clrscr();
printf("Enter any
number:");
scanf("%d",&n);
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
f=1;
break;
}
}
if(f==1)
{
printf("\nNot Prime
Number");
}
else
{
printf("\nPrime
Number");
}
getch();
}
4. WAP in c to generate all prime numbers from 1 to 100.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,f;
clrscr();
printf("\n\t\tPrime
numbers from 1 to 100\n");
for(i=1;i<=100;i++)
{
f=0;
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
f=1;
break;
}
}
if(f==0)
{
printf("%d\t",i);
}
}
getch();
}
Output:
5. WAP in c to find sum of digits of a given number.
#include<stdio.h>
#include<conio.h>
void main()
{
int r,s=0,n,t;
clrscr();
printf("\nEnter any
number:\n");
scanf("%d",&n);
t=n;
while(n!=0)
{
r=n%10;
n=n/10;
s=s+r;
}
printf("\nSum of digits
of %d is %d",t,s);
getch();
}
Output:
6. WAP in c to find reverse of digits of a given number.
#include<stdio.h>
#include<conio.h>
void main()
{
int r,s=0,n,t;
clrscr();
printf("\nEnter any
number:\n");
scanf("%d",&n);
t=n;
while(n!=0)
{
r=n%10;
n=n/10;
s=s*10+r;
}
printf("\nReverse of
digits of %d is %d",t,s);
getch();
}
Output:
7. WAP in c to check whether a given number is Armstrong or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int r,s=0,n,t;
clrscr();
printf("\nEnter any
number:\n");
scanf("%d",&n);
t=n;
while(n!=0)
{
r=n%10;
n=n/10;
s=s+r*r*r;
}
if(s==t)
{
printf("\nArmstrong
number");
}
else
{
printf("\nNot Armstrong
number");
}
getch();
}
Output:
8. WAP to print all Armstrong numbers from 1 to 1000.
#include<stdio.h>
#include<conio.h>
void main()
{
int r,s,n,t;
clrscr();
printf("\nArmstrong
numbers from 1 to 1000:\n");
for(t=1;t<=1000;t++)
{
s=0;
n=t;
while(n!=0)
{
r=n%10;
n=n/10;
s=s+r*r*r;
}
if(s==t)
{
printf("%d\t",t);
}
}
getch();
}
Output:
9. WAP in c to check whether a
given number is PALINDROME or not
(palindrome number is a number
which is equal to its reverse).
ex-121,1331 etc.
#include<stdio.h>
#include<conio.h>
void main()
{
int r,s=0,n,t;
clrscr();
printf("\nEnter any
number:\n");
scanf("%d",&n);
t=n;
while(n!=0)
{
r=n%10;
n=n/10;
s=s*10+r;
}
if(s==t)
{
printf("palindrome");
}
else
{
printf("not
palindrome");
}
getch();
}
10. WAP in c to print all
PALINDROME numbers from 1 to 1000.
palindrome number is a number
which is equal to its reverse.
ex-121,1331 etc.
#include<stdio.h>
#include<conio.h>
void main()
{
int r,s,n,t;
clrscr();
printf("\n\n\t\tpalindrome
numbers from 1 to 1000\n\n");
for(n=1;n<=1000;n++)
{
s=0;
t=n;
while(t!=0)
{
r=t%10;
t=t/10;
s=s*10+r;
}
if(s==n)
{
printf("%d\t",n);
}
}
getch();
}
No comments:
Post a Comment