C Program : Arithmetic Operators
int main() { int num1, num2; // Input two numbers printf("Enter the first number: "); scanf("%d", &num1); printf("Enter the second number: "); scanf("%d", &num2); // Addition printf("%d + %d = %d\n", num1, num2, num1 + num2); // Subtraction printf("%d - %d = %d\n", num1, num2, num1 - num2); // Multiplication printf("%d * %d = %d\n", num1, num2, num1 * num2); // Division if (num2 != 0) { printf("%d / %d = %d\n", num1, num2, num1 / num2); } else { printf("Division by zero is not allowed.\n"); } // Modulus (Remainder) if (num2 != 0) { printf("%d %% %d = %d\n", num1, num2, num1 % num2); } else { printf("Modulus operation with zero is not allowed.\n"); } return 0; }
Comments
Post a Comment