DEV Community

Its Aomi
Its Aomi

Posted on

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 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;

}
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (0)