-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCONDITIONAL_STATEMENT.CPP
More file actions
193 lines (174 loc) · 3.71 KB
/
CONDITIONAL_STATEMENT.CPP
File metadata and controls
193 lines (174 loc) · 3.71 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// largest of 2 no.
/*
#include<iostream>
using namespace std;
int main(){
int a,b;
cout<<"enter first number:";
cin>>a;
cout<<"enter second number:";
cin>>b;
if(a>b){
cout<<"larger number is:"<<a<<endl;
}
else if(b>a){
cout<<"larger number is:"<<b<<endl;
}
else{
cout<<"both numbers are equal."<<endl;
}
}
// find no. is even or odd.
#include<iostream>
using namespace std;
int main(){
int a;
cin>>a;
if(a%2==0){
cout<<"number is even."<<endl;
}
else{
cout<<"number is odd."<<endl;
}
}
#include <iostream>
using namespace std;
int main(){
int income;
float tax;
cout<<"enter your income (in lakh):";
cin>>income;
if(income<=1){
tax = 0;
}
else if(income>1 && income<=5){
tax = 0.2*income;
}
else if(income>5 && income<=10){
tax = 0.3*income;
}
else{
tax = 0.4*income;
}
cout<<"your tax is: "<<(tax*100000)<<endl;
}
// largest of 3 no.
#include <iostream>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
if(a>b && a>c){
cout<<"largest number is:"<<a<<endl;
}
else if(b>c && b>a){
cout<<"largest number is:"<<b<<endl;
}
else if(c>a && c>b){
cout<<"largest number is:"<<c<<endl;
}
else{
cout<<"all numbers are equal."<<endl;
}
return 0;
}
// largest of 2 no. using ternary operator
#include <iostream>
using namespace std;
int main(){
int a,b;
cout<<"enter a and b:";
cin>>a>>b;
int largest = (a>b) ? a : b;
cout<<"largest number is:"<<largest<<endl;
return 0;
}
// build a simple calculator using switch case.
#include <iostream>
using namespace std;
int main(){
char op;
float num1,num2;
cout<<"enter first number:";
cin>>num1;
cout<<"enter second number:";
cin>>num2;
cout<<"enter operator (+,-,*,/):";
cin>>op;
switch(op){
case '+':
cout<<"result is:"<<num1+num2<<endl;
break;
case '-':
cout<<"result is:"<<num1-num2<<endl;
break;
case '*':
cout<<"result is:"<<num1*num2<<endl;
break;
case '/':
if(num2!=0){
cout<<"result is:"<<num1/num2<<endl;
}
else{
cout<<"division by zero is not allowed."<<endl;
}
break;
default:
cout<<"invalid operator."<<endl;
}
return 0;
}
// find the no. is positive, negative or zero.
#include <iostream>
using namespace std;
int main(){
int a;
cout<<"enter a number:";
cin>>a;
if(a>0){
cout<<"number is positive."<<endl;
}
else if(a<0){
cout<<"number is negative."<<endl;
}
else{
cout<<"number is zero."<<endl;
}
return 0;
}
// For any 3 digit number check whether it’s an Armstrong number or not.
#include <iostream>
using namespace std;
int main(){
int num, originalNum, remainder, result = 0;
cout<<"enter a 3 digit number:";
cin>>num;
originalNum = num;
while(num != 0){
remainder = num % 10;
result += remainder * remainder * remainder;
num /= 10;
}
if(result == originalNum){
cout<<"number is an Armstrong number."<<endl;
}
else{
cout<<"number is not an Armstrong number."<<endl;
}
return 0;
}*/
// to find the no. is leap year or not.
#include <iostream>
using namespace std;
int main(){
int year;
cout<<"enter a year:";
cin>>year;
if((year%4==0 && year%100!=0) || (year%400==0)){
cout<<"year is a leap year."<<endl;
}
else{
cout<<"year is not a leap year."<<endl;
}
return 0;
}