[go: up one dir, main page]

0% found this document useful (0 votes)
6 views16 pages

C++ 2

The document outlines a group assignment for a computer programming course at Debre Birhan University, detailing algorithms and flowcharts for various tasks such as calculating averages, finding the largest number, displaying odd numbers, swapping variables, calculating factorials, summing even numbers, and solving quadratic equations. Each task includes a step-by-step algorithm description and a corresponding flowchart. The assignment is intended for a group of students, with names and IDs listed.

Uploaded by

temu12211221
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views16 pages

C++ 2

The document outlines a group assignment for a computer programming course at Debre Birhan University, detailing algorithms and flowcharts for various tasks such as calculating averages, finding the largest number, displaying odd numbers, swapping variables, calculating factorials, summing even numbers, and solving quadratic equations. Each task includes a step-by-step algorithm description and a corresponding flowchart. The assignment is intended for a group of students, with names and IDs listed.

Uploaded by

temu12211221
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

DEBRE BIRHAN UNIVERSITY

College of Natural and computational sciences

Course name: Computer programing


Course Code: ECEg 2052
Group Assignment
Group 3

Name ID
1, Dagim Biruk ………………………………….. 1700546
2, Dagmawi Dawit……………………………… 1700548
3, Ayele Seyife ……………………………………. 1700391
4, Bemirew
5,
6,
7,
8,
9,
10,
1. Write an algorithm description and draw a flow chart to calculate the
average of 4 integer numbers.

Algorithm
Step 1: start
Step 2: read a, b, c, d
Step 3: sum= a + b +c + d
Step 4: A = sum/4
Step 5: print A
Step 6: stop Flow chart

start

Input a, b,
c, d

Sum=a + b + c + d

A=sum/4

Print A

Stop
2, write an algorithm description and a flow chart to find the
largest value of any three numbers.

Algorithm
Step 1: start
Step 2: read a,b,c
Step 3: compare a and b
 If a>b, then compare a with c:
If a>c, then a is the largest
Else c is the largest
 Else (when b>a ), compare b with c:
If b>c, then b is the largest
Else , c is the largest
Step 4: return the identefid the largest value
Step 5: stop
Flow chart

start

read : a ,b, c

Yes No
Is a>b ?

Yes No No Is b>c
Is a>c ?
? ????? Yes

Print a Print c Print b

stop
3, Write an algorithm description and draw a flow chart which gats
a natural numbers N and display odd number equal or less than N.
Algorithm
Step 1: Start
Step 2: Input the value of N
Step 3: initialize i=1
Step 4: if (i<=N) then
 Go to the next step
o Else: go to step 8
Step 5: if (i % 2=1) then
 Print “i”
o Else go to the next step
Step 6: compute i=i+1
Step 7: go to step 4
step 8: stop
Flow chart

start

Input N

Initialize i=1

NO

stop If i<=N

Yes

Print i yes If i%2=1

No

i=i+1
4, write an algorithm description and draw a flow chart to swap the
content of two variable using third variables .
Algorithm
Step 1: Start
Step 2: Input Two Numbers Say x, y and third variable t
Step 3: Display Before Swap Values x, y
Step 4: Assign t = x
Step 5: Assign x = y
Step 6: Assign y = t
Step 7: Display After Swap Values x, y
Step 8: Stop
Flow chart

start

Input x, y

Display x, y before
swap and t

t=x
X=y , y=t

Print x, y
after swap

stop
5, write an algorithm description and draw a flow chart to swap the
content of two variable without using third variable.
Algorithm
Step 1: start
Step 2: input two numbers say x, y
Step 3: display before swap values x, y
Step 4: Assign x= x + y
Step 5: Assign y= x-y
Step 6: Assign x= x-y
Step 7: display after swap value x,y
Step 8: stop
Flowchart
start

Input x, y
before
swap

X=x + y
y=x-y
x=x-y

Print x, y after
swap

stop
6, write an algorithm description and draw a flow chart to the
factorial of any number.
Algorithm
Step 1: start
Step 2: read number
Step 3: set fact=1, i=1
Step 4: check condition i<=number
if false go to step 7
Step 5: fact=fact*i
Step 6: update i=i+1 go to step 4
Step 7: display fact.
Step 8: stop
Flow chart

. start

Read
number

Fact=1
I=1

i<=num false Display fact


true

Fact=fact*i

stop

i=i+1
7, write an algorithm description and draw a flow chart to add
even number from 1 up to 100.
Algorithm
Step 1: start
Step 2: read i=1
Step 3: initialize sum=0
Step 4: if (i<=100) then
go to next step
else display sum then
go to step 9
Step 5: if (i%2==0) then
go to next step
else go to step 7
step 6: compute=sum=sum + i
step 7: compute i=i+1
step 8: go to step 4
step 9: stop
Flow chart Start

Read i=1

Initialize sum=0

Yes
Display sum No If i<=100

YES

YES NO
Stop if i%2=o

Sum=sum + i I=i+1

8, write an algorithm description and draw a flow chart to


calculate quadratic questions.
Algorithm
Step 1: start
Step 2: input the values of a, b and c
Step 3: calculate the discriminant D as:
D = b*b-4*a*c
Step 4: check D:
 If D>=0:
o Calculate real root:
 X1=(-b+√ D)/(2*a)
 X2=(-b-√ D)/(2*a)
 Print “real root”
 Else
 Print “no real root “
Step 5: stop

Flowchart

start
Yes No

X1= (-b+√ D)/2a


Print no
X2= (-b-√ D)/2a real root

Print real
root

stop

You might also like