+ 1
Whats wrong with this code?
//program to check prime no. #include<stdio.h> #include<conio.h> int main() { clrscr(); int count=1,i=1,num,d); printf("Enter A no"); while (i>=1 && i<=num) { d=(num/i); i++; if(d==1 || d==num) count=count+1; } if (count==2) printf("a prime no."); else printf("not a prime no."); getch(); return 0; }
12 Respuestas
+ 1
1. use clrscr after variable declaration.
2. variable d is declared d)
3. capture the number input from user.
+ 1
you havent define a value for your num variable. The while loop is ignored. And your d never created.
0
have declared all variables as int and called clrscr function in a fn.(as i can call a fn anytime, anywhere). Its a program to calculate prime.. dont know y its not working
0
count ==2. (the no. itself and one)
0
count will not be 2 for 17 because d will be 1 for i of 9 through 17.
0
as d is defined as int.. it will either take 1 or 2....
so it'll be 1 till 9. i think ?
0
Better test r=num%i; if (r==0) count++;
0
still shows wrong
0
count should initialized to 0 not 1
0
instead of using while try to use for loop and the biggest factor of any number wont be bigger than the half of that value. i'll write code for you give me 10 min posting here.
0
sorry for the delay was busy here is you code
https://code.sololearn.com/cvmG2iMbSFL9
writing this similar code with while also i'll update link later
here is code with while loop
https://code.sololearn.com/ct3I9NhaJ3TK
- 1
once num is defined (say 5), you exit the loop with d = 5/5 = 1 so your test of d==2 will never be true.