You are on page 1of 4

Loop

Write a program to find the factorial of given number.


Explanation:
This program find the factorial of the given number. This symbol (!) is factorial symbol.
e.g.
factorial of 2! = 2*1=2
factorial of 3! = 3*2*1=6

#include<stdio.h>
#include<conio.h>
main()
{
int n,fact=1;
clrscr();
printf("Enter the any number");
scanf("%d",&n);
while(n>0)
{
fact=fact*n;
n=n-1;

}
printf("The factorial is=%d\n",fact);

getch();
}
Output:
Enter the any number
5
The factorial is=120

write a program to print the febeonic series.


#include<stdio.h>
#include<conio.h>
main()
{
int n,a=0,b=1,s=0;
clrscr();
printf("Enter the any number");
scanf("%d",&n);
printf("The febeonic sereis is=%d %d ",a,b);
while(s<=n)
{
s=a+b;
a=b;
b=s;
printf(" %d ",s);

getch();
}

Output:
Enter the any number
21
The febeonic sereis is=0 1 1 2 3 5 8 13 21

Write a program to check a number is prime or not.


Explanation:

A number is said to a prime number if it divisible by only itself.


e.g.
7 is prime number because it is divisible by itself only.

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

}
if(n==i)
printf("Prime Number");

getch();
}

Output:
Enter the any number
66
Not Prime

PATTERN MATCHING
Write a program to print this figure.
12345
1234
123
12
1
#include<stdio.h>
#include<conio.h>
main()
{
int i,j;
clrscr();
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf(" %d",j);
}
printf("\n");

}
getch();
}

Output:
12345
1234
123
12
1

Write a program to print this type figure.


*****
****
***
**
*

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

Output:
*****
****
***
**
*

You might also like