AedenCak3

SP. question 2 (series 1/2-2/3+3/4...n)

Dec 2nd, 2021
976
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. include<stdio.h>
  2.  
  3. int main()
  4.  {
  5.  
  6. int n,i;
  7.  
  8. float sum=0;
  9.  
  10. printf("Enter the  values of n: ");
  11.  
  12. scanf("%d",&n);
  13.  
  14.  
  15. for (i =1;i<=n;i++)
  16.     {
  17.         if(i%2!=0)
  18.  
  19.   sum=sum+(float)i/(i+1);
  20.     else
  21.     sum=sum-(float)i/(i+1);
  22.  
  23.  
  24.  
  25. }
  26.  
  27.  
  28. printf("sum= %.3f ",sum);
  29.  
  30.  
  31.  
  32. return 0;
  33.  
  34. }
RAW Paste Data