Determining the volume of the unit sphere

Assignment Help C/C++ Programming
Reference no: EM13703790

You need to implement a program to find the volume of the unit sphere.

Program: Write a C program for determining the volume of the unit sphere by the Monte Carlo Method      \(x^{2}+ y^{2} + z^{2} <1,     x > 0, y > 0, z > 0.\)    : This is what I have so far, but it's not working.

#include <stdio.h>#include <math.h>#include <stdlib.h>#include <time.h>int main() {float x, y, z;int n, i, count=0;float volume=(4/3);srand(time(NULL));for (i=0; i< n; i++) {x=1.0*rand()/RAND_MAX;y=1.0*rand()/RAND_MAX;z=1.0*rand()/RAND_MAX;if (pow(x,2) + pow(y,2)+ pow(z,2) < 1.0) count=count+1;}printf("True value = %f\n", volume*3.1415);printf("Appx value = %f\n", 1.0*count/n);return 0;

You need to make well-formed and clean code. You should not copy and paste the code from other source.

 

Reference no: EM13703790

Questions Cloud

What is the output of the statement : Given the subsequent array declaration, if the array is stored starting at address 2500, what is the output of the following statement?
Can firm increase variability of its product line : Can a firm increase the variability and diversity of its product line while simultaneous realizing the higher possible level of efficiency? Provide one product example for illustration.
Babylonian algorithm : Babylonian Algorithm. The Babylonian algorithm to compute the square root of a positive number n is as given:
Write a program that request a students name : Write a program that request a student's name in the subsequent form: lastName,firstName.
Determining the volume of the unit sphere : Write a C program for determining the volume of the unit sphere by the Monte Carlo Method      \(x^{2}+ y^{2} + z^{2} 0, y > 0, z > 0.\)    : This is what I have so far, but it's not working.
How will cyber security influence the next 10 years : How will cyber security influence the next 10 years?
Prepare a main function : Write a function that converts an input of some integer number of nickels into outputs of integer numbers of dollars, quarters, and nickels.
Canonical product of sums : Design a majority circuit. This is a circuit which produces a 1 anytime there are more 1's than 0's on the inputs. Your circuit should have 3 inputs.
What is wrong with this function : What is wrong with this function? Can you find problem in this code?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  What does the following display

Given the subsequent array definition: double rainfall[] = {1.4, 1.2, 3.4, 1.8, 1.6}; what does the following display?

  Develop a two dimensional interactive game

The player starts as a disk, but can "morph" (that is expand and contract) in selected directions

  Write c program which has parent process and child process

Write a C program that has a parent process, a child process, and a grandchild process. The parent process should print its id and the square or 5.

  1 what is the output of the following c programsnbspinclude

1. what is the output of the following c programs?nbspinclude ltiostreamgtusing namespace stdint mainnbspnbspnbsp cout

  Design a nested program

How many levels of nesting are there in this design?

  Program to find the factors of an integer

Write a C++ program to find the factors of an integer (entered by the user) which are themselves squares.

  Properly store the number from variable value

1. Statement will properly store the number from variable  value  into the output file object AnsFile?

  Model-view-controller

Explain Model-View-Controller paradigm

  Write an entire c++ program that reads a positive integer

Write an entire C++ program that reads a positive integer entered by an interactive user and then prints out all the positive divisors of that integer in a column and in decreasing order.

  To use a sentinel loop so once the value of -99 i

modify this program to use a sentinal loop so once the value of -99 is entered after getting the pay and hours the program should end.

  Loops and if conditions

Write a program that requests a password

  Write a class with the following static methods

Wordcount: This method should accept a reference to a String object as an argument and return the number of words contained in the object.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd