Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 error in program
Index -> Programming, C -> C Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
stauroula89




PostPosted: Sun Nov 07, 2010 6:34 pm   Post subject: error in program

/*File:carmichael.c*/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAXINUM 1000000

int main()
{
int o,i,p,k,flag,v,s,j,n,m;
for (n=561; n<=MAXINUM; n+=2)
m=n;
o=0;
i=3;
p=0;
k=0;
flag=1;
v=0;
s=1;
j=3;
while ((j<=sqrt(sqrt(n))) && (s=1)){
if (n%j==0)
s=0;
else
j+=2;
}
if (s==0) {
do {
while ((i<=sqrt(m)) && (m!=1)){
if ((m%i==0) && ((n-1)%(i-1)==0)) {
m=m/i;
k++;
if ((flag==1) && (p==1)) {
printf("%3d x ",i);
}
else
i+=2;
}
}
if ((m!=1) && ((n-1)%(m-1)==0) && (k>1)) {
o=m;
p=1;
m=n;
i=3;
if (v==0) {
printf("%3d is a Carmichael number (=",n);
}
else
flag=0;
}
v=v+1;
if ((v==2) && (p==1)) {
printf("%3d )",o);
flag=0;
}
}while (flag=0);
}
o=m;
v=0;
k=0;
return 0;
}
it's not runnung and i can't find out why!!please help me!!!!
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Sun Nov 07, 2010 11:42 pm   Post subject: RE:error in program

First, format your post using BBCode. At the very least, use [ code ] CODE GOES HERE [ / code ] without the spaces between the [ ] so we can see your indenting.

Second, you need to describe why it doesn't work. Does it compile? Does it run? Does it produce the expected output? Describe exactly what you're doing, what you expect it to do in response, and what it actually does in response.
SmokeMonster




PostPosted: Sun Nov 14, 2010 8:02 am   Post subject: Re: error in program

You didn't give us any information so we can't really help you too much but just looking at the code, you are going in an infinate loop at your do while loop-
code:

do
{
    some stuff.....
}while(flag = 0);


This is what you are doing in your code and it's gonna send you into an infinate loop, = is an assingment operator, the value of the flag is being set to 0 each time you are trying to test the condition. Use the == symbol- while(flag == 0).
Display posts from previous:   
   Index -> Programming, C -> C Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: