Professional Documents
Culture Documents
Program To Print Prime Numbers From 1 To N
Program To Print Prime Numbers From 1 To N
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(); }
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(); }
16
for(i=0;i<=5;i++) {
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 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)
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(); }