
Our second program in C
#include <iostream.h>
main()
{
int ho;
cout <<"how many years old are you?"
<<"\n" ;
cin >> ho;
cout << "you are " << ho <<" years
old";
}
Result
This program
will ask you “how many years old are you” and then it will tell you your age.
Explanation
In this program
there are many commands which I have explained above so I will not repeat them.
B/w braces we
have typed “int ho;” this line will declare the variable “ho”.
Then after
cout we have type “<<” to times so in one cout so I m telling you that
you can print as many thing as you want on screen by putting “<<” in one
cout.
Then we type
“\n”, it will tell program to go to next line.
Then we have
typed “cin >> ho;” this will give user a chance to enter his/her data and
after pressing enter computer will store the data in the variable “ho”.
Then after
“cout << “you are”” we have typed “<< ho” without quotes mark this
mean that it will not print ho instead it will print ho’s value.
If you have any doubt about any
calculation put bracket in that place
Note:
Bracket
and comments are free mean they can be used freely.
(In C) In
calculations only parentheses are used not any other brackets
0 comments:
Post a Comment