Programming Practicum Template Assignment 2: Summing Fractions. Demonstrate a fl
ID: 3743910 • Letter: P
Question
Programming Practicum Template Assignment 2: Summing Fractions. Demonstrate a floating point round off error. This can be done with a print statement or any more complicated code. What we demonstrated in class is to add 1 + ½ + …+1/6 and compare this to adding 1/6 + … + ½ +1. Name: Date: (5 points) Introduction: Describe your code in a single sentance (5 points) Code: Please copy and paste your code here (5 points) Output: Please copy and paste the results from your code here (5 points) Verification: Please tell me why you believe your code and output are correct (5 points) Summary: Please tell me what you learned and how you will use this in the future Programming Practicum Template Assignment 2: Summing Fractions. Demonstrate a floating point round off error. This can be done with a print statement or any more complicated code. What we demonstrated in class is to add 1 + ½ + …+1/6 and compare this to adding 1/6 + … + ½ +1. Name: Date: (5 points) Introduction: Describe your code in a single sentance (5 points) Code: Please copy and paste your code here (5 points) Output: Please copy and paste the results from your code here (5 points) Verification: Please tell me why you believe your code and output are correct (5 points) Summary: Please tell me what you learned and how you will use this in the future Programming Practicum Template Assignment 2: Summing Fractions. Demonstrate a floating point round off error. This can be done with a print statement or any more complicated code. What we demonstrated in class is to add 1 + ½ + …+1/6 and compare this to adding 1/6 + … + ½ +1. Name: Date: (5 points) Introduction: Describe your code in a single sentance (5 points) Code: Please copy and paste your code here (5 points) Output: Please copy and paste the results from your code here (5 points) Verification: Please tell me why you believe your code and output are correct (5 points) Summary: Please tell me what you learned and how you will use this in the futureExplanation / Answer
Introduction :
(int) operation (int) always gives int.
Example :
int x=1/2; or float y=1/2;
x=(int)0.5; y=(int)0.5; //result is getting converted into int
x=0; y=0; //0 is integer from 0.5
Code:
/* C Language used */
#include <stdio.h>
int main()
{
float x=1+1/2+1/3+1/4+1/5+1/6;
float y=1/6+1/5+1/4+1/3+1/2+1;
printf("%f %f",x,y);
return 0;
}
/* Code ends here */
Output:
1.000000
1.000000
Verification:
Statement 1: float = int + (int/int) + (int/int) + .. + (int/int) ;
x = 1 + 1/2 + 1/3 + .. + 1/6 ;
x = 1 + 0 + 0 + .. + 0 ;
x = 1; //assignment
Statement 2: float = (int/int) + (int/int) + .. + (int/int) + int ;
x = 1/2 + 1/3 + .. + 1/6 + 1 ;
x = 0 + 0 + .. + 0 + 1 ;
x = 1; //assignment
Summary :
Output is getting verified as (int) operation (int) gives int
Npte: For queries drop comment
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.