Advertisement
gpsgiraldi

2024_listaC_mediaponderada

Apr 20th, 2024 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | Source Code | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     float v1,v2,v3,v4,aux;
  6.     printf("Insira quatro valores reais positivos: ");
  7.     scanf("%f %f %f %f", &v1,&v2,&v3,&v4);
  8.     if(v1<0 ){
  9.         printf("Reinicie o programa e insira valores adequados! ");
  10.         return 0;
  11.     }
  12.     else{
  13.         if(v1<0||v2<0||v3<0||v4<0){
  14.             printf("Reinicie o programa e insira valores adequados! ");
  15.             return 0;
  16.         }
  17.         else{
  18.             aux = (v1+(2*v2)+(3*v3)+(4*v4))/(1+2+3+4);
  19.             printf("Os valores inseridos foram %.2f %.2f %.2f e %.2f. \n", v1,v2,v3,v4);
  20.             printf("A media ponderada destes valores equivale a %.2f.", aux);
  21.         }
  22.     }
  23.     return 0;
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement