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
2
Answer:
1. int main()
{
int elementno, i;
float sum = 0, number[100];
printf("Enter number of elements: ");
scanf("%d", &elementno);
printf("\n\n\nEnter %d elements\n\n", elementno);
for(i = 0; i < elementno; i++)
{ scanf("%f", &number[i]);
sum = sum + number[i];
}
printf("\n\n\nAverage of the entered numbers is = %f", (sum/elementno));
return 0;
}
2.
int main() {
int elementno, i, smallest;
float number[100];
printf("Enter number of elements: ");
scanf("%d", &elementno);
printf("\n\n\nEnter %d elements\n\n", elementno);
for(i = 0; i < elementno; i++)
{
scanf("%f", &number[i]);
}
smallest = number[0];
for(i = 0; i < elementno; i++)
{
if (number[i] < smallest) {
smallest = number[i];
}
}
printf("\nSmallest Element : %d", smallest);
return (0);
}
Similar questions
English,
6 months ago
Environmental Sciences,
6 months ago
Business Studies,
6 months ago
Physics,
1 year ago
English,
1 year ago
Science,
1 year ago