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?
4 Réponses
+ 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 ;
+ 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
+ 1
out put of this code please?
0
Danil already answered while I was writing😅