-
Notifications
You must be signed in to change notification settings - Fork 0
/
1 assignment.txt
168 lines (134 loc) · 3.91 KB
/
1 assignment.txt
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
Q1 - Write a program to check whether two numbers (entered by user) are equal or not
#include<iostream>
using namespace std;
int main(){
int a;
cout<<"Enter A Value: ";
cin>>a;
int b;
cout<<"Enter B Value: ";
cin>>b;
if(a==b){
cout<<"A and B are equal";
}else{
cout<<"A and B are not equal";
}
//if you want to get output as a boolean value then you print bool return 0 for flase or 1 is true
// if(a==b){
// cout<<true;
// }else{
// cout<<false;
// }
return 0;
}
Q2 - Write a program to take the values of two variables a and b from the keyboard and then check if
both the conditions 'a < 50' and 'a < b' are true.
#include<iostream>
using namespace std;
int main(){
int a;
cout<<"Enter A value: ";
cin>>a;
int b;
cout<<"Enter B value: ";
cin>>b;
if(a<50 && a<b){
cout<<true;
}else{
cout<<false;
}
return 0;
}
Q3 - There are 45 total pupils in the class, 25 of whom are boys. Write a program to find how many
girls received grades "A" if 17 boys made up 80% of the students that received grades "A".
#include<iostream>
using namespace std;
int main(){
int total, boys, girls;
cout<<"Enter the total number of student: ";
cin>>total;
total= (80*(total))/100;
boys = 17;
girls = total - boys;
cout<<"Total girls recieved A grade: "<<girls<<endl;
return 0;
}
Q4 - Write a program to calculate the sum of the first and the second last digit of a 5 digit number.
#include<iostream>
using namespace std;
int main(){
int a;
cout<<"Enter the 5 digit number: ";
cin>>a;
int sum;
int first = a/10000; //first digit
a = a%10000;
int second = a/1000; //second digit
a = a%1000;
int third = a/100; //third digit
a = a%100;
int fourth = a/10; //fourth digit
int fifth = a%10;
sum= first+fourth;
cout<<"First and second last digit of sum is: "<<sum<<endl;
return 0;
}
Q5 - Write a program to calculate the sum of digits of a 3 digit number.
#include<iostream>
using namespace std;
int main(){
int num, first, second , third, sum;
cout<<"Enter the 3 digit number: ";
cin>>num;
first = num/100;
num %= 100;
second = num/10;
num %= 10;
third = num/1;
num %= 1;
sum = first + second + third;
cout<<"Total three digit sum: "<<sum<<endl;
return 0;
}
Q6 - Design a calculator to perform basic arithmetic operations (+,-,/,*,%)
#include<iostream>
using namespace std;
int main(){
char operators;
cout<<"Enter the following operators (+ - * / %): ";
cin>>operators;
float a, b;
int c, d;
if(operators=='%'){
cout<<"Enter c value: ";
cin>>c;
cout<<"Enter d value: ";
cin>>d;
}else{
cout << "Enter the a value: ";
cin >> a;
cout<< "Enter the b value: ";
cin>>b;
}
switch(operators){
case '+':
cout << a << " + " << b << " = " << a + b;
break;
case '-':
cout << a << " - " << b << " = " << a - b;
break;
case '*':
cout << a << " * " << b << " = " << a * b;
break;
case '/':
cout << a << " / " << b << " = " << a / b;
break;
case '%':
cout << c << " % " << d << " = " << c % d;
break;
default:
cout<<"Enter the value by given instruction! ";
break;
}
return 0;
}