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

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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