Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5.  
  6. using namespace std;
  7.  
  8. float ErroAbsoluto(float vP, float vM){
  9. return fabs(vP - vM);
  10.  
  11. }
  12.  
  13. float ErroRelativo(float vP, float vM){
  14. float erroR;
  15. erroR = (ErroAbsoluto(vP, vM)/vP) * 100;
  16. return erroR;
  17.  
  18. }
  19.  
  20. int main()
  21. {
  22. float x, y;
  23. float ErroAbs[3], ErroRel[3];
  24.  
  25. for(int i = 0; i < 3; i++){
  26. printf("\nDigite o valor real: ");
  27. scanf("%f", &x);
  28.  
  29. printf("Digite o valor aproximado: ");
  30. scanf("%f", &y);
  31.  
  32. ErroAbs[i] = ErroAbsoluto(x, y);
  33. ErroRel[i] = ErroRelativo(x, y);
  34. }
  35.  
  36. for(int i = 0; i < 3; i++){
  37. printf("\nO erro absoluto e: %.2f", ErroAbs[i]);
  38. printf("\nO erro relativo e: %.2f%%\n\n", ErroRel[i]);
  39. }
  40.  
  41. system("pause");
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement