0% found this document useful (0 votes)
6 views2 pages

Simple C Program for Basic Arithmetic

The document presents a simple C program that demonstrates basic input/output, arithmetic operations, and error handling for division by zero. It prompts the user to enter two integers and displays the results of addition, subtraction, multiplication, and conditional division and modulo operations. The author offers to create a more compact version that includes relational and logical operators.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Simple C Program for Basic Arithmetic

The document presents a simple C program that demonstrates basic input/output, arithmetic operations, and error handling for division by zero. It prompts the user to enter two integers and displays the results of addition, subtraction, multiplication, and conditional division and modulo operations. The author offers to create a more compact version that includes relational and logical operators.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Sure!

Here's a smaller, simpler C program that still combines basic I/O, variables, and arithmetic
operators:

#include <stdio.h>

int main() {

int a, b;

// Welcome message

printf("Simple C Program Demo\n\n");

// Input two integers

printf("Enter first integer: ");

scanf("%d", &a);

printf("Enter second integer: ");

scanf("%d", &b);

// Display arithmetic operations

printf("\nResults:\n");

printf("%d + %d = %d\n", a, b, a + b);

printf("%d - %d = %d\n", a, b, a - b);

printf("%d * %d = %d\n", a, b, a * b);

if (b != 0) {

printf("%d / %d = %.2f\n", a, b, (float)a / b);

printf("%d %% %d = %d\n", a, b, a % b); // modulo operator


} else {

printf("Division and modulo by zero is not allowed.\n");

return 0;

✅ This small program:

Takes two integer inputs

Performs all basic arithmetic operations

Handles division by zero safely

Uses printf formatting for clarity

---

If you want, I can make an even smaller version that also shows relational and logical operators so it
becomes a full “operators demo” in under 30 lines. Do you want me to do that?

You might also like