C++ Programs with Collapsible Answers
#include <iostream>
using namespace std;
int main() {
cout << "Hello world";
return 0;
}
#include <iostream>
using namespace std;
int main() {
cout << "subject" << "\tmarks" << "\nmathematics\t" << 90
<< "\ncomputer\t" << 77 << "\nchemistry\t" << 69;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cout << "\nEnter first number : ";
cin >> a;
cout << "\nEnter second number : ";
cin >> b;
c = a + b;
cout << "\nThe Sum is : " << c;
return 0;
}
#include <iostream>
using namespace std;
int main() {
float F, C;
cout << "\nEnter temperature in Fahrenheit : ";
cin >> F;
C = 5 * (F - 32) / 9;
cout << "Temperature in Celsius is : " << C;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int p, r, t, i;
cout << "Enter Principle : ";
cin >> p;
cout << "Enter Rate : ";
cin >> r;
cout << "Enter Time : ";
cin >> t;
i = (p * r * t) / 100;
cout << "Simple interest is : " << i;
return 0;
}
#include <iostream>
using namespace std;
int main() {
char ch;
cout << "\nEnter any character : ";
cin >> ch;
cout << "ASCII equivalent is : " << int(ch);
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a, b, temp;
cout << "\nEnter two numbers : ";
cin >> a >> b;
temp = a;
a = b;
b = temp;
cout << "\nAfter swapping numbers are : " << a << " " << b;
return 0;
}
#include <iostream>
using namespace std;
int main() {
float r, area;
cout << "\nEnter radius of circle : ";
cin >> r;
area = 3.14 * r * r;
cout << "Area of circle : " << area;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a;
cout << "Enter any non-zero Number : ";
cin >> a;
(a > 0) ? cout << "Number is positive" : cout << "Number is negative";
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a;
cout << "Enter the Number : ";
cin >> a;
(a % 2 == 0) ? cout << "Number is even" : cout << "Number is odd";
return 0;
}