my program was supossed to Read a series of integer numbers from the keyboard into a one-dimensional array (with no more than 100 integer numbers). Then output the array on the screen. Then ask the user to input an integer number n from the keyboard. Then calculate the sum of numbers in the array between –n and n inclusive. And finally display the sum on the screen.
This is my program i've created, can anyone tell me my errors?
#include <stdio.h>
int
main()
{
int array[100];
int number=1, n, i=0, j, sum;
do{
if (number>=0)
printf ("Enter an integer: ");
scanf ("%d", &number);
i++;
}
while (i<=100);
printf ("Enter an integer and ill tell you the sum of the numbers between the - and + integer: ");
scanf ("%d, &n");
for(j=1; j<=i; ++j){
if (n + array[j]<= 2*n && n+array[j]>=0);
else n+i;
sum = sum+array[j];
}
printf ("the sum of the integers is %d", sum);
return (0);
}
if also posted it here, http://codepad.org/GccwmA5C.
This is my program i've created, can anyone tell me my errors?
#include <stdio.h>
int
main()
{
int array[100];
int number=1, n, i=0, j, sum;
do{
if (number>=0)
printf ("Enter an integer: ");
scanf ("%d", &number);
i++;
}
while (i<=100);
printf ("Enter an integer and ill tell you the sum of the numbers between the - and + integer: ");
scanf ("%d, &n");
for(j=1; j<=i; ++j){
if (n + array[j]<= 2*n && n+array[j]>=0);
else n+i;
sum = sum+array[j];
}
printf ("the sum of the integers is %d", sum);
return (0);
}
if also posted it here, http://codepad.org/GccwmA5C.