Input
The input file contains many floating-point numbers, positive or negative. The program execution will be finished after the input of two valid scores.
Output
When an invalid score is read, you should print the message "nota invalida".
After the input of two valid scores, the message "media = " must be printed followed by the average of the student. The average must be printed with 2 numbers after the decimal point.
After the input of two valid scores, the message "media = " must be printed followed by the average of the student. The average must be printed with 2 numbers after the decimal point.
Input Sample | Output Sample |
-3.5
3.5 11.0 10.0 |
nota invalida
nota invalida media = 6.75 |
Solution using C :
#include <stdio.h>
int main() {
float n,s=0;
int v=0;
while(v<2)
{
scanf("%f",&n);
if(n>= 0 && n <= 10)
{
s += n;
v++;
}
else
printf("nota invalida\n");
}
printf("media = %.2f\n",s/2);
return 0;
}
Comments
Post a Comment