added exercise 3
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
// creating variables
|
||||||
|
int first = 0, second = 0, addition = 0, subtraction = 0, multiplication = 0, modulo = 0;
|
||||||
|
double division = 0;
|
||||||
|
|
||||||
|
// receiving numbers from user
|
||||||
|
printf("Please type in the first integer: ");
|
||||||
|
scanf("%i", &first);
|
||||||
|
printf("Please type in the second integer: ");
|
||||||
|
scanf("%i", &second);
|
||||||
|
|
||||||
|
// checking numbers
|
||||||
|
printf("Your input: %i and %i\nCalculating...\n\n", first, second);
|
||||||
|
|
||||||
|
// calculating
|
||||||
|
addition = first + second;
|
||||||
|
subtraction = first - second;
|
||||||
|
multiplication = first * second;
|
||||||
|
if (second != 0) {
|
||||||
|
division = first / second;
|
||||||
|
} else {
|
||||||
|
printf("\n\nError: Dividing by 0 is not allowed. Output will be 0.\n\n");
|
||||||
|
}
|
||||||
|
modulo = first % second;
|
||||||
|
|
||||||
|
// output of calculation
|
||||||
|
printf("The results are:\n+ = %i\n- = %i\n* = %i\n/ = %f\nmod = %i", addition, subtraction, multiplication, division, modulo);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user