This preview shows pages 1–3. Sign up to view the full content.
Hacettepe University
Department Of Computer Engineering
Bil137 Programming Laboratory
Experiment 2
Submission Date : 27.10.2009
Due Date : 10.11.2009
Advisors : Oğuz ASLANTÜRK
R.A. Seda TANKIZ
Programming Language : C
INTRODUCTION
You have learned flow charts, control structures (Ifelse), repetitive structures or loops (while,
for) during course sessions. In order to impact what you learned so far, you are asked to
write a program in C programming language. There are fifteen questions below and you are
supposed to answer just one of them. You can find out which question you are going to
answer in the list at the end of this document. Please pay attention submission and
restriction section of this paper.
OBJECTIVES
Assignment, Increment and Decrement Operators
Arithmetic expressions
Control Structures:
if and if/else
Repetition Structure:
WHILE, FOR
Type casting
QUESTIONS
1.
Calculate the value of π from the infinite series :
π = 4  (4/3) + (4/5)  (4/7) + (4/9)  (4/11) + .
..........
Your program should ask for an iteration value and do the calculation for that number of
iterations. For example :
If iteration = 0 then result is 4
If iteration = 1 then result is 4  (4/3)
If iteration = 2 then result is 4  (4/3) + (4/5)
2.
Write a program that estimates the value of the mathematical constant
e
by using the
formula:
The number of iterations will vary according to the input value. Your program is supposed to
work for any value between 120, so do not forget to include long values.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document3
. A palindrome is a number or a text phrase that reads the same backward as forward. For
example each of the following five digit integers is a palindrome: 12321, 55555, 45554 and
11611. Write a program that prints out all fivedigit palindrome integers. Your program should
also print out the number of 5digit palindrome integers. (Hint: Use the division and
remainder operators to separate the number into its individual digits.)
4.
Write a program, which is going to print the following shape for different inputs:
If the input is 2 then the result is going to be:
If the input is 3 then the result is going to be:
5.
An integer number is said to be a
perfect number
if its factors, including 1 ( but not the
number itself ), sum to the number. For example, 6 is a perfect number because
6 = 1+2+3
Write a program that finds the perfect numbers up to n, input from the keyboard.
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '09
 qwe

Click to edit the document details