Professional Documents
Culture Documents
Tutorial 2
Purpose of writing comments is for the developers(programmers) to identify different stages of the
program much easily.
2. ‘Main’ function.
4. Yes
5.
(a) valid
(c) invalid because a dash symbol cannot be used to separate words in an identifier
(f) valid
(i) valid
(j) invalid because a number cannot be used to start an identifier name and also dash symbols cannot
be used
6.
a) False, \n must be used to begin in a new line.
b) False, because compiler ignores comments.
c) True
Q1.
• x=x+1
• x++
• ++x
• x+=1
Q2.
a) Z=(x++) + y
b) x*=2
c) x=x*2
d) if(count>10) printf(“count is greater than 10”);
e) total=(--x) - total
f) total=total+x--
g) q=q/d
q/=d
h) printf(“%.2f”,123.4567)
Output is 123.45
i) printf(“%.3f”,3.14159);
Output is 3.141
Q3.
a) scanf(“%.d”,&x);
b) scanf(“%d”,&y);
c) i=1;
d) power=1;
e) power=power*x;
f) i=i+1;
g) while ( i <= y)
h) printf(“%d”,power);
2) Output :
No, I’m here!
if (doesSignificantWork)
if (makesBreakthrough) nobelPrizeCandidate =
true;
else
nobelPrizeCandidate = false;
false;
4)
– If character variable taxCode is ’T’, increase price by adding the taxRate percentage
of price to it.
If(taxCode==’T’)
– If integer variable opCode has the value 1, read in double values for X and Y and
calculate and print their sum.
double x,y,sum;
printf(“sum is
%lf”,sum);
– If integer variable currentNumber is odd, change its value so that it is now 3 times
currentNumber plus 1, otherwise change its value so that it is now half of currentNumber
(rounded down when currentNumber is odd).
if(currentNumber%2==1)
currentNumber=(currentNumber*3)+1;
else
currentNumber=currentnumber*0.5;
– Assign true to the boolean variable leapYear if the integer variable year is a leap year.
(A leap year is a multiple of 4, and if it is a multiple of 100, it must also be a multiple of
400.)
Distance Cost
----------------------------------- ----------
double cost;
if(distance> 0 && distance<100)
cost=5.00; else if(distance> 100
&& distance<500)
cost=8.00;
else if(distance>500 && distance<1000)
cost=10.00;
else(distance== 1000 && distance>1000)
cost=12.00;
Switch
W
While Loop
1)
Do While Loop
1)
2)
2)