initial import
[staff/goc4/2018bti7061.git] / c-2-controlStructures / examples / controlStatements / ifthenelse.c
1 #include <stdio.h>
2 #define PI 3.14159
3
4
5 main(){
6
7 puts("Examples for If / Then /Else");
8
9 puts("-------------------------");
10 puts("Example 1");
11
12 char status = 'S';
13 double pay = 7000, tax;
14
15 if (status == 'S')
16 tax = 0.20 * pay;
17 else
18 tax = 0.14 * pay;
19
20 printf("Pay=%lf and tax=%lf",pay,tax);
21
22
23
24
25 puts("-------------------------");
26 puts("Example 2");
27 char circle;
28 double radius, area,length, width;
29
30 circle = 1;
31
32 if(circle){
33 scanf("%lf",&radius);
34 area = PI * radius * radius;
35 printf("Area of the circle = %lf \n",area);
36 }
37 else {
38 scanf("%lf %lf", &length, &width);
39 area = length * width;
40 printf("Area of rectangle = %lf",area);
41 }
42
43
44
45 }