hi
i am currently working on loops and i would like to know how to input multiple numbers into a for loop and a while loop and get the sum of them numbers for the output
i just cant seem to get my head round this problem
help much appreciated
thanks
This is a discussion on how to enter multiple numbers using a for & while loop within the C Programming forums, part of the General Programming Boards category; hi i am currently working on loops and i would like to know how to input multiple numbers into a ...
hi
i am currently working on loops and i would like to know how to input multiple numbers into a for loop and a while loop and get the sum of them numbers for the output
i just cant seem to get my head round this problem
help much appreciated
thanks
The sum of some numbers doesn't require a loop, it just requires arithmetic, eg:
Code:int sum = 2+3+4;
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
yes i know this but i want it to keep a running total and learn more about loops
so as soon as the user enters a number it will qrun through the loops and add the inputted numbers until it has reached 10 numbers
Something like:
Code:#include <stdio.h> int main(int argc, const char *argv[]) { int i, x, total = 0; for (i = 0; i < 10; i++) { printf("Enter a number: "); scanf("%d",&x); total += x; } printf("The total is %d\n",total); return 0; }
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
thanks im going to have to check this out im going to try the while loop also ill let you know if i get stuck
thank you