A basic C programming question, help please! 15, what is the output of the follo
ID: 3723558 • Letter: A
Question
A basic C programming question, help please!
15, what is the output of the following: ' (You only need to write the number and value of data, i.e, 11. 30) (15 points) include int main0 int data 22; do 2) afa (22) theref ore, number ,ss( .ta:n valve of datu:22 if(data> 0) rint f(" 1 1 .data is even %dIn", data): else printf("22, data is odd %dn", data); data *=-1; else data *=-1; data++ if((data%2)--0) printf("33. data is even %din', data); else printf("44, data is odd %dn", data); data -2 3 while (data 45); return 0;Explanation / Answer
Answer :
Output is :
11.data is even 22
44.data is odd 45
Explanation:-
Pass 1: data =22
It will go inside do-while loop. If condition is checked,i.e, 22>0, true so if part is to be executed.
(22%2==0) :It holds true.
So it will print " 11.data is even 22".
now data *=-1. So data = -22.
It will come out of if loop and compute data *=2,i.e.,data = -44.
Pass 1 is over.
Pass 2: data = -44
-44>0 : it is false. So else part will be executed.
data *= -1; data = -44 *-1=44.
data++; data = 44+1=45.
if(45%2==0) ,It is false so else part will be printed ,i.e., "44.data is odd 45".
now data = 45*2=90.
while loop doesn't satisfy(90<45) so it will come out of do-while loop.
Final answer will be printed.
output:
11.data is even 22
44.data is odd 45
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.