3 Lec 3
3 Lec 3
• input statement to get input from keyboard during execution of the program
is cin, pronounced as see in.
• Its part of the iostream header file.
• General syntax:
cin>>var1;
OR cin>>var1>>var2>>var3;
• >> is called extraction operator or get from operator.
• During execution of program, when a cin command encounters, the
computer waits to receive an input from keyboard. When a value is
typed and the ENTER key is pressed , a value is assigned to a
variable and control shifts to the next statement
assigment
• Write a program that takes marks of three
subjects as an input from user and
displays the total and average of these
subjects.
Compound assignment statement
• x=y=z=10;
• Compound assignment expression:
var operator= expression;
where expression is any expression whose value is assigned to variable. It can
be a single variable or constant
Operator is +, _, *, /
• Examples:
xy=xy+10; can be written as xy+=10;
x -= 2;
y *= 4;
n /=7;
Increment operator
• The operator that is used to add 1 to the
value of a variable.
• xy++;
• Prefix increment ++xy;
• Postfix increment xy++;
Decrement operator
• Subtracts 1 from the value of a variable.
• Postfix increment xy--;
• Prefix increment --xy;
assignment
• Write a program that takes a no as input
from user and displays the square and
cube of that number.
• Write a program that takes a no1 and a
no2 as input from user and display
quotient and remainder of the two.