Problem 01

author
By Supreme2023-02-14
Problem Statement :
Write a program to that performs as calculator ( addition, multiplication, division, subtraction).
Code:

#include <stdio.h>

int main()
{

// 1. Write a program to that performs as calculator ( addition, multiplication,
// division,
// subtraction).

printf("\t\tCalculator");
printf("\n=====================================================");

float a, b;

printf("\n\nEnter A : ");
scanf("%f", &a);

printf("\nEnter B : ");
scanf("%f", &b);

printf("\n_____________________________________________________");

printf("\n\nAddition of A (%.2f) And B (%.2f) is : %.2f", a, b, a + b);

printf("\n\nSubtraction of A (%.2f) And B (%.2f) is : %.2f", a, b, a - b);

printf("\n\nMultiplication of A (%.2f) And B (%.2f) is : %.2f", a, b, a * b);

printf("\n\nDivision of A (%.2f) And B (%.2f) is : %.2f", a, b, a / b);

printf("\n_____________________________________________________\n\n");

return 0;
}

Description :
  • This program is a simple calculator that performs addition, subtraction, multiplication, and division of two floating-point numbers A and B.
  • The program starts by including the standard input-output library "stdio.h" and declaring the main function.
  • It then prints the title "Calculator" and a line of equal signs for decoration.
  • Two float variables, a and b, are declared to store the user inputs for the calculation.
  • The program prompts the user to enter the value of A and B through standard input using scanf.
  • The program then prints the result of addition, subtraction, multiplication, and division of A and B using printf.
  • The program ends by returning 0 to indicate that it has executed successfully.
Output Image:
Output-image

© Copyright 2022. All right reserved, GTU Coder.