Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

There is a famous story about a primary school teacher who wanted to occupy his

ID: 3676447 • Letter: T

Question

There is a famous story about a primary school teacher who wanted to occupy his students' time by making the children compute the sum of 1 + 2 + 3 + ... + 100 by hand. As the story goes, the teacher was astounded when one of the children immediately produced the correct answer: 5050. The student, a child prodigy, was Carl Gauss, who grew up to be one of the most famous mathematicians of the eighteenth century. Repeat Gauss's remarkable calculation by writing a program with a loop that will compute and print the above sum. After you have the program working, rewrite it so you can compute 1 + 2 + ... + n where n is any positive integer. Perhaps the first algorithm used for approximating the square root of S is known as the "Babylonian method", named after the Babylonians, or "Heron's method", named after the first-century Greek mathematician Heron of Alexandria who gave the first explicit description of the method. It can be derived from (but predates by 16 centuries) Newton's method. The basic idea is that if x is an overestimate to the square root of a non-negative real number S then S/x will be an underestimate and so the average of these two numbers may reasonably be expected to provide a better approximation. More precisely, assuming S is a positive number: Make a guess at the answer (you can pick S/2 as your initial guess). Compute r = S / guess. Set new guess = (guess + r) / 2 Go back to step 2 until the last two guess values are within 1% of each other^1. Write a program that: Inputs the value of S from the user. Uses the Babylonian Algorithm to determine and output the square root of n.

Explanation / Answer

14.1 Source Code for sum of n numbers:

(C program)

#include<stdio.h>
void main()
{
int i, t=0 , n;

printf("Enter some n value to find sum: ");
scanf(" %d ", &n);
for( i=1 ; i<=n ; i++)
{
t = t+i;
}
printf("Sum of %d numbers is %d",n,t);

}

output:

Enter some n value to find sum: 10

Sum of 10 numbers is 55

14.2 Source Code for Babylonian algorithm:

(C program)

#include<stdio.h>

void main()

{

float g,x;

int s;

printf("Enter number whose root is to be finded: ");

scanf("%d",&s);

g=s/2;

while(1)

{

if((g*g-s)>1)

{

x=s/g;

g=(g+x)/2;

}

else

break;

}

printf("%f",g);

}

output:

Enter number whose root is to be finded: 24

4.908513

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote