You are not logged in.
Pages: 1
Topic closed
Hi there:
I just wrote a tiny program in C to realize the function to get the largest prime within 0 and 100,and the code is here:
#include <stdio.h>
#include <stdbool.h>
int main(void)
{
long num;
long div;
bool numIsPrime,flag;
const long big=100;
for (num=big,flag=true;flag==true&&num>=3;num--)
{
for (div=2,numIsPrime=true;(div*div)<=num;div++)
{
if(num%div==0)
{
numIsPrime=false;
flag=true;
}
}
if (numIsPrime)
printf("%ld is the largest prime within %ld.\n",num,big);
flag=false;
}
return 0;
}
But when I executed it,I got nothing........So did I do anything wrong?I need your help,please.:(
Last edited by YZMSQ (2010-02-09 14:13:04)
This is the way the world ends
Not with a bang but a whimper
-------T·S·Eliot
Offline
This sounds like a homework question, which we generally don't allow on the forums (the point of homework is to figure it out yourself and learn, after all).
I'll give you a hint: your problem is here:
if (numIsPrime)
printf("%ld is the largest prime within %ld.\n",num,big);
flag=false;
Good luck. If you can convince me it's not a homework assignment, I may reopen the thread.
Offline
Pages: 1
Topic closed