Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maybe it is taking too long ... ? #23

Open
narutocanada opened this issue Dec 23, 2017 · 0 comments
Open

maybe it is taking too long ... ? #23

narutocanada opened this issue Dec 23, 2017 · 0 comments

Comments

@narutocanada
Copy link

hi
the first example I tried never print out anything. maybe movcc does not work with argc,argv,atoi etc, so I got rid of them all, and set the number of primes to a constant 10, and use only one external function "printf". still, it never print out anything. maybe you should give it a try. what is the speed normally like?
main()
{
int n, i = 3, count, c;

//n=10000;
//printf("Enter the number of prime numbers required\n");
//scanf("%d",&n);

n=10;

if ( n >= 1 )
{
// printf("First %d prime numbers are :\n",n);
printf("2\n");
}

for ( count = 2 ; count <= n ; )
{
for ( c = 2 ; c <= i - 1 ; c++ )
{
if ( i%c == 0 )
break;
}
if ( c == i )
{
printf("%d\n",i);
count++;
}
i++;
}

}

// original version
#include <stdio.h>

int main(int argc,char** argv)
{
int n, i = 3, count, c;

//n=10000;
//printf("Enter the number of prime numbers required\n");
//scanf("%d",&n);

if (argc<2) {printf("%s number.of.primes\n",argv[0]);return 1;}
n=atoi(argv[1]);

if ( n >= 1 )
{
// printf("First %d prime numbers are :\n",n);
printf("2\n");
}

for ( count = 2 ; count <= n ; )
{
for ( c = 2 ; c <= i - 1 ; c++ )
{
if ( i%c == 0 )
break;
}
if ( c == i )
{
printf("%d\n",i);
count++;
}
i++;
}

return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant