-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path(04.11.23) Lab 2
66 lines (43 loc) · 1.72 KB
/
(04.11.23) Lab 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<stdio.h>
int main(){
//Program to experiment with typecasting
//declaring all variables together
int itotal_mark, ino_of_subjects, iaverage ;
double dtotal_mark, dno_of_subjects, daverage;
//int, int and int
printf("\n\nThis is for data type: int, int & int\n");
//getting input
printf("Please enter the totalmarks:\n");
scanf("%d", &itotal_mark);
printf("Please enter the number of subjects:\n");
scanf("%d", &ino_of_subjects);
//calculation1
iaverage = itotal_mark / ino_of_subjects;
daverage = itotal_mark / ino_of_subjects;
printf("The average without typecasting is %d or %lf \n",iaverage,daverage);
//calculation2
iaverage = (double) itotal_mark / ino_of_subjects;
daverage = (double) itotal_mark / ino_of_subjects;
printf("The average with collective typecasting is %d or %lf \n",iaverage,daverage);
//calculation3
iaverage = (double) itotal_mark / (double) ino_of_subjects;
daverage = (double) itotal_mark / (double) ino_of_subjects;
printf("The average with seperate typecasting is %d or %lf \n",iaverage,daverage);
//double, double and double
printf("\n\nThis is for data type: double, double & double\n");
//getting input
printf("Please enter the totalmarks:\n");
scanf("%lf", &dtotal_mark);
printf("Please enter the number of subjects:\n");
scanf("%lf", &dno_of_subjects);
//calculation1
daverage = dtotal_mark / dno_of_subjects;
printf("The average without typecasting is %lf \n",daverage);
//calculation2
daverage = (int) itotal_mark / ino_of_subjects;
iaverage = dtotal_mark / dno_of_subjects;
printf("The average with collective typecasting is %d or %lf \n",iaverage,daverage);
//calculation3
daverage = (int) itotal_mark / (int) ino_of_subjects;
printf("The average with seperate typecasting is %lf \n",daverage);
}