I need to write c program which would count total numbers of prime between 0 & input value. I cannot use scanf so I must write main function. using command line argument..
Please Please Help Me
Printable View
I need to write c program which would count total numbers of prime between 0 & input value. I cannot use scanf so I must write main function. using command line argument..
Please Please Help Me
if you cannot help
me
this is what I wrote so far
this is the code I wrote
but the output is wrong
this one only suppose to post the prime number.
Code:
#include <stdio.h>
main( int argc, char *argv[] ) {
int n=0, i, found_a_factor;
for (n=2; n<=argc; n++) {
found_a_factor = 0;
for (i=2; i <= n-1; i++)
if (n % i == 0) found_a_factor = 1;
if (found_a_factor == 0)
printf("F(%s) = %s\n",argv[1]);
//printf ("%d\n", n);
}
return 0;
}
Your for loop should not be going up to argc, that is the count of how many arguments were provided, but you want the value of one of the arguments.
You're also missing one of the arguments to printf (for the given format string). You need to combine bits of he comented out printf line with the one above it.