New course! Every coder should learn Generative AI!
Try a free lesson- 1
in this code why we can not take i==num in for loop?
#include<iostream> using namespace std; int main() { int num; int i;int div = 0; cout << "ent no"<< endl; cin >> num; for (i = 1; i <= num; i++) { if (num % i == 0) { div++; } } if (div == 2) cout << "yes!!!!/n"; else { cout << "noooooooooooooooo/n"; }
2 Answers
0
yes you can, but be carefull of the div value... it increases each time that num%i==0
0
You can use "i == num"
If the user inputs 1, the condition is true and it will run ..but once only.