0

How to write a c program that will print all even numbers from 2 to x, user must input the max.value using for loop?

9th Jan 2018, 12:03 PM
Mae Ann
Mae Ann - avatar
4 odpowiedzi
+ 1
very simple example: long long int x; cout << "Input max value: "; cin >> x; cout << "All even num: \n" ; for(long long int i = 2; i <= x; i+=2) cout << i <<endl ;
9th Jan 2018, 12:21 PM
Данил Кудрицкий
Данил Кудрицкий - avatar
+ 1
This would be for java but I guess you will understand and will be able to do it for c easily. 1.take user input and store it in a variable named input or something. 2.for loop would like this: for(int i=0; i<input; i+=2;){ write i to the console. } 3. For example, if I enter 10 as an input, it will display all even numbers untill it reaches 10(number that user has entered). I hope it helps
9th Jan 2018, 12:27 PM
Sad
Sad - avatar
+ 1
out put of this code please?
10th Jan 2018, 1:07 AM
Mae Ann
Mae Ann - avatar
0
Danil already answered while I was writing😅
9th Jan 2018, 12:30 PM
Sad
Sad - avatar