ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

What is the final value of the variable n after this C++ code excuted: int n=5; for(int i=1; i<=n; i++){ cout<<'*'; n--; }?

user-image
تم إضافة السؤال من قبل هاشم المشارقة , Key Account Manager , Advanced United Systems Ltd. ( A member of Taj Holding Group)
تاريخ النشر: 2016/02/03
Gayasuddin Mohammed
من قبل Gayasuddin Mohammed , Advocate , Practicing Law before High Court at Hyderabad

The value of n after the execution is2. it iterates3 times while n decrements by1 and i increments by1 so when3 < =2 (i <=2) fails, loop fails and comes out of the for loop. Thanks.

MohammedMansoor Sahul Hameed
من قبل MohammedMansoor Sahul Hameed , Senior Software Engineer , Femina Lace International

Value of n will be2, since inside the loop value of n is decreasing and the loop will execute only till i<=n.

salma samreen
من قبل salma samreen , Quality Assurance Engineer , Private Limited

int n=5; for (int i=1,i<=5,i++)

cout<<"* n--<<

}

here the output sequence will be you will increment the value of i, till you try to come out of for loop and simultaneously decrement the value of n,

the end result will be4,3,2,1,0

المزيد من الأسئلة المماثلة