I have to create a program that will read integer numbers from the user, one at a time. It will print these numbers out after reading them. It will continue to read numbers until it receives the number 7 or 11. If the number is both even and a multiple of 5, then it will print the number multiplied by itself. If the number is instead a multiple of 6, but is not a multiple of 5, then print twice the number (instead of the number itself).
given the following inputs, the outputs should be: (these are just examples, the number should be printed out right after receiving the input number
Input Output
3 3
10 100
12 24
15 15
7
I wrote the following code:
But the problem I am having is if the number is instead a multiple of 6, but is not a multiple of 5, then print twice the number (instead of the number itself). If it's better to use while loops can someone please let me know how. I have not learned while loops yet.Code:#include <stdio.h> int main() { int x, y; printf("Enter in a number: \n"); scanf("%d", &x); if (x % 2 == 0) { printf("%d\n", y = x * x); } else { printf("%d\n", y); } return 0; }
Any help is appreciated, but please explain.