By: Emiley J in C Tutorials on 2010年04月16日 [フレーム]
This is a simple calculator written in C. To use this calculator, just type the number, followed by the operand and then by another number. The application will then display the result. After the result is displayed, the program goes into the loop which asks if they want to do another calculation. If y is pressed, another calculation can be carried out.
#include <stdio.h>
int main()
{
double number1 = 1.0;
double number2 = 2.0;
char operation = '+';
char answer = 0;
switch(operation)
{
case '+':
printf("= %lf\n", number1 + number2);
break;
case '-':
printf("= %lf\n", number1 - number2);
break;
case '*':
printf("= %lf\n", number1 * number2);
break;
case '/':
if(number2 == 0)
printf("\n\n\aDivision by zero error!\n");
else
printf("= %lf\n", number1 / number2);
break;
case '%':
if((long)number2 == 0)
printf("\n\n\aDivision by zero error!\n");
else
printf("= %ld\n", (long)number1 % (long)number2);
break;
default:
printf("\n\n\aIllegal operation!\n");
}
}
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Most Viewed Articles (in C )
Passing double value to a function in C
Printing a simple histogram in C
Sum of the elements of an array in C
Simple arithmetic calculations in C
Passing pointer to a function in C
Find square and square root for a given number in C
Using memset(), memcpy(), and memmove() in C
Latest Articles (in C)
Simple arithmetic calculations in C
Find square and square root for a given number in C
Printing a simple histogram in C
Sum of the elements of an array in C
Passing pointer to a function in C
Passing double value to a function in C
Infix to Prefix And Postfix in C
Sum of the elements of an array in C
Printing a simple histogram in C
Find square and square root for a given number in C
Simple arithmetic calculations in C
Passing double value to a function in C
Passing pointer to a function in C
Infix to Prefix And Postfix in C
while, do while and for loops in C
© 2023 Java-samples.com
Tutorial Archive: Data Science React Native Android AJAX ASP.net C C++ C# Cocoa Cloud Computing EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Trends WebServices XML Office 365 Hibernate
Latest Tutorials on: Data Science React Native Android AJAX ASP.net C Cocoa C++ C# EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Cloud Computing WebServices XML Office 365 Hibernate