In MATLAB how do I get rid of the 40 at the start CHALLENGE 25.2.3: Basic while
ID: 3733771 • Letter: I
Question
In MATLAB how do I get rid of the 40 at the start
CHALLENGE 25.2.3: Basic while loop expression. ACTIVITY Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow each number by a space. Example output for userNum 40: 20 10 5 2 1 Note: These activities may test code with different test values. This activity will perform four tests, with userNum-40, then with userNum 2, then with userNum 0, then with userNum-1. See "How to Use zyBooks Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report Program end never reached. The system doesn't print the test case that caused the reported message 1 Winclude 3 int nain(void) 1 int userNum; 8 hile(userNum!-e) 1e printf(" ",userNum) 12 13 14 15 printf("In") 16 17 18 return ; Run Testing with userNum = 40 Output differs. See highlights below. Special character legend Your output 40 20 10 5 2 1 Expected output 20 10 5 2 1 X Test aborted View your last submissionExplanation / Answer
#include<stdio.h>
int main(void) {
int userNum;
int flag = 0;
userNum = -1;
while(userNum != 0)
{
if(flag == 1)
{
printf("%d ",userNum);
}
flag = 1;
userNum = userNum/2;
}
printf(" ");
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.