How to present only even and odd values with three variables in C?

Asked

Viewed 193 times

2

My variables are :

    int codigo; --> Sendo esta variável para o switch
    int numero1,numero2,numero3;

User will enter with three variables :

         printf("Digite o primeiro numero inteiro: ");
         scanf("%d", &numero1);
         printf("Digite o segundo numero inteiro: ");
         scanf("%d",&numero2);
         printf("Digite o terceiro numero inteiro: ");
         scanf ("%d", &numero3);

After this, I need to make the program check on each variable, what are its even and odd numbers.

For example, the user in the first variable called numero1 type the número 20, with this, the program will have to travel until it reaches the número 20 and show which numbers were even and odd.

Then the user type in the variable numero2, the número 19, and again will make the previous check.

Finally, the user type in the variable numero3, the número 30 and again the same check.

I’m using a switch because the user will have other options too. But how can I do it then ? Using a for along with a do-while until you can pick up all the numbers and check which ones are even and odd ?

1 answer

2


I don’t know much about C, and I don’t know if I understand the question correctly (I can’t comment yet so I couldn’t ask, sorry )

I made this code to show the numbers stop, I would normally use only 1 variable for this, but you said you needed 3 so I decided to make a function to show her pairs.

if you want the program to list and separate the pairs from the odd ones, let me know

#include<stdio.h>

int main (void){
    int numero1;
    int numero2;
    int numero3;
    int count;

    void Par(int valor){
        for(count=1 ; count <= valor ; count++){
            if (count % 2 == 0){
                printf("%d \n", count);
            }
        }
    }

    printf("Digite o primeiro numero inteiro: ");
    scanf("%d", &numero1);
    Par(numero1);
    printf("Digite o segundo numero inteiro: ");
    scanf("%d",&numero2);
    Par(numero2);
    printf("Digite o terceiro numero inteiro: ");
    scanf ("%d",&numero3);
    Par(numero3);

}
  • Thanks for the code, it worked, I only modified your answer because the method was inside the main, causing that error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.