Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

PROGRAM SHOWING ROUND-OFF ERRORS IN FLOATING POINT COMPUTATIONS

Posted By: Victoria Hughes     Category: C Programming     Views: 3113

WRITE A PROGRAM SHOWING ROUND-OFF ERRORS IN FLOATING POINT COMPUTATIONS.

Code for PROGRAM SHOWING ROUND-OFF ERRORS IN FLOATING POINT COMPUTATIONS in C Programming

/*------------------- Sum of n terms of 1/n -------------------*/
main() { float sum, n, term ; int count = 1 ; sum = 0 ; printf("Enter value of n\n") ; scanf("%f", &n) ; term = 1.0/n ; while( count <= n ) { sum = sum + term ; count++ ; } printf("Sum = %f\n", sum) ; } Output Enter value of n 99 Sum = 1.000001 Enter value of n 143 Sum = 0.999999
  
Share: 



Victoria Hughes
Victoria Hughes author of PROGRAM SHOWING ROUND-OFF ERRORS IN FLOATING POINT COMPUTATIONS is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!