0% found this document useful (0 votes)
49 views6 pages

FLOW and ALGO 9&12

The document describes algorithms to: 1) Compute the sine of a value (in degrees) using a Taylor series approximation up to a specified number of terms, and compare the result to using the built-in math library function; 2) Find the square root of a number without using the sqrt() library function, by iteratively calculating estimates using the formula (x^2 + n) / (2x) until convergence. Both algorithms print the results of the custom calculation and library function for comparison.

Uploaded by

Radhika Ajadka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views6 pages

FLOW and ALGO 9&12

The document describes algorithms to: 1) Compute the sine of a value (in degrees) using a Taylor series approximation up to a specified number of terms, and compare the result to using the built-in math library function; 2) Find the square root of a number without using the sqrt() library function, by iteratively calculating estimates using the formula (x^2 + n) / (2x) until convergence. Both algorithms print the results of the custom calculation and library function for comparison.

Uploaded by

Radhika Ajadka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

9.

Develop a Program to compute Sin(x) using Taylor series


approximation. Compare your result with the built- in Library
function. Print both the results with appropriate messages.

Algorithm:

Step 1: [Start]
Begin
Step 2: [Read the value of degrees]
Read degree
Step 3: [Read the number of terms in the series]
Read n
Step 3: [Initialization & Radians conversion] Temp=x
x=degree*(3.142/180.0)
term=x
sum=term

Step 4: [compute sin value]]


for i=3 through n by steps 2
term= -term*x*x / ((i-1)*i)
sum=sum+term
Step 5: [Print the output]
print degree and the sum
print sin(x)= without using library function , print degree and
sum
print sin(x)= using library function
Step 6: [Stop] End
Program:

#include<stdio.h>
#include<math.h>
void main()
{
int i,n;
float degree,x,term,sum;
printf("Enter the value in degree's : ");
scanf("%f",&degree);
printf("Enter number of terms in the series : ");
scanf("%d",&n);
x=degree*3.142/180;
term=x;
sum=term;
for(i=3;i<=n;i=i+2)
{
term=-term*x*x/((i-1)*i);
sum=sum+term;
}
printf("MYSIN(%g)=%f \n",degree,sum);
printf("Using built-in librabry function, SIN(%g)=%f \n",degree,sin(x));
}
12. Develop a program to find the square root of a given number N
and execute for all possible inputs with appropriate messages. Note:
Don’t use library function sqrt(n).

Algorithm:

Step 1: [Start]
Begin
Step 2: [Input an integer n] Read n
Step 3: [check if the number is positive]
If n<0
print number is negative
else
calculate the squareroot of n
initialize x=1.0
for i=1 through n/2 in steps 1
root=( (x*x)+n ) / (2*x);
x=root;

Step 4: [print the results]


Print the squareroot of a given number without using
library function
Print the squareroot of a given number using library
function
Step 5: [Stop]
End
Program:

#include<stdio.h>
#include<math.h>
void main()
{
int i;
float n,x,root;
printf("Enter the Number : ");
scanf("%f",&n);
if(n<0)
{
printf("Invalid Input\n");
}
else
{
x=1.0;
for(i=1;i<=30;i++)
{
root=( (x*x)+n ) / (2*x);
x=root;
}
printf("The Square Root of %f is %f \n",n,root);
printf("Using Built-In Library function,Square Root of
%f is %f\n",n,sqrt(n));
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy