Not sure how to do these Ubunto problems. Someone please help Compose a program
ID: 3810729 • Letter: N
Question
Not sure how to do these Ubunto problems. Someone please help
Compose a program that writes the coordinates of a random point (a, b, c) on the surface of a sphere. To generate such a point, use Marsaglia's method: Start by picking a random point (x, y) in the unit disk using the method described at the end of this section. Then, set a to 2 x squareroot (1 - x^2 - y^2), b to 2 squareroot (1 - x^2 -y^2), and c to 1 - 2 (x^2 + y^2). Exponential function. Assume that x is a float. Compose a program that uses the Taylor series expansion to assign e^x = 1 + x + x^2/2! + x^3/3! + ... to total.Explanation / Answer
#include<stdio.h>
#include<conio.h>
#include<math.h>
long int factorial(int n);
int main()
{
int x,i;
float s,r;
char c;
printf("You have this series:-1+x/1! + x^2/2! + x^3/3! + x^4/4!..x^x/x!");
printf("To which term you want its sum of ? ");
scanf("%d",&x);
s=0;
for (i=1;i<=x;i++)
{ s=s+((float)pow(x,i)/(float)factorial(i));
}
printf("The sum of %d terms is %f",x,1+s);
fflush(stdin);
getch();
}
long int factorial(int n)
{
if (n<=1)
return(1);
else
n=n*factorial(n-1);
return(n)
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.