-8) Write sample program of C or C++.
Answers
Answer:
#include<iostream>
using namespace std;
int main(){
int num;
cout << "Enter a number: ";
cin >> num;
if(num % 2 == 0){
cout << "It is a even number.";
}else{
cout << "It is a odd number.";
}
}
This program checks whether a number is even or odd.
- Write a sample program of C or C++.
- This is an example program to print hello world.
- #include <iostream.h>
- int main()
- {
- std:: cout<< "Hello World!!!!";
- return 0;
- }
Hello World!!!!!
How it works?
Line number 1:
Here #include is a preprocessor directive used to include files in a program.
Line number 2:
Given line indicates the main function. The curly braces indicate the starting and ending of the function. From here, execution starts.
Line number 4:
This line is used to print Hello World!!
std::cout<< prints the content inside the question mark. Semicolon is used to mark the end of the statement.
Line number 5:
return 0 is the exit status of the program. Here, the program terminates.