Preview

C++ Programs

Good Essays
Open Document
Open Document
716 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
C++ Programs
INDIAN INSTITUTE OF TECHNOLOGY ROORKEE 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: Number Square ……… ………

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

You May Also Find These Documents Helpful

  • Satisfactory Essays

    = z) return true; else return false; } Problem 5 a. Output: 720 b. Output: 0 c. Output: 71 d. Output: 362880 Problem 6 a. Output: “Take Programming I.” b. Output:…

    • 188 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    cout << "You are in factorial program of C++. Please enter a +ve integer:- ";…

    • 426 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Week 1 Lab_ CIS_115

    • 439 Words
    • 2 Pages

    Describe your solution using pseudocode. Use the same valid variable names you selected in Step 1.…

    • 439 Words
    • 2 Pages
    Good Essays
  • Good Essays

    It/210 Final Exam

    • 1235 Words
    • 5 Pages

    5. The program will allow the user to clear all the input fields and do the calculations over.…

    • 1235 Words
    • 5 Pages
    Good Essays
  • Good Essays

    Nt1310 Unit 3 Quiz

    • 6337 Words
    • 26 Pages

    /*question number 1*/ Code: int z,x=5,y=-10,a=4,b=2; z = x++ - --y * b / a; What number will z in the sample code above contain? Choice 1 5 Choice 2 6 Choice 3…

    • 6337 Words
    • 26 Pages
    Good Essays
  • Satisfactory Essays

    unit 7 assignment 1

    • 431 Words
    • 2 Pages

    7. Convert the While loop in the following code to a Do-While loop: int x;…

    • 431 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Pt1420 Unit 7 Study Guide

    • 582 Words
    • 3 Pages

    21. Write a program that prompts the user to enter two unsigned numbers 0 to FFFFh and their sum in hex on the next line.…

    • 582 Words
    • 3 Pages
    Satisfactory Essays
  • Better Essays

    Nt1310 Unit 1 Assignment

    • 1994 Words
    • 8 Pages

    * The binary numbering system plays a central role in how information of all kinds is stored on the computer. Understanding binary can lift a lot of the mysteries from computers because at a fundamental level they're really just machines for flipping binary digits on and off. There are several activities on binary numbers in this document, all simple enough that they can be used to teach the binary system to anyone who can count! Generally children learn the binary system very quickly using this approach, but we find that many adults are also excited when they finally understand what bits…

    • 1994 Words
    • 8 Pages
    Better Essays
  • Good Essays

    4) 10 + 11 + 12 + 13 + 14 + 15 + 16 = 27 + 64…

    • 825 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    It210 Appendix F

    • 372 Words
    • 3 Pages

    5. The program will allow the user to clear all the input fields and do the calculations over.…

    • 372 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    unit 8 homework

    • 793 Words
    • 5 Pages

    The advantage of using a sentinel is that when you are processing a long list of values with a loop a sentinel marks the end of a list of items.…

    • 793 Words
    • 5 Pages
    Good Essays
  • Good Essays

    c. Modify the program of Part b so that at the option of the user, it displays…

    • 300 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    UNIT 2

    • 470 Words
    • 3 Pages

    5.) Write the pseudocode for a program that will determine the average miles per gallon a car gets. (Inputs should be miles driven and gallons of gas used)…

    • 470 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    code program

    • 317 Words
    • 2 Pages

    (Input screenshot) - Insert here a screenshot of your program running showing entry of the provided set of test input data for this assignment:…

    • 317 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Lab 3 Student

    • 1264 Words
    • 7 Pages

    Step 1: This program is most easily solved using just a few variables. Identify potential problems with the following variables declared in the pseudocode. Assume that the college has the ability to offer half credits. (Reference: Variable Names, page 39-40).…

    • 1264 Words
    • 7 Pages
    Satisfactory Essays