Posts

Showing posts with the label cppExample

Take number from user input

  User input: In this example of c++,taking number from the user as input.here is the code of this problem taking input. code: #include<iostream> using namespace std; int main() { char ch;                               //declare variable of character cout<<" enter the any character"<<endl;                     //message for taking input cin>>ch;                          //take input  //display enter character cout<<ch; return 0; } Output: enter the any character h h In this code, take input from the user through in and store in the ch variable. Then use this ch variable to display on the screen.

Hello world program

This program has very simple code but it is used to understanding for the newbies.In the beginning of the programming language learn this example. lets see the "Hello world" program code: //first program in c++ #include<iostream> int main() { std::cout<<" Hello world"; return 0; } Output: Hello world How Hello world program work In the first line,(//) comment is used to explain what is doing here,It is useful for code reader to understand what actually code does. For now,In the second line, library iostream is used to court something on the screen. The main() must involve in the c++ code because execution start from this main() function. std:: cout<<" Hello world "; is used to display message on the screen. return 0 is exit statement for c++ program in the main()  function.