Making a Basic C Calculator

Here’s how you can make a Basic C Calculator.

Get more C Calculator Examples here.

Ill first give you the code then ill explain how it works.

#include <stdio.h>
#include <stdlib.h>

int main()

{
double number1, number2; // Creates …


This content originally appeared on DEV Community and was authored by Its Aomi

Here's how you can make a Basic C Calculator.

Get more C Calculator Examples here.

Ill first give you the code then ill explain how it works.

#include <stdio.h>
#include <stdlib.h>

int main()

{
  double number1, number2; // Creates two variables

  printf("Enter First Number: "); // Takes First Number
  scanf("%lf", &number1); // Stores first number in number1

  printf("Enter Second Number: "); // Takes Second Number
  scanf("%lf", &number2); // Stores second number in number2

  printf("The Addition of the two is: %f", number1 + number2); // Prints out the addition of the two numbers
  return 0;

}

Okay so here's how the program works.

The program first makes two variables number1 and number2. Where we will be able to store our first and second number.

The program then asks the user for an input of the first number and second second number which are then stored in variable number1 and number2.

After the program got both the first number and second number it will add them together using operator '+' and print out the answer.

The program is using double instead of int so that it can calculate decimal numbers also.

You can change the '+' operator to anything else also like -, x etc.


This content originally appeared on DEV Community and was authored by Its Aomi


Print Share Comment Cite Upload Translate Updates
APA

Its Aomi | Sciencx (2022-07-02T03:53:56+00:00) Making a Basic C Calculator. Retrieved from https://www.scien.cx/2022/07/02/making-a-basic-c-calculator/

MLA
" » Making a Basic C Calculator." Its Aomi | Sciencx - Saturday July 2, 2022, https://www.scien.cx/2022/07/02/making-a-basic-c-calculator/
HARVARD
Its Aomi | Sciencx Saturday July 2, 2022 » Making a Basic C Calculator., viewed ,<https://www.scien.cx/2022/07/02/making-a-basic-c-calculator/>
VANCOUVER
Its Aomi | Sciencx - » Making a Basic C Calculator. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/07/02/making-a-basic-c-calculator/
CHICAGO
" » Making a Basic C Calculator." Its Aomi | Sciencx - Accessed . https://www.scien.cx/2022/07/02/making-a-basic-c-calculator/
IEEE
" » Making a Basic C Calculator." Its Aomi | Sciencx [Online]. Available: https://www.scien.cx/2022/07/02/making-a-basic-c-calculator/. [Accessed: ]
rf:citation
» Making a Basic C Calculator | Its Aomi | Sciencx | https://www.scien.cx/2022/07/02/making-a-basic-c-calculator/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.