SRM ELAB SOLUTIONS OOPS
I/O Operations 3
- Waiting or Not Waiting
- Letter Pattern
- Scientist Game
- You and Me
- Dhoni and Ziva in Chennai
Waiting or Not Waiting
#include <iostream>
using namespace std;
int main()
{
int a;
cin >> a;
if (a > 0)
cout << "I am waiting";
else if (a < 0)
cout << "I am not waiting";
else
cout << "Sorry";
return 0;
}
Letter Pattern
#include <iostream>
using namespace std;
int main()
{
int i, j, n;
char ch = 'A';
cin >> n;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
{
if (ch < 'Z' + 1)
cout << ch++;
else
{
ch = 'A';
cout << ch++;
}
}
cout << endl;
}
return 0;
}
Scientist Game
#include <iostream>
using namespace std;
int main()
{
int origNum, num, rem, sum = 0;
cin >> origNum;
num = origNum;
while (num != 0)
{
rem = num % 10;
sum += rem * rem * rem;
num /= 10;
}
if (sum == origNum)
cout << "Give to Scientist Armstrong";
else
cout << "Dont Give to Scientist Armstrong";
return 0;
}
You and Me
#include <iostream>
using namespace std;
int main()
{
int a, b, c;
cin >> a >> b;
cout << "I am " << a << endl;
cout << "You are " << b << endl;
c = (a + b) / 2;
cout << "We are around " << c;
return 0;
}
Dhoni and Ziva in Chennai
#include <iostream>
using namespace std;
int main()
{
float a;
int b;
cin >> b;
a = (16.6 * b) / 100;
cout << "Your weight on moon is : " << a;
return 0;
}
0 Comments