Friday, 2 March 2012

C++ Practice A-1

Dear Readers,


 Now we can try how it possible to reading a input from our keyboard and how to print it on the screen.


--------------

#include<iostream.h>
#include<conio.h>
void main()
{
int a;
clrscr();
cout<<"Enter Your Number :";
cin>>a;
cout<<"Your Number is :";
cout<<a;
getch();
}
------------
Scrrenshot


coding


Output

In the program's main function ( starting from  {  ),

I declared a variable -   int a;    - as an integer and named it "a" . Here "int" is a keyword used for declaring a variable and "a" is the name of that variable.

In the other line -  clrscr();   -function for clearing the screen. we discussed about it in our first program.

In next line -   cout<<"Enter Your Number :";   - I printed a message on screen "Enter Your Number" for the user of the program.

in the next step -    cin>>a;   - function for reading input from the user of the program through keyboard.Here " cin " is the keyword used for reading input from keyboard. " >> " symbol directing the read input to the variable we declared as integer two lines before.

In next -   cout<<"Your Number is :";   -  again I printed a message(Your Number is :" on the screen using " cout"  printing function.

In next -  cout<<a;   - again I printed the value in the variable on the screen. here  " cout" printing function printing the value of the variable named " a " on the screen  .

In last line I called the - getch();   - function for showing the result on the screen.

So that's it. I hope you understood the program  well. So we learned two new things with this program.

A READING INPUT FUNCTION        -   cin>>a;

A PRINTING OUTPUT FUNCTION  -   cout<<a;

Now I am going to sign off. I am going to do my home work. You too can do some experiments. 

Try to read two input and print that two input on the screen. (click to see)

Best of luck.

Thanks & Regards,

Sidh




0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Web Hosting Coupons