programming,
programming knowledge,
programming with mosh,
programming language,
programology,
programs,
programmer,
programming fundamentals,
program song,
program dance,
program khabardar,
program video,
program breaking point with malick,
program mazaaq raat,
program pukar,
program khabar naak,
program aaj shahzeb khanzada ke saath,
program aik din geo ke saath,
program aitraaz hai,
program aftab iqbal,
program agenda pakistan with amir zia,
program asif,
program asaib zada,
program aaj kamra
23 : Write a C program that read 5 numbers and counts the number of positive numbers and print the average of all positive values.
Write a C program that read 5 numbers and counts the number of positive numbers and print the average of all positive values. Test Data : Input the first number: 5 Input the second number: 8 Input the third number: 10 Input the fourth number: -5 Input the fifth number: 25 Expected Output: Number of positive numbers: 4 Average value of the said positive numbers: 12.00
#include <stdio.h>int main() {
float numbers[5],total=0, avg;int j, pctr=0;
printf("\nInput the first number: ");
scanf("%f",&numbers[0]);
printf("\nInput the second number: ");
scanf("%f",&numbers[1]);
printf("\nInput the third number: ");
scanf("%f",&numbers[2]);
printf("\nInput the fourth number: ");
scanf("%f",&numbers[3]);
printf("\nInput the fifth number: ");
scanf("%f",&numbers[4]);for(j =0; j <5; j++) {
if(numbers[j]>0)
{
pctr++;
total += numbers[j];
}
}
avg = total/pctr;
printf("\nNumber of positive numbers: %d", pctr);
printf("\nAverage value of the said positive numbers: %.2f", avg);
printf("\n");return0;
}
Comments
Post a Comment
PLEASE DO NOT ENTER THE SPAM LINK IN THE COMMENT BOX