C++ Programs

Only available on StudyMode
  • Download(s) : 40
  • Published : January 12, 2013
Open Document
Text Preview
EC101A: Computer Systems and Programming
Spring Semester: 2010-2011
January 20, 2011

1. Write a program program in C++ to find the square of the numbers from 1 to 10 using : (a) for loop (b) while loop(c) do-while loop
The output of the program should be in the following format: NumberSquare

2. Write a program in C++ that calculates the value of π from the infinite series [pic]
Print a table that shows the value of π approximately by 1 term of the series, by two terms, by three terms, etc. How many terms of this series do you have to use before you first get 3.14? 3.141? 3.1415?3.14159?

3. Write a program in C++ to find the sum of the first 20 terms of the following series sum = 1 – (1/1!) + (2/2!) – (3/3!) + (4/4!) …………. (n/n!)

4. Write a program in C++ that prints the factorial of the given number using : (a) for loop (b) while loop(c) do-while loop
Make sure that the program correctly handles the exceptions such as the value of factorial zero and the value of factorial of a negative number.

5. Write a C++ program that checks whether a number entered by the user is a perfect number or not. (Note: A perfect number is the one whose all the divisors sum up the number itself. For example, number 28 is a perfect number as 1+2+4+7+14=28).

6. Write a program in C++ to read a set of 10 positive integers and display them all. If the number entered is zero, the program continues reading, but when the user input is a negative number, the program stops reading any further input and displays a message: “a negative number entered”.

7. Write a program that reads three non-zero double values and determines and prints whether they could represent sides of a triangle. 8. Write a program to evaluate the quadratic polynomial a x2 + bx + c for a given set of...
tracking img