You are on page 1of 3

1. Integer Numbers that outputs the Sum.

#include <iostream>
using namespace std;

int main() {

int first_number, second_number, sum;

cout << "Enter two integers: ";


cin >> first_number >> second_number;

// sum of two numbers in stored in variable sumOfTwoNumbers

sum = first_number + second_number;

// prints sum

cout << first_number << " + " << second_number << " = " << sum;

return 0;
}

2. Program that swaps two numbers

#include <iostream>
using namespace std;

int main()
{
int a = 5, b = 10, temp;

cout << "Before swapping." << endl;


cout << "a = " << a << ", b = " << b << endl;

temp = a;
a = b;
b = temp;

cout << "\nAfter swapping." << endl;


cout << "a = " << a << ", b = " << b << endl;

return 0 }
3. Program that Calculates the volume of a sphere.

#include <iostream>
using namespace std;

float solve( float r ) {


float volume;
volume = ( 4 / 3 ) * 3.14159 * ( r * r * r);
return volume;
}
int main() {
cout << "Volume of a sphere with radius r = 2.5 cm, is " << solve( 2.5 ) << " cm^3" << endl;
cout << "Volume of a sphere with radius r = 5in, is " << solve( 5 ) << " in^3" << endl;
}

4. Fahrenheit to Celsius:

#include <iostream>

using namespace std;


int main() {

float fahren, celsius;


cout << "Enter the temperature in fahrenheit\n";
cin >> fahren
celsius = 5 * (fahren - 32) / 9;
cout << fahren <<" Fahrenheit is equal to "
<< celsius <<" Celsius";

return 0;

}
5. Program wherein it checks if the input number is Negative, Positive or Zero.

#include <iostream>

using namespace std;

int main()
{
int num1;
cout << "Enter the number: ";
cout << " ";
cin>>num1;

if(num1>0){
cout<<num1<<" is a Positive number";
}
else if(num1<0){
cout<<num1<<"is a Negative number";
}
else{
cout<<"You entered Zero";
}
return 0;
}

You might also like