make simple calculator using C language | C language prectical | pps solution GTU

GTU PPS Practical - 1

Table of content:

Logic :

Logic of this program is very simple as everyone knows the basic mathematics of addition, multiplication, division and subtraction.

In this program, we have to take two numbers from user and we display the addition, multiplication, division and subtraction of that two numbers.

Let's look at the algorithm.

Algorithm :

  1.  START
  2.  Input two numbers from user and store it in variables num1 and num2.
  3.  Compute addition, multiplication, division and subtraction of num1 and num2.
  4.  Print addition, multiplication, division and subtraction.
  5.  STOP

Code 1

#include <stdio.h>
int main()
{
float num1,num2, addition,multiplication, division, subtraction;
printf("Enter first number:\n");
scanf("%f",&num1);
printf("Enter second number:\n");
scanf("%f",&num2);
addition = num1 + num2 ;
multiplication = num1 * num2 ;
division = num1 / num2 ;
subtraction = num1 - num2 ;
printf("Addition : %.2f + %.2f = %.2f \n", num1,num2, addition);
printf("Multiplication : %.2f * %.2f = %.2f \n", num1,num2, multiplication);
printf("Division : %.2f / %.2f = %.2f \n", num1,num2, division);
printf("Subtraction : %.2f - %.2f = %.2f \n", num1,num2, subtraction);
return 0;
}

Code 2

Here is a second code which has only six floats are define in programme. This code also displays addition, subtraction, multiplication and division in output side. You can see output below.

#include <stdio.h>
int main()
{
float num1,num2,addition,subtraction,multiplication,division;
printf("\n Enter the first number:");
scanf("%f",&num1);
printf("\n Enter the second number:");
scanf("%f",&num2);
addition=num1+num2;
subtraction=num1-num2;
multiplication=num1*num2;
division=num1/num2;
printf("\n The addition of your numbers is %f",addition);
printf("\n The subtraction of your numbers is %f",subtraction);
printf("\n The multiplication of your numbers is %f",multiplication);
printf("\n The division of your numbers is %f", division);
return 0;
}

Code for Turbo C

This code is used in Turbo C because there are some code to hold output on screen and clear last operations. Here is a third code which has only six floats are define in programme. This code displays addition, subtraction, multiplication and division in output side. You can see output below.

#include <stdio.h>
#include <coino.h>
int main()
{
float num1,num2,addition,subtraction,multiplication,division;
clrscr();
printf("\n Enter the first number:");
scanf("%f",&num1);
printf("\n Enter the second number:");
scanf("%f",&num2);
addition=num1+num2;
subtraction=num1-num2;
multiplication=num1*num2;
division=num1/num2;
printf("\n The addition of your numbers is %f",addition);
printf("\n The subtraction of your numbers is %f",subtraction);
printf("\n The multiplication of your numbers is %f",multiplication);
printf("\n The division of your numbers is %f", division);
getch();
return 0;
}

Output :

Here you can see output screen of the code.You can get this type of output if you write above code 1.

c-program-to-perform-addition-subtraction-multiplication-and-division

THANK YOU for reading this post.

Post a Comment

0 Comments