0
Guys, I’m having trouble putting this together using the for, I know how to make a program that displays even or odd numbers up to the number typed but how do I make it so it can display how many numbers the user reports in num
?
#include <stdio.h>
int main() {
int op, num, x;
printf("1.pares\n2.Impares\n");
scanf("%d", &op);
printf("Digite o numero de vezes que voce quer imprimir\n");
scanf("%d", &num);
if (op==1) { for (x=2; num>=x; x=x+2) {
printf("%d\n", x); }
}else if (op==2) {
for (x=1; num>=x; x=x+2) {
printf("%d\n", x);
}
}
}
The idea is for the user to choose between odd or even and then to choose how many numbers will be displayed (e.g.: display 5 even numbers, display 3 odd numbers)
Put at least what you tried to do.
– Roberto de Campos
I couldn’t understand the logic, that’s the problem
– Rafael Lucca Magalhães
I’m not sure I understand your problem. It is to make a program that reads from the user whether he wants even or odd, how many impressions and do exactly what with these numbers?
– Victor Stafusa
I also did not understand because the concept is a bit complicated, see that in the example I put it types the even or odd numbers up to the number that was typed. But in case I wanted something like for example: I choose pairs and type 5 and el will type 2 4 6 8 10
– Rafael Lucca Magalhães
So the idea is to choose between even or odd and choose how many numbers will be displayed (e.g.: display 5 even numbers, display 3 odd numbers)
– Cleber Griff