Rojen G Embate
Honorary Poster
- Joined
- Mar 12, 2018
- Posts
- 275
- Reaction
- 217
- Points
- 209
- Age
- 19
C language
An integer variable, total, is initialized to 10 in the code editor. Ask the user to input an integer and check if it is positive, negative, or zero.
if positive: check if it is even or odd. if it is even, add its square to total, otherwise add its cube to total
if negative: ask the user to input another integer as an exponent to this negative number and add the result to total.
if zero: print "Nothing happened."
Lastly, only print the value of total if the inputted integer is positive or negative.
Sample Output 1
Enter an integer: 2
14
Sample Output 2
Enter an integer: 3
37
Sample Output 3
Enter an integer: -2
Enter another integer: 3
2
4. The Final Total
by CodeChum AdminAn integer variable, total, is initialized to 10 in the code editor. Ask the user to input an integer and check if it is positive, negative, or zero.
if positive: check if it is even or odd. if it is even, add its square to total, otherwise add its cube to total
if negative: ask the user to input another integer as an exponent to this negative number and add the result to total.
if zero: print "Nothing happened."
Lastly, only print the value of total if the inputted integer is positive or negative.
Sample Output 1
Enter an integer: 2
14
Sample Output 2
Enter an integer: 3
37
Sample Output 3
Enter an integer: -2
Enter another integer: 3
2