Ask Question
26 November, 04:36

program that reads numbers from scanf (keyboard) and then sums them, stopping when 0 has been entered. Construct three versions of this program, using the while, do-while, and for loops.

+3
Answers (1)
  1. 26 November, 06:34
    0
    I'm going to write three examples in C language:

    int main () {

    int n, i, sum = 0;

    printf ("Enter the number: ");

    scanf ("%d", &n);

    for (i = 1; i < = n; + +i) {

    sum + = i;

    }

    printf ("Sum = %d", sum);

    return 0;

    }

    int main () {

    int n, i, sum = 0;

    printf ("Enter a number: ");

    scanf ("%d", &n);

    i = 1;

    while (i < = n) {

    sum + = i;

    ++i;

    }

    printf ("Sum = %d", sum);

    return 0;

    }

    int main () {

    int n, i, sum = 0;

    do {

    printf ("Enter a number: ");

    scanf ("%d", &n);

    } while (n < = 0);

    for (i = 1; i < = n; + +i) {

    sum + = i;

    }

    printf ("Sum = %d", sum);

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “program that reads numbers from scanf (keyboard) and then sums them, stopping when 0 has been entered. Construct three versions of this ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers