scanf not workin

scanf is not not working. may be header prob..is there a better way to code this...need to find min no of guess required to determine a no. between 1 and 1000 by only usin divide

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<stdio.h>

int main()
{
int t,i,c=0,m,x=1;
printf("enter no of test case\n");
scanf("%d",&t);
do{
printf("enter guess no\n");
scanf("%d",&m);
for (i=1;i<=1000;i=i+x)
{
c++;
if(m%i==0){

x=i;
if(m/i==1){
break;
}

}

}
printf("%d",c);

return 0;
t--;

}while(t!=0);
}
What makes you think that scanf is not working? Add a printf() right after the scanf statements to print the value scanned. You may find that scanf is working fine. In that case, maybe the rest of your algorithm is broken.

Learn how to use the debugger. It can be really valuable to find bugs.
I did use debugger and code is just working fine ...i replaced scanf and put m=6 ...it gives 4....but not taking input from user....i used codeblocks at first...then online debugger dbgr.cc...any help would be appreciated
Line 27: This line will never be reached because of the return statement above it. Therefore, t will never be decremented.

You probably want line 26 after line 29.

Last edited on
Thanx @abstractionanon. But my problem still not solved
The scanf()'s work for me.

What is the program supposed to do? In addition to moving hte return, I suspect that you need move the definitions of c and x inside the do/while loop so they get initialized each time through the loop.
Topic archived. No new replies allowed.