Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Paragraph Styles Laboratory Tasks l rite a C program that prompts for and reads

ID: 3824336 • Letter: P

Question

Paragraph Styles Laboratory Tasks l rite a C program that prompts for and reads 10 numbers (of type double) from the user into a double array of size 10, it then: calculates the sum and average of positive numbers of the array and displays them. ote: consider 0 as positive] Displays the array indexes where positive numbers appear in the array. Note: The program must display the message: "There are no positive values" if the array does not contain any positive value. Sample program runs value 2 value Inter value 6 3

Explanation / Answer

#include<stdio.h>
int main()
{
int a[10],n=10,i,sum=0,count=0;
float avg;
printf("Elements are: ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]>0){
sum=sum+a[i];
   count++;
}
}
avg = sum/count;
printf("Sum of the positive numbers%d ",sum);
printf("Average of positive numbers%.2f ",avg);
printf("Indexes of positive elements are:");
for (i=0;i<n;i++){
if (a[i]>0){
printf("%d ",i);
}
}
return 0;
}