Programming in C 22226 2018-19
Important Questions
Unit I: Program Logic Development
1. Define Algorithm.
Ans: Algorithm:- Algorithm is a stepwise set of instructions written to perform a specific task.
2. Draw and label symbols used in flow chart.
Ans:
3. Write an algorithm to determine whether a given number is divisible by 5 or not.
Ans:
Step 1- Start
Step 2- Read / input the number.
Step 3- if n%5==0 then goto step 5.
Step 4- else number is not divisible by 5 goto step 6.
Step 5- display the output number is divisible by 5.
Step 6- Stop
1
Programming in C 22226 2018-19
4. Write algorithm and draw flow-chart to print even numbers from 1 to 100.
Ans:
Algorithm
1. Start
2. Initialize the variable i to 1.
3. while i<=100
4. if i%2==0 then
5. print the number
6. increment value of i
7. stop
2
Programming in C 22226 2018-19
5. State the use of following symbols used for flowchart drawing:
6. Write an algorithm for checking whether given number is prime or not.
Ans:
Step 1: Start
Step 2: Declare variables n,i,flag.
Step 3: Initialize variables
flag←1
i←2
Step 4: Read n from user.
Step 5: Repeat the steps until i<(n/2)
5.1 If remainder of n÷i equals 0 then
flag←0
Go to step 6
5.2 i←i+1
Step 6: If flag=0 then
Display n is not prime
else
Display n is prime
Step 7: Stop
3
Programming in C 22226 2018-19
7. Write an algorithm to find the factorial of a number entered by user.
Ans:
Step 1: Start
Step 2: Declare variables n,factorial and i.
Step 3: Initialize variables
factorial←1
i←1
Step 4: Read value of n
Step 5: Repeat the steps until i=n
5.1: factorial←factorial*i
5.2: i←i+1
Step 6: Display factorial
Step 7: Stop
8. Write an algorithm to find the Fibonacci series till term≤1000.
Ans:
Step 1: Start
Step 2: Declare variables first_term,second_term and temp.
Step 3: Initialize variables first_term←0 second_term←1
Step 4: Display first_term and second_term
Step 5: Repeat the steps until second_term≤1000
5.1: temp←second_term
5.2: second_term←second_term+first term
5.3: first_term←temp
5.4: Display second_term
Step 6: Stop
9. Write an algorithm to find the largest among three different numbers entered by user.
Ans:
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a>b then
If a>c then
Display a is the largest number.
Else
Display c is the largest number.
Else
If b>c then
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop
4
Programming in C 22226 2018-19
10. Write an algorithm to find all roots of a quadratic equation ax2+bx+c=0.
Ans:
Step 1: Start
Step 2: Declare variables a, b, c, D, x1, x2, rp and ip;
Step 3: Calculate discriminant
D←b2-4ac
Step 4: If D≥0 then
r1←(-b+√D)/2a
r2←(-b-√D)/2a
Display r1 and r2 as roots.
Else
Calculate real part and imaginary part
rp←b/2a
ip←√(-D)/2a
Display rp+j(ip) and rp-j(ip) as roots
Step 5: Stop
11. Write an algorithm to find area and circumference of a circle.
Ans: _________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
5
Programming in C 22226 2018-19
12. Write an algorithm to find area of a triangle.
Ans: ______________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
6
Programming in C 22226 2018-19
13. Draw flowchart for checking whether given number is prime or not.
7
Programming in C 22226 2018-19
14. Draw flowchart to find the factorial of a number entered by user.
8
Programming in C 22226 2018-19
15. Draw flowchart to find the largest among three different numbers entered by user.
9
Programming in C 22226 2018-19
16. Draw flowchart to find area and circumference of a circle.
10
Programming in C 22226 2018-19
17. Draw flowchart to find area of a triangle.
11