You are on page 1of 5

Here is a simple program to generate prime numbers upto a given specific number #include<stdio.h> #include<conio.

h> void main() { int i,j,n; printf(" Enter the number upto which we have to find the prime number: "); scanf("%d",&n); printf("\n"); for(i=2;i<=n;i++) { for(j=2;j<=i-1;j++) if(i%j==0) break; //Number is divisble by some other number. So break out if(i==j) printf("\t%d",i); //Number was divisible by itself (that is, i was same as j) }//Continue loop upto nth number getch(); }

/* Write a C program to generate all the prime numbers between 1 and n, where n is a value supplied by the user. */ #include <stdio.h> void main() { int no,counter,counter1,check; clrscr(); printf(<PRIME NO. SERIES>); printf(\n\n\n\t\t\tINPUT THE VALUE OF N: ); scanf(%d,&no); printf(\n\nTHE PRIME NO. SERIES B/W 1 TO %d : \n\n,no); for(counter = 1; counter <= no; counter++) { check = 0; //THIS LOOP WILL CHECK A NO TO BE PRIME NO. OR NOT. for(counter1 = counter-1; counter1 > 1 ; counter1) if(counter%counter1 == 0) { check++; // INCREMENT CHECK IF NO. IS NOT A PRIME NO. break; }

if(check == 0) printf(%d\t,counter); } getch(); }

Answer: Improve Here is a simple program to generate prime numbers upto a given specific number /*Prime No. from 1 to 50*/ /*By-Himanshu Rathee*/ #include<stdio.h> #include<conio.h> void main() { int i,j,n; clrscr(); printf(" Enter the number upto which we have to find the prime number: "); scanf("%d",&n); printf("\n"); for(i=2;i<=n;i++) { for(j=2;j<=i-1;j++) if(i%j==0) break; /*Number is divisble by some other number. So break out*/ if(i==j) printf("\t%d",i); /*Number was divisible by itself (that is, i was same as j)*/ } /*Continue loop upto nth number*/ getch(); } Read more: http://wiki.answers.com/Q/C_program_to_print_how_many_prime_numbers_are_there_from_1_ to_50#ixzz1VkFztFK6

Answer:

Improve Here is a simple program to generate prime numbers upto a given specific number /*Prime No. from 1 to 50*/ /*By-Himanshu Rathee*/ #include<stdio.h> #include<conio.h> void main() { int i,j,n; clrscr(); printf(" Enter the number upto which we have to find the prime number: "); scanf("%d",&n); printf("\n"); for(i=2;i<=n;i++) { for(j=2;j<=i-1;j++) if(i%j==0) break; /*Number is divisble by some other number. So break out*/ if(i==j) printf("\t%d",i); /*Number was divisible by itself (that is, i was same as j)*/ } /*Continue loop upto nth number*/ getch(); } Read more: http://wiki.answers.com/Q/C_program_to_print_how_many_prime_numbers_are_there_from_1_ to_50#ixzz1VkGuVvHf

Factorial program in c
Factorial program in c: c code to find and print factorial of a number, three methods are given, first one uses a for loop, second uses a function to find factorial and third using recursion. Factorial is represented using !, so five factorial will be written as 5!, n factorial as n!. Also n! = n*(n-1)*(n-2)*(n-3)...3.2.1 and zero factorial is defined as one i.e. 0!=1.

Factorial program in c using for loop


: Here we find factorial using for loop.
#include<stdio.h>

#include<conio.h> main() { int c, n, fact = 1; printf("Enter a number to calculate it's factorial\n"); scanf("%d",&n); for( c = 1 ; c <= n ; c++ ) fact = fact*c; printf("Factorial of %d = %d\n",n,fact); getch(); return 0; }

1. #include<stdio.h> 2. #include<conio.h> 3. int main(void) 4. { 5. int no,i,fact=1; 6. clrscr(); 7. printf("\nEnter the number: "); 8. scanf("%d",&no); 9. //loop to multiply the number from 1 to no.(input) 10. for(i=1;i<=no;i++) 11. { 12. fact=fact * i; 13. } 14. printf("\nThe factorial of number %d is %d\n",no,fact); 15. return 1; 16. } #include<conio.h> #include<iostream.h> void main() { int x=0; int Fact=1; cout<<"Enter number to calculate Factorial:";//printf cin>>x;//scanf

for(int c=1;c<=x;c++) { Fact=Fact * c; } cout<<"Factorial of number <<x << is: "<<Fact; getch(); } 3

You might also like