visit :- allinpython.com for more practicals
C program to make a basic
calculator, before we write code for making a basic calculator you should remember
basic work of calculator is adding a two number, substrate a two number,
multiplication or division of two number. this is very basic work of calculator.
So keeping this thing in mind we should write a program.it is very easy to make a basic calculator using
"c language" ,so we know all basic keyword's of "c" like int,float,if etc (their are total 32 keyword but am
not mention all those) only one keyword and two variable we are use to make calculator
this is very beginner friendly so we are start to write a code.
one think also am share with you friends if you
don't have good code editer or compiler then you should also visit a onlinegdb.com their you can write
program very easily, so you can also go their to write code of "c
language".
Code for making basic calculator using C.
SOURCE CODE:
#include <stdio.h>int main()\// this program only give ans of integer value{ int a,b; printf("enter the value of a="); scanf("%d",&a); printf("the the value of b="); scanf("%d",&b); printf("sum of %d+%d=%d\n",a,b,a+b); printf("substraction of %d-%d=%d\n",a,b,a-b); printf("multiplication of %d*%d=%d\n",a,b,a*b); printf("division of %d/%d=%.3f\n",a,b,(float) a/b);
return 0;}OUTPUT:
enter the value of a=7
the the value of b=2
sum of 7+2=9
substraction of 7-2=5
multiplication of 7*2=14
division of 7/2=3.500
above program make by using int function, int stand for integer.
code for making calculator using float in C
SOURCE CODE:
#include <stdio.h>int main()\// this program only give ans of floating value{ float a,b; printf("enter the value of a="); scanf("%f",&a); printf("the the value of b="); scanf("%f",&b); printf("sum of %.3f+%.3f=%.3f\n",a,b,a+b); printf("substraction of %.3f-%.3f=%.3f\n",a,b,a-b); printf("multiplication of %.3f*%.3f=%.3f\n",a,b,a*b); printf("division of %.3f/%.3f=%.3f\n",a,b,a/b);
return 0;} OUTPUT:
enter the value of a=3.5
the the value of b=7.2
sum of 3.500+7.200=10.700
substraction of 3.500-7.200=-3.700
multiplication of 3.500*7.200=25.200
division of 3.500/7.200=0.486
above program make by using float function,float stand for real number.
0 Comments