C plus plus Program-Introduction to Programming-Assignment, Exercises of Computer Programming

This programming assignment is for Introduction to Programming course. It was assigned by Prof. Abhimoda Arora at Alagappa University. It includes: Program, Calculate, Mathematical, Constant, Pi, Circle, Quadrants, Radius, Area, Random, Number

Typology: Exercises

2011/2012

Uploaded on 07/31/2012

dhairya
dhairya 🇮🇳

5

(4)

32 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Qno1 Write a C++ program to calculate the mathematical constant of
PI:
(a) Imagine a circle, whose area is given by: Area=PI*R^2
(b) Now imagine that you divide the circle exactly into 4 quadrants.
(c) The area of one quadrant is hence: Area=0.25*PI*R^2
(d) Now let us set the radius to be R=1;
(e) The equation hence becomes: Area=0.25*PI
(f) So we can simply say: PI = Area*4
Now the big question is how do you calculate the area of the gray shaded
quadrant of the circle above? Use a random number generator and guess
effectively the correct answer. (Hint: use rand() from <cstdlib> and make
sure that you divide through by RAND_MAX.)
The technique you should use is to:
- guess a random number between 0.00 and 1.00 and assign this to x.
- guess a random number between 0.00 and 1.00 and assign this to y.
- find out if this (x,y) coordinate lies inside the gray shaded quadrant or
outside. Hint: sqrt(x^2 + y^2 ).
- Repeat these steps N times, where N is sufficiently big and then find the
ratio of points inside the circle divided by the total number N, to determine
the area of the gray shaded area.
- Apply this to your equation to find the mathematical constant PI.
-
docsity.com
pf2

Partial preview of the text

Download C plus plus Program-Introduction to Programming-Assignment and more Exercises Computer Programming in PDF only on Docsity!

Qno1 Write a C++ program to calculate the mathematical constant of PI: (a) Imagine a circle, whose area is given by: Area=PIR^ (b) Now imagine that you divide the circle exactly into 4 quadrants. (c) The area of one quadrant is hence: Area=0.25PIR^ (d) Now let us set the radius to be R=1; (e) The equation hence becomes: Area=0.25PI (f) So we can simply say: PI = Area* Now the big question is how do you calculate the area of the gray shaded quadrant of the circle above? Use a random number generator and guess effectively the correct answer. (Hint: use rand() from and make sure that you divide through by RAND_MAX.) The technique you should use is to:

  • guess a random number between 0.00 and 1.00 and assign this to x.
  • guess a random number between 0.00 and 1.00 and assign this to y.
  • find out if this (x,y) coordinate lies inside the gray shaded quadrant or outside. Hint: sqrt(x^2 + y^2 ).
  • Repeat these steps N times, where N is sufficiently big and then find the ratio of points inside the circle divided by the total number N, to determine the area of the gray shaded area. - Apply this to your equation to find the mathematical constant PI.

docsity.com

Q no 2 Write a program which will print all the pairs of prime numbers whose sum equals the number entered by the user. Store these prime numbers and randomly select any prime number from that array Q no 3 An integer number is said to be perfect number if its factors including 1 (but not the number itself) sum to the number. For example, 6 is a perfect number because 1+2+3=6. Write a function perfect that determines if parameter number is a perfect number, and returns a boolean value true if number is perfect other wise returns false. Use this function in a program that prints perfect numbers between 1 and 1000. Store these perfect numbers in an array

docsity.com