Showing posts with label pattern design. Show all posts
Showing posts with label pattern design. Show all posts

Monday, September 12, 2016

List of Important Programs in C language

/*1. Program to calculate the factorial of a Number*/
#include<stdio.h>
int main()
{
int fact=1,i,Num;
printf("Enter the value of Num:");
scanf("%d",&Num);
for(i=2;i<=Num;i++)
    fact=fact*i;
     printf("\nFactorial of %d is %d",Num,fact);
return 1;  
}

/*Program to Check whether the number is prime or not*/
#include<stdio.h>
int main()
{
int flag=1,i,Num;
printf("Enter the value of Num:");
scanf("%d",&Num);
for(i=2;i<Num;i++)
{
  if ((Num%i)==0)
  {
   flag=0;
    }
}
     if(flag==1)
         printf("Prime Number");
    else
         printf("Not Prime Number");
return 1;  
}
/*Optimized Program to Check whether the number is prime or not*/
#include<stdio.h>
int main()
{
int flag=1,i,Num;
printf("Enter the value of Num:");
scanf("%d",&Num);
for(i=2;i<Num/2;i++)
{
  if ((Num%i)==0)
  {
   flag=0;
    }
}
     if(flag==1)
         printf("Prime Number");
    else
         printf("Not Prime Number");
return 1;  
}
/*Program to print the pattern

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

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

/*Program to print the pattern

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

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

/*Program to print the pattern

A
B B
C C C
D D D D
E E E E E

*/
#include<stdio.h>
int main()
{
int i,j,k;
for(i=65;i<=69;i++)
{
  for(j=65;j<=i;j++)
{
printf("%c ",i);
}
printf("\n");
}
return 1;  
}

/*Program to print the pattern

A
A B
A B C
A B C D
A B C D E

*/
#include<stdio.h>
int main()
{
int i,j,k;
for(i=65;i<=69;i++)
{
  for(j=65;j<=i;j++)
{
printf("%c ",j);
}
printf("\n");
}
return 1;  
}