Recap Challenge
Part of the Fundamentals section of Coddy's C journey — lesson 24 of 63.
Challenge
EasyLet's create a program that uses various operators we've learned:
- Declare and initialize two integer variables:
num1to 25 andnum2to 7. - Calculate the following values:
- The sum of
num1andnum2 - The difference between
num1andnum2 - The product of
num1andnum2 - The quotient when dividing
num1bynum2 - The remainder when dividing
num1bynum2
- The sum of
Print the results in the format:
num1 = 25, num2 = 7 Sum: 32 Difference: 18 Product: 175 Quotient: 3 Remainder: 4- Check if
num1is greater thannum2AND the remainder when dividingnum1by 2 is 1 (i.e., ifnum1is odd). Store the result in a variable calledresult1. - Check if
num2is less than 10 ORnum1is even. Store the result in a variable calledresult2. Print the logical operation results in the format:
result1: 1 result2: 1
Try it yourself
#include <stdio.h>
int main() {
// Declare and initialize variables
// Calculate arithmetic operations
// Print arithmetic results
// Calculate logical operations
// Print logical operation results
return 0;
}All lessons in Fundamentals
3Operators
Arithmetic OperatorsModulo OperatorIncrement/DecrementAssignment OperatorsRelational OperatorsLogical Operators Part 1Logical Operators Part 2Logical Operators Part 3Recap Challenge