Im suppose to write a code using one-dimension array, of size 100 only, and output the array on screen. The user should imput the value n from the keyboard, and then calculate, and display the sum between -n to n ONLY.
Code:
#include <stdio.h>
#define SIZE 100
int main(void)
{
int integer[SIZE], n, j, sum, sum1;
printf("Enter an integer: ");
while (scanf("%s", &integar[n]) !=EOF)
for (n=0;n<100;++n)
{
scanf("d", &integer[n]);
if(integars[n] == -1)
{
j=n;
break;
}
j=100;
for(j=0;j<n;++j){
sum=sum+integer[n];
printf("The sum is %d\n", sum);
}
}
return (0);
}
I started it out, and its giving me a weird output of odd numbers. Im completely lost :S. Where am I going wrong?