Computer Science, asked by tweenkie912, 9 months ago

Develop the pseudo code for, desk check and test the following programs. Allow the user to provide the number of elements, and initialise the array according to their input. Use functions where appropriate to ensure modularity.
1. Find the average of a list of numbers
2. Find the smallest element in a list of numbers

Answers

Answered by Anonymous
0

Answer:

To find the average from a list of numbers:

1. int main()

{  

int numelement, i;

   float sum = 0, list[100];

   printf("Enter number of elements:  ");

   scanf("%d", &numelement);

   printf("\n\n\nEnter %d elements\n\n", numelement);

   for(i = 0; i < numelement; i++)

   {

       scanf("%f", &list[i]);

       sum = sum + list[i];

   }

   printf("\n\n\nAverage of the entered numbers is =  %f", (sum/numelement));

   return 0;

}

2.

 int main() {

 int numelement, i, smallest;

   float list[100];

 

   printf("Enter number of elements:  ");

   scanf("%d", &numelement);

  printf("\n\n\nEnter %d elements\n\n", numelement);

   for(i = 0; i < numelement; i++)

   {

       scanf("%f", &list[i]);

}

  smallest = list[0];

 

  for(i = 0; i < numelement; i++)

{

     if (list[i] < smallest) {

        smallest = list[i];

     }

  }

 

  printf("\nSmallest Element : %d", smallest);

 

  return (0);

}

Similar questions