in this code why we can not take i==num in for loop? | Sololearn: Learn to code for FREE!
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"; }

16th Nov 2020, 7:19 PM
Muhammad Ali Zulfiqar
Muhammad Ali Zulfiqar - avatar
2 Answers
0
yes you can, but be carefull of the div value... it increases each time that num%i==0
16th Nov 2020, 9:05 PM
KAWOTTE
KAWOTTE - avatar
0
You can use "i == num" If the user inputs 1, the condition is true and it will run ..but once only.
16th Nov 2020, 9:19 PM
rodwynnejones
rodwynnejones - avatar