View difference between Paste ID: c4ruGkp0 and TBbN3Kfn
SHOW: | | - or go back to the newest paste.
1
/* C programme to creat simple calculator */
2
#include <stdio.h>
3
float add(float a,float b);
4
float substract(float a,float b);
5
float multiply(float a,float b);
6
float divide(float a,float b);
7
int main(void)
8
{
9
     float num1,num2;
10
     float w,result=6;
11
     char ch,c;
12
     printf("Enters two numbers to add,substract,multiply or divide\n");
13
     scanf("%f %f",&num1,&num2);
14
     printf("enter a to add, s to substract ,m to multiply,d to divide\n");
15
     scanf("%c %c",&c,&ch);
16
     if(ch=='a'||ch=='A')
17
     {
18
         result=add(num1,num2);
19
         printf("%f\n",result);
20
     }
21
     else if(ch=='s'||ch=='S')
22
     {
23
         result=substract(num1,num2);
24
         printf("%f\n",result);
25
     }
26
     else if(ch=='m'||ch=='M')
27
     {
28
         result=multiply(num1,num2);
29
         printf("%f\n",result);
30
     }
31
     else if(ch=='d'||ch=='D')
32
     {
33
         result=divide(num1,num2);
34
         printf("%f\n",divide(num1,num2));
35
     }
36
     else
37
     {
38
         printf("please input the correct character\n");
39
     }
40
     return 0;
41
}
42
float add(float a,float b)
43
{
44
     float add;
45
     add=a+b;
46
     return add;
47
}
48
float substract(float a,float b)
49
{
50
     float substract;
51
     substract=a-b;
52
     return substract;
53
}
54
float multiply(float a,float b)
55
{
56
     float multiply;
57
     multiply=a*b;
58
     return multiply;
59
}
60
float divide(float a,float b)
61
{
62
     float divide;
63
     divide=(float)a/(float)b;
64
     return divide;
65
}