Question

1. From the list below, which term/topic has NOT been discussed in lecture? (type in the...

1. From the list below, which term/topic has NOT been discussed in lecture?

(type in the answer area below the one topic from the list of five that has not been discussed)

List:

looping

debugging

paging tables

precision

compiler

2. Write a while loop that accepts integers from the user until a negative number is entered. The prompt should be "Enter a number (negative to quit):" Add up the numbers and print the sum (not including the negative number). Assume and use the following declarations:

int sum = 0;  int num;

Homework Answers

Answer #1

Greetings!!

Code:

#include <stdio.h>

#include <stdlib.h>

int main()

{

    int sum=0;

    int num;

    while(1)                                          //always enter into the loop

    {

        printf("Enter a number (negative to quit):\n"); //prompt message

        scanf("%d",&num);                    //read the number from the user

        if(num>0)                                    //check whether the number is positive

            sum=sum+num;                      //if the number is positive then find the sum

        else

            break;                                      //go out of the loop if the number is negative

    }

    printf("Sum of the entered numbers: %d\n",sum);     //print the sum

return 0;

}

Output screenshots:

Hope this helps

Thank You

Know the answer?
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
Similar Questions