Skip to content

Instantly share code, notes, and snippets.

@encodes1
Created May 10, 2013 12:48
Show Gist options
  • Save encodes1/5554214 to your computer and use it in GitHub Desktop.
Save encodes1/5554214 to your computer and use it in GitHub Desktop.
Week 1 - Challenge 1 - solution 2
#include<stdio.h>
#include<math.h>
int main()
{
int n, i = 3, x, c;
char prime;
printf("Enter the number of prime numbers required\n");
scanf("%d",&c);
printf("Enter the last number\n");
scanf("%d",&n);
printf("\n");
for(;c <=n; c++){
prime = 1;
for(x=2; x< ceil(c/2); x++){
if(c%x == 0){
prime = 0;
break;
}
}
if(c ==2){
prime = 0;
}
if(prime == 1){
printf("%d\n",c);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment