Task:
1. Take the name and ID as input from the user
2. Take two numbers from the user then add those numbers
3. Check if the summation is odd or even
4. Print all the odd numbers from 1 to 100
5. Take a number from the user then find the factorial of that number
6. Find if a number is prime
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
cout << "Hello! This is my first program.";
cout << " C++ is fun." << endl;
int number1;
number1;
int number2;
int sum;
cout << number1 <<endl;
cout << number2 <<endl;
cout << "\nPlease enter two number: " << endl;
cin >> number1;
cin >> number2;
cout << "Given numbers are: " << endl;
cout<< number1 <<endl;
cout<< number2 <<endl;
//Take the name an d ID as input from user
string name;
int id;
cout << "Enter your name: ";
cin >> name;
cout << "Enter your Id: ";
cin >> id;
cout << "Given name & id: " << endl;
cout << "Name: " << name << endl;
cout << "ID: " << id << endl;
//Take two numbers from the user then add those numbers
cout << "\nPlease enter two number: " << endl;
cin >> number1;
cin >> number2;
sum = number1 + number2;
cout << "\nSum: " << sum << endl;
//Check if the summation is odd or even
if(sum % 2 == 0){
cout << "Sum is even number." << endl;
}else{
cout << "Sum is odd number." << endl;
}
//Print all the odd numbers from 1 to 100
cout << "\nOdd numbers between 1 to 100: " << endl;
for(int i =1; i<=100; i++){
if(i % 2 != 0){
cout << i << endl;
}
}
//Take a number from user then find the factorial of that number
int fnum, fact = 1;
cout << "Enter number: " << endl;
cin >> fnum;
for(int i = 1; i <= fnum; ++i){
fact *= i;
}
cout << "Factorial of " << fnum << ": " << fact << endl;
//Find if a number is prime
int pnum;
cout << "Enter number: " << endl;
cin >> pnum;
if(pnum%1 == 0 && pnum % pnum == 0){
cout << "Prime number." << endl;
}
}
0 Comments