Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 7

PROGRAM TO PRINT PRIME NUMBERS FROM 1 TO N:#include<stdio.h> #include<conio.

h> void main() { int i,j,n; clrscr(); x: printf("Enter the no: "); scanf("%d",&n); if(n<=0) goto x; printf("\n"); for(i=1;i<=n;i++) { for(j=2;j<=i-1;j++) { if(i%j==0) break; } if(j==i) printf("%d ",j); } getch(); }

PROGRAM TO FIND WHETHER A NUMBER IS PRIME OR NOT:#include<conio.h> #include<stdio.h>

void main() { int i=2; int count=0; int n; printf("enter a no"); scanf("%d",&n); for(i=2;i<n;i++) { if(n%i==0) count++; } printf("count= %d",count); if(count<1) printf("prime number"); else printf("not prime"); getch(); }

PROGRAM TO FIND WHETHER A NUMBER IS PALINDROME OR NOT:


#include<conio.h> #include<stdio.h> void main() { int m,n,a,s=0; clrscr(); printf("Enter the value for n"); scanf("%d",&n); m=n;

while(n>0) { a=n%10; s=s*10+a; n=n/10; } printf("%d",s);

if(s==m) { printf("no is palindrome"); } else { printf("no is not palindrome"); } getch(); }

PROGRAM TO GENERATE SERIES:32 64


#include<stdio.h> #include<conio.h> void main() { int i,j=1; clrscr(); printf("%d ",j);

16

for(i=0;i<=5;i++) {

j=j+j; printf("%d ",j); } getch(); }

PROGRAM TO COUNT THE NO OF VOWELS IN A STRING:#include<stdio.h> #include<conio.h> void main() { char str[50]; int vowels = 0, i = 0; clrscr(); printf("ENTER A STRING"); scanf("%s",str); while(str[i] != 0) { if(str[i]=='A' || str[i]=='a' || str[i]=='E' || str[i]=='e' || str[i]=='I' || str[i]=='i' || str[i]=='O' || str[i]=='o' || str[i]=='U' || str[i]=='u') { vowels++; str[i]='*'; } i++; } printf("THE TOTAL NUMBER OF VOWELS IS %d", vowels); printf("\n%s",str); getch(); }

Program to find Fibonacci series upto n terms:


#include<stdio.h> #include<conio.h> main() { int n,i,c,a=0,b=1; clrscr(); printf("Enter Fibonacci series of nth term : "); scanf("%d",&n); printf("%d %d ",a,b); for(i=0;i<=(n-3);i++) { c=a+b; a=b; b=c; printf("%d ",c); } getch(); }

PROGRAM TO FIND THE REVERSE OF A NUMBER:#include<conio.h> #include<stdio.h> void main() { int n,a,s=0; clrscr(); printf("Enter the value for n"); scanf("%d",&n); while(n>0)

{ a=n%10; s=s*10+a; n=n/10; } printf("%d",s); getch(); }

PROGRAM TO FIND THE REVERSE OF A STRING:#include<conio.h> #include<stdio.h> void main() { int l,i,j; char str[10],temp[10]; clrscr(); printf("\n enter any string to reverse =>"); scanf("%s",&str); for (l=0;str[l];++l); {printf("\nThis is the length of the string =>%d\n",l); } j=l; for (i=0;j>=0;i++,j--) { temp[i]=str[j]; } printf("\n this is the reversed string =>");

for (i=0;i<=l;i++) {

printf("%c",temp[i]); } getch(); }

You might also like