Posts

Showing posts with the label C Language

program for printing fibonacci series

#include<stdio.h> #include<conio.h> void main() { int a=0,b=1,c=1,e=1,n; printf("enter the number"); scanf("%d",&n); do { printf("%d\n",b); b=a+e; a=e; e=b; c=c+1; }while(n>=c); getch(); }   Output enter the number 4 1 1 2 3

program for printing pyramid

#include<stdio.h> #include<conio.h> void main() {         int i,j,k,n;         clrscr();         printf("enter the number=");         scanf("%d",&n);         for(i=1;i<=n;i++)         {         for(j=i;j<=n-1;j++)         {         printf(" ");         }         for(k=1;k<=i;k++)         {         printf("*");         }         for(k=2;k<=i;k++)         {         printf("*");         }         printf("\n");         }         getch();         }                                                                               Output enter the number=6          *        ***      *****    *******   ********* ***********

Program for checking whether input number is Prime or not

#include<stdio.h> #include<conio.h> void main() { int n,n1,i; printf("\nEnter any positive integer number to check"); scanf("%d",&n); if(n==1 || n==2) printf("\nThe number is Prime"); else { i=2; while(i<=n) { if(n%i==0) break; i++; } if(n==i) printf("\nThe Number is Prime"); else printf("\nThe Number is Not Prime"); } printf("\nPress any key to continue..."); getch(); }   Output Enter any positive integer number to check 4 The Number is Not Prime Press any key to continue... Enter any positive integer number to check 7 The Number is Prime Press any key to continue...