C++
Hello World Program
// C++ program to demonstrate how to print your
// name using printf() method
#include <bits/stdc++.h>
using namespace std;
int main() {
// Printing the name using printf() method
printf("Anmol");
return 0;
}
Output
Anmol
// C++ Program to demonstrate how to print your
// name using puts() method
#include <bits/stdc++.h>
using namespace std;
int main() {
// Printing the name using puts function
puts("Anmol");
return 0;
Output
Anmol
// C++ program demonstrate how to print your
// name by taking it as input
#include <bits/stdc++.h>
using namespace std;
int main() {
// Variable to store the name
string str;
// Taking the name string as input using
// cin object
cin >> str;
// Print the name string using cout object
cout << str;
return 0;
}
Input
Anmol
Output
Anmol
Check Whether Number is Even or odd using if else
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter an integer: ";
cin >> n;
if ( n % 2 == 0)
cout << n << " is even.";
else
cout << n << " is odd.";
return 0;
}
Output
Enter an integer: 23
23 is odd.
Print Number Entered by User
#include <iostream>
using namespace std;
int main() {
int number;
cout << "Enter an integer: ";
cin >> number;
cout << "You entered " << number;
return 0;
}
Output
Enter an integer: 23
You entered 23
Program to Add Two Integers
#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;
}
Output
Enter two integers: 4
5
4+5=9