More while loops

Bidding example.

Write an expression that continues to bid until the user enters ‘n’.

#include <stdio.h>
#include <stdlib.h>

int main(void) {
 char keepGoing;
 int nextBid;

srand(5);
 nextBid = 0;
 keepGoing = 'y';

while (keepGoing !='n') {
 nextBid = nextBid + (rand()%10 + 1);
 printf("I'll bid $%d!\n", nextBid);
 printf("Continue bidding? (y/n) ");
 scanf("%c", &keepGoing);
 }
 printf("\n");

return 0;
}

 

While loop: Insect growth.

Given positive integer numInsects, write a while loop that prints that number doubled without reaching 100. Follow each number with a space. After the loop, print a newline. Ex: If numInsects = 8, print:

8 16 32 64
#include <stdio.h>

int main(void) {
 int numInsects;

numInsects = 8; // Must be >= 1


 if(numInsects<100){
 printf("%d ", numInsects);
 }
 while((numInsects>=1)&&numInsects<100){
 
 numInsects=numInsects*2;
 if(numInsects<100){
 printf("%d ", numInsects);}
 }
printf("\n");

return 0;
}