I really need ur help!

I am a CE student and I am still learning the basics
so far I am studying the array on c++ program
I have this question and Unfortunately I have no idea how to slove it!
-------------------------------------------------------------------------------
>> Lab question 9.1.3

All the steps are related. You need to write all the code in just one program file. Declare any new variable when required.
Copy the following piece of code into your Visual C
#include <stdio.h>
#define size 7
void main (void)
{
int List[size]={0};

}



 Add a portion of code that would read the values for the array list from the users.
 Add a portion of code that would display the values of array list to user.
 Add a portion of code that would sum up all the values of array list and print the sum to users.
 Add a portion of code that would find and display the least value in the list.
 Add a portion of code that would find and display the highest value in the list.
------------------------------------------------------------------------------

The code that I tried to solve is like this :
#include <stdio.h>
#define size 7

void main (void)
{
int list[size]={0};
int i,n,sum;
printf("enter numbers:");
scanf("%d\t",&n);
for(i=n;i<=size;i++)
{
list[size]=n;
printf("%d\n",list[size]=n);
}
}

what do you want to do..???
here user has to enter number (n) which should be <=7, because this loop will run upto i=7 as u earlier declare size =7.
and every time u r putting value at the same index , list[size] i.e list[7]

for(i=n;i<=size;i++)
{
list[size]=n;
printf("%d\n",list[size]=n);
}
Last edited on
so, my code is not correct or what
i don understand
lets see what your code is doing?

1
2
3
4
5
6
#include <stdio.h>
#define size 7

void main (void)
{
int list[size]={0};


So far we have an array called list, of 7 ints each set to 0.

int i,n,sum;

Now we declare three more ints. They have no value.

printf("enter numbers:");

This prints to screen.

scanf("%d\t",&n);

Lets say I put in "5". That code now stores 5 in the int n.

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


A loop with i=5, run as long as i <= 7; i ++ with each loop.


list[size]=n;

With each run of the loop, list[7] will equal 5.


printf("%d\n",list[size]=n);

This line is an error, I believe. It tries to print a decimal int, but what int? list[7]=n?
1
2
}
}


I would suggest you put the scanf inside the for loop and asign the input to list[i] but start i at 0.


thanks
Topic archived. No new replies allowed.