Assignment Operators and Expressionswith Answers
Assignment Operators and Expressionswith Answers
Class XI
Subject Computer Science
i) x *(++ y) y % 10 +3
ii) (x+y > z) ? cout<<( ++ x y) :cout<< (- - z + ++y) where x=8, y=10, z=8
Answer :
i. 90
ii. -1
3. Construct logical expressions to represent the following conditions
i) salary is in the range 8000 to 10000
ii) ch is an uppercase letter
iii) weight is greater than or equal to 30 but less than 50
iv) a is an odd number
Answer:
i. salary>=8000 && salary<=10000
ii. ch>=65 && ch<=90
iii. weight>=30 && weight<50
iv. a%2!=0? cout<<Odd:cout<<Even;
Answer: 5
9. Give the output
#include<iostream.h>
void main()
{ int U=10, V=20;
cout<<[1]=<<U++<<&<<V-5<<endl;
cout<<[2]=<<++V<<&<<U+2<<endl; }
Answer: [1]=10&15
[2]=21&13
10. Differentiate between the following.
ii) = and = =
iii) / and %
Unary: They operate on single operands eg. increment decrement operators(++,--), unary
Binary: operate on two operands eg arithmetic, relational, logical operators
Ternary: operate on three operands, eg conditional operator ?:
Give output:
#include<iostream.h>
void main( )
{
int a=2,b=5,c=3,m;
m=(a>b) ? c : (( b>c) ? b : c ) ;
cout<<m;
}
Answer : 5
Answer: 21
21
After replacing: 21
20
int n=7;
cout<<n++=<<n++<<,n=<<n<<\n;
Answer :
n++=7,n=8
24. What will be the size of following constants : \a , A\a , Reema\s , / \ .
int a = 5 + 7 % 2;
cout<<a;
Answer :
366
Answer :
i. True or 1
ii. c=13.5
iii. False or 0
Answer:
(i) T=(z+3)*(y-4)
(ii) W=log(v)
(iii) A=tanh(x)
36 Explain the following functions with example
clrscr() (ii) pow() (iii) sqrt (iv) ceil() (v) setw() (vi) floor
Answer:
i. in the first statement the value 5 is assigned to 5 whereas in the second statement it is
checked whether the value of v is 5 .
ii. first statement : v= 5, in the second statement 0 will be output as v =10 thus statement
v= =5 will be false or 0.
39. Correct the error(s) if any in the following code segment
int i, float k; i = 25;
k = 75.90;
cout >> \n Enter The new values of I and k ;
cin << i<< k;
cout<< The new values are \n << i <<\n << k;
Answer :
int i, float k;
i = 25;
k = 75.90;
cout << \n Enter The new values of I and k ;
cin >> i>> k;
cout<< The new values are \n << i <<\n << k;
Answer:
i. True
ii. True
iii. True
iv. False
v. False