Question

Given positive integer num_insects, write a while loop that prints that number doubled up to, but...

Given positive integer num_insects, write a while loop that prints that number doubled up to, but without exceeding 100. Follow each number with a space. Ex: If num_insects == 8, print: 8 16 32 64

num_insects = 8 # Must be >= 1

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Pseudocode:

int num_insects;

printf(" Enter any number ");
scanf("%d",&num_insects);

while(num_insects>=1&&num_insects<100)
   {
       printf("%d ",num_insects);
       num_insects=num_insects*2;
   }

program :

#include<stdio.h>
void main()
{
   int num_insects;
   printf(" Enter any number ");
   scanf("%d",&num_insects);
   if(num_insects<1) /* input number must be greater then 0 */
   printf(" Please enter a number greater than zero");
   while(num_insects>=1&&num_insects<100)   /* loop condition to check for a number condition */
   {
       printf("%d ",num_insects);
       num_insects=num_insects*2; /* doubling the number */
   }
}

Screen shots:

Output:

Add a comment
Know the answer?
Add Answer to:
Given positive integer num_insects, write a while loop that prints that number doubled up to, but...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT