Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

progaming homework help please and thank you LOOPING * *********** 1) Describe t

ID: 3694791 • Letter: P

Question

 progaming homework help please and thank you  LOOPING *  ***********  1) Describe the difference between a while loop and a do-while loop.  2) Write a program that counts up to 100.  3) Write a program that prints the sum of the first 100 even numbers. So,     you're doing 2 + 4 + 6...+ 100 (hint: increment by 2. You need a     running sum.)  4) Keep reading numbers from the user until they enter a zero. Then print     the average of all the numbers you've read in except for the zero.  5) Write a program that reads numbers from the user, and stops when the     user enters a zero. Then print the largest number the user entered.     (hint: keep track of the largest number the user has entered. Compare     each new number to the largest number you've seen so far.)  6) Write a program that asks the user to enter two numbers. Then prints     all the numbers in that range. So for eg, if the user enters a 3 and 7,     your program should print 3, 4, 5, 6, and 7. (hint: where should you     start your counter? Where should you end it? When should your looping     condition become false?)  7) Ask the user what multiplication table they want. Then print that     multiplication table on the screen up to 25. So for eg, if the user     enters a 5, the output should be          5 x 1 = 5          5 x 2 = 10          ...         5 x 25 = 125  8) Write a program that keeps printing random values until the user enters     a number greater than 50. Then it counts down to zero from that number.     (hint: two separate loops. When does the first one stop? When does the     second one stop?)  9) Write a program that asks the user to enter a number, and then     estimates the square root of the number (hint: just check to see if     your counter*counter is < the number)  ******************************** SKIP THIS ONE. GO TO QUESTION 11 10) Write a program that asks the user to enter two numbers--the small      one, and the large one. Then find their least common divisor. The      least common divisor is the smallest number other than one that      divides both numbers without any remainder. ********************************  11) Write a program that asks the user to enter two numbers--the small      one, and the large one. This time around, find their greatest common      divisor (hint: you need to keep track of your GCD in a variable. And      as soon as you find a new, greater one, store that in your variable      etc.  until you're finished).  12) Play a guessing game with the user. Generate a random number, then let      the user guess what it is. If the user's guess is too low, tell them      to increase their guess. If their guess is too high, tell them to      lower it. Keep doing this until they guess it right. Then print      congrats!  13) Write a program that asks the user to enter a number. Then print all      of its divisors. (hint: if-statement with the modulous operator inside      a loop.)  14) Write a program that asks the user to enter a number. Then it      determines if the user entered a prime number or not (hint: a prime      number is one that has only 2 divisors. 1, and itself. It's the same      as #12, except instead of printing the divisors you find, you're      counting them, and have an if-else statement at the end to determine      if it was prime or not).  15) Write a program that asks the user to enter a number. Then it prints      all the prime numbers up to that point (hint: This is basically #13      wrapped in another loop).  16) True/false:   a) The while loop and do while loop are functionally equivalent. Whatever  you can do in one, you can do in the other as well.  b) A while loop runs 0 or more times.  c) A do-while loop runs 1 or more times.  d) Loops keep executing over & over again for as long as the condition  stays true. 

Explanation / Answer

ans) While loop is an entry control loop and do-While is an exit control loop.
   While Loop executes minimum zero number of times and do-While loop executes minimum 1 times. this is because the condition is checked once the statements inside the loop are executed.

2) Write a program that counts up to 100.

ans) this code will print the count once it turn to 100

#include<stdio.h>

int main()
{
int count=0;
while(count<100)
{
count++;
}
printf("the count is :%d",count);
}

// this code will print for every count increment.

#include<stdio.h>

int main()
{
int count=0;
while(count<100)
{
count++;

printf("the count is :%d",count);
}
return 0;
}

ans) #include<stdio.h>

int main()
{
int i=2,sum=0;
while(i<100)
{
sum=sum+i;
i=i+2;
  
}
printf("the sum of even numbers is :%d",sum);
}

the above mentioned code will sum even numbers upto 100.

#include<stdio.h>

int main()
{
int i=2,sum=0, count=0;
while(count<100)
{
sum=sum+i;
i=i+2;
count++;
}
printf("the sum of first 100 even numbers is :%d",sum);
}//this is the code to print sum of first 100 even numbers.

ans) #include<stdio.h>

int main()
{
int number,sum=0,count=0;
float average=0;
while(1)
{
printf("enter the any number(enter 0 to exit):");
scanf("%d",&number);
if(number==0)
break;
sum=sum+number;
count++;
}
average=(float)sum/count;
printf("the average of the given %d numbers is :%f",count,average);
}