Home Forums C Programming c array bound Reply To: c array bound

#3406
Humayan
Participant

It looks like in the code below you are you are only using the first item in the array ( a [ 0 ] )  to read in values in the for loop:

scanf(“%d”,&a);
 
you then add the address of the address of the first item in the array to ‘s’:

s=s+a;
 
and then print this sum. I think you should try:

s = s + a [ 0 ] ;
 
for the proper result. To read stepping through the array do:
 
for( i = 0 ; i < n ; i ++ )
{
     scanf ( “%d” , &a [ i ] );
     s = s + a [ i ];
}