Mary_99

ex4.2

Dec 4th, 2018
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  5.  
  6. int Wn(int n)
  7. {
  8.  int value;
  9.  
  10.  if(n%2==0)     //for even
  11.  {
  12.       value = (0.5*n + pow(n,2));
  13.     }
  14.   else
  15.  {
  16.     value=(n-5)*n;    //for odd
  17.   }
  18.  
  19.   return value;
  20. }
  21.  
  22. int main(int argc, char *argv[]) {
  23. int n;
  24. int a;
  25. int b;
  26. int c=0;
  27. float results[100];
  28.  
  29.  
  30. printf("a=");
  31. scanf("%f",&a);
  32. printf("b=");
  33. scanf("%f", &b);
  34.  
  35. for(n=a; n<=b; n++)
  36. {
  37.  results[c]= Wn(n);
  38.  c++;
  39. }
  40.  
  41. for(n=0; n<c; n++, a++)
  42. {
  43.   printf("\t\t\t\t\t\tV(%d) = %.2f\n", a, results[n]);
  44. }
  45.  
  46. //float value(n);
  47.  
  48.  
  49.  
  50.  printf("results");
  51.  
  52.  return 0;
  53. }
Add Comment
Please, Sign In to add comment