Computer Science, asked by fmustang207, 8 months ago

-8) Write sample program of C or C++.

Answers

Answered by imtiyazallam
0

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.

Attachments:
Answered by anindyaadhikari13
1

\star\:\:\:\sf\large\underline\blue{Question:-}

  • Write a sample program of C or C++.

\star\:\:\:\sf\large\underline\blue{Example\:Program:-}

  • This is an example program to print hello world.

  1. #include <iostream.h>
  2. int main()
  3. {
  4. std:: cout<< "Hello World!!!!";
  5. return 0;
  6. }

\star\:\:\:\sf\large\underline\blue{Output:-}

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.

Similar questions