First, we declare two integer variables num1 and num2 to store the two numbers to be operated upon.
Then, we declare a float variable result to store the result of the arithmetic operation.
Next, we declare a character variable operator to store the arithmetic operator to be used.
We then use the printf function to prompt the user to enter two numbers and an operator.
The scanf function is used to read the input values for the two numbers and the operator.
Next, we use a switch statement to perform the arithmetic operation based on the value of the operator variable.
In each case of the switch statement, we perform the respective arithmetic operation and print the result using the printf function.
If the value of the operator variable is not one of the four arithmetic operators (+, -, *, /), the default case is executed and an error message is displayed.
Finally, the return statement is used to return a value of 0 to indicate that the program has run successfully.
Arithmetic operations such as addition, subtraction, multiplication, and division C program
#include <stdio.h>
int main()
{
int num1, num2;
float result;
char operator;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
printf("Enter an operator (+, -, *, /): ");
scanf(" %c", &operator);
switch(operator)
{
case '+':
result = num1 + num2;
printf("%.2f\n", result);
break;
case '-':
result = num1 - num2;
printf("%.2f\n", result);
break;
case '*':
result = num1 * num2;
printf("%.2f\n", result);
break;
case '/':
result = (float) num1 / num2;
printf("%.2f\n", result);
break;
default:
printf("Invalid operator\n");
break;
}
return 0;
}
Digital Marketing Consultants and Social Media Marketing Expert with over 3 years of rich experience in various Branding, Promotions, business directories, On pages and off page optimization, Link building Advertising, Research, paid advertisement, content writing and marketing
[…] Finally, don't forget to enjoy your day! The more relaxed and natural you look in your photos, the more they will capture the happy memories of your wedding day. written by the owner of study from here he wrote amazing article on addition subtraction multiplication division program in c […]
[…] Once your wedding photos are ready, be sure to take the time to review them with your photographer. This is the perfect opportunity to discuss any concerns you have and to make sure that you are happy with the final results. By taking the time to review the photos, you can be sure that you will love your wedding photos for years to come. written by the owner of study from here he wrote amazing article on addition subtraction multiplication division program in c […]
[…] supports multi-threading, which allows multiple threads of execution to run concurrently within a single program. This feature helps to improve the performance and responsiveness of Java […]
[…] problem, we will use an array to store the marks for each student. We will also utilize loops and arithmetic operations to calculate the required […]
[…] Sensible Functions and Actual-World Impression:Addition, subtraction, multiplication, and division in C aren’t simply theoretical ideas; they’ve sensible functions and real-world affect. These operations are on the coronary heart of quite a few software program functions, algorithms, simulations, and mathematical fashions that clear up actual issues and enhance lives. Figuring out that one’s work has tangible results and contributes to the betterment of society can present a deep sense of objective and happiness addition subtraction multiplication division program in c. […]
[…] One other widespread false impression is assuming that division by zero will at all times end in an error or exception. In C, dividing a non-zero quantity by zero results in undefined conduct. The consequence can range relying on the compiler or system. It’s important to validate enter and implement applicable error dealing with to forestall division by zero eventualities addition subtraction multiplication division program in c. […]
[…] Native artist Sherry Diaz will host a Watercolor Portray Class on Aug. 14 from 10 a.m. to midday. Discover the basic portray type with an skilled skilled. Registration required as area is restricted. Price is $35 for members and $44 for non-members. All provides included with the fee c++ addition subtraction multiplication division with error. […]
[…] Finally, don't forget to enjoy your day! The more relaxed and natural you look in your photos, the more they will capture the happy memories of your wedding day. written by the owner of study from here he wrote amazing article on addition subtraction multiplication division program in c […]
[…] Once your wedding photos are ready, be sure to take the time to review them with your photographer. This is the perfect opportunity to discuss any concerns you have and to make sure that you are happy with the final results. By taking the time to review the photos, you can be sure that you will love your wedding photos for years to come. written by the owner of study from here he wrote amazing article on addition subtraction multiplication division program in c […]
[…] Example:- c program addition subtraction multiplication division […]
[…] supports multi-threading, which allows multiple threads of execution to run concurrently within a single program. This feature helps to improve the performance and responsiveness of Java […]
[…] problem, we will use an array to store the marks for each student. We will also utilize loops and arithmetic operations to calculate the required […]
[…] Sensible Functions and Actual-World Impression:Addition, subtraction, multiplication, and division in C aren’t simply theoretical ideas; they’ve sensible functions and real-world affect. These operations are on the coronary heart of quite a few software program functions, algorithms, simulations, and mathematical fashions that clear up actual issues and enhance lives. Figuring out that one’s work has tangible results and contributes to the betterment of society can present a deep sense of objective and happiness addition subtraction multiplication division program in c. […]
[…] One other widespread false impression is assuming that division by zero will at all times end in an error or exception. In C, dividing a non-zero quantity by zero results in undefined conduct. The consequence can range relying on the compiler or system. It’s important to validate enter and implement applicable error dealing with to forestall division by zero eventualities addition subtraction multiplication division program in c. […]
[…] Native artist Sherry Diaz will host a Watercolor Portray Class on Aug. 14 from 10 a.m. to midday. Discover the basic portray type with an skilled skilled. Registration required as area is restricted. Price is $35 for members and $44 for non-members. All provides included with the fee c++ addition subtraction multiplication division with error. […]