Simple calculator in C

This program creates a simple arithmetic calculator using if-else statements. It takes two numbers and an operator from the user as input and then performs the chosen operation on those numbers.

Program: Arithmetic calculator in C

In the 8th line of the program, unlike other operators, the ‘%’ operator is passed using character conversion. That is because in a string in C, % expects the flag character, field width, precision, length modifier, or the conversion specifier. So this is also how to print % in C.

Output: Calculator using if-else in C

Enter two numbers: 35 71
Enter an operator (+, -, *, /, %): +

The sum is: 106

Calculator using switch-case statements in C is here.

Share your code in the comments to help others.

Share this code on twitter.

Follow us on twitter.

About ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ

Linux and Python enthusiast, in love with open source since 2014, Writer at programming-articles.com, India.

View all posts by ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ →

Leave a Reply

Your email address will not be published. Required fields are marked *