- #1
Saterial
- 54
- 0
So I'm working on two questions while learning C.
The first question is, I need to create a program that prompts a user "Please enter an integer" and display whether the answer is odd or even. I'm using the logic that you can divide the input by 2, if the answer is a whole number it is even, if it's a decimal it is odd. How can you check whether the input is a decimal or not? Would this solution work for a question that asked for an input of 2 numbers, say "15 5"? Let 15 be a, 5 be b and divide a by b; if answer is whole number then it is a multiple, else it is an odd number?
Second question is, I need to create a program that prompts a user "Please enter a five integers:" for example "5 12 -10 0 1". From there it will display "The max is: 12" and "The min is -10". How can I do this without using an array?
I get the idea behind it, I just can't figure out how to make it check whether the output of the calculation is a float. Additionally, this is an intro to learning C class; my idea for a solution to question 1 was using something like "scanf("%d", a b c d e); and then a long line of code checking if each variable is greater than each other. This obviously didn't seem very efficient to me is there another basic way I can try?
Thanks!
The first question is, I need to create a program that prompts a user "Please enter an integer" and display whether the answer is odd or even. I'm using the logic that you can divide the input by 2, if the answer is a whole number it is even, if it's a decimal it is odd. How can you check whether the input is a decimal or not? Would this solution work for a question that asked for an input of 2 numbers, say "15 5"? Let 15 be a, 5 be b and divide a by b; if answer is whole number then it is a multiple, else it is an odd number?
Second question is, I need to create a program that prompts a user "Please enter a five integers:" for example "5 12 -10 0 1". From there it will display "The max is: 12" and "The min is -10". How can I do this without using an array?
I get the idea behind it, I just can't figure out how to make it check whether the output of the calculation is a float. Additionally, this is an intro to learning C class; my idea for a solution to question 1 was using something like "scanf("%d", a b c d e); and then a long line of code checking if each variable is greater than each other. This obviously didn't seem very efficient to me is there another basic way I can try?
Thanks!