Sie sind auf Seite 1von 15

ITTIHAD UNIVERSITY

COLLEGE OF MANAGEMENT AND INFORMATION SYSTEMS


Student Name: Zubaidah Abdul Rehman Alim Al Din
Student ID: 20042080
Course: Programming 2 (ab Assignment ! "#
Problem#1: [ 10-Marks]
Write a program that reads 2 integers start and end in the main program. It passes these 2
integers to a fn!tion sbprogram that ses for loop to find the sm of all the integers
bet"een start and end and retrns the sm to the main program. #he main program shold
print the sm.
#in!lde $iostream.h%
&oid main'(
)
int *+,+i-
int sm.0-
!ot$$/0nter the t"o &ales:/$$endl-
!in%%*%%,-
for'i.0-i$.2-i11(
)
sm.*1,-
2
!ot$$/3m is ./$$sm$$endl-
2
Page " o$ "%
ITTIHAD UNIVERSITY
COLLEGE OF MANAGEMENT AND INFORMATION SYSTEMS
Student Name: Zubaidah Abdul Rehman Alim Al Din
Student ID: 20042080
Course: Programming 2 (ab Assignment ! "#
Problem#2: [ 10-Marks]

Write a program that reads 4 integers start+ end and nmber in the main program. It passes
these 4 integers to a fn!tion sbprogram that ses for loop to find those integers bet"een
start and end that are di&isible b, nmber. If it finds the nmbers it prints them in the
fn!tion onl,. 5ere the fn!tion is not retrning an,thing. 6i&isible means gi&ing a
remainder of 0.
#in!lde $iostream.h%
&oid main'(
)
int *-
int ,-
int a+b+!-
!ot $$ /0nter integer 780 ,o "ant to find di&isible's( b,: /$$endl-
!in %%a-
!ot $$ /0nter integer #W7 ,o "ant to find di&isible's( b,: /$$endl-
!in %%b-
!ot $$ /0nter integer #5900 ,o "ant to find di&isible's( b,: /$$endl-
!in %%!-
for'* . 1- * :. a - *11(
)
, . a;*-
if', .. 0 (
)
!ot$$/6i&isible of entered integer 780./$$ *-
!ot$$ /<n/-
2
2
Page 2 o$ "%
ITTIHAD UNIVERSITY
COLLEGE OF MANAGEMENT AND INFORMATION SYSTEMS
Student Name: Zubaidah Abdul Rehman Alim Al Din
Student ID: 20042080
Course: Programming 2 (ab Assignment ! "#

for'* . 1- * :. b - *11(
)
, . b;*-
if', .. 0 (
)
!ot$$/6i&isible of entered integer #W7./$$ *-
!ot$$ /<n/-
2
2
for'* . 1- * :. ! - *11(
)
, . !;*-
if', .. 0 (
)
!ot$$/6i&isible of entered integer #5900../$$ *-
!ot$$ /<n/-
2
2
!ot$$/#hank ,o and this is the end of the Program/$$endl-
2
Page & o$ "%
ITTIHAD UNIVERSITY
COLLEGE OF MANAGEMENT AND INFORMATION SYSTEMS
Student Name: Zubaidah Abdul Rehman Alim Al Din
Student ID: 20042080
Course: Programming 2 (ab Assignment ! "#
Problem # 4: [ 10-Marks]
Write a fn!tion to find ma*imm+ minimm and a&erage of all elements stored in an
arra,. Write main to !all this fn!tion and displa, reslts.
#in!lde $iostream.h%
&oid mn 'int a[ ](
)
int i+ma*.0+min.a[0]-
float a&-
==a&erage de!laration
for ' i.0-i$10-i11(
)
if'a[i]% ma*(
ma*.a[i]-
else if 'a[i]$ min(
min.a[i]-
2
!ot$$/#he ma*imm is./$$ma*$$endl-
!ot$$/#he minimm is./$$min$$endl-
a&.ma*=min-
!ot$$/#he a&erage is./$$a&$$endl-
2
&oid main '(
)
int >[10].)100+200+400+?00+@00+A00+B00+C00+D00+202-
mn'>(-
==fn!tion !all
2
Page 4 o$ "%
ITTIHAD UNIVERSITY
COLLEGE OF MANAGEMENT AND INFORMATION SYSTEMS
Student Name: Zubaidah Abdul Rehman Alim Al Din
Student ID: 20042080
Course: Programming 2 (ab Assignment ! "#
Problem # ?: [ 10-Marks]

Write a program in "hi!h the main fn!tion reads an integer arra, ab! of siEe 10 and an
integer &ariable nm. It then passes the arra, ab! and the nm &ariable to a fn!tion !alled
di& "hi!h !onts the nmber of elements of arra, ab! that are di&isible b, nm and retrns
the !ont to the main program "hi!h prints it.
#in!lde$iostream.h%
#define siEe 10
int di&' int F[]+ int nm(
)
int i+!ont.0-
for 'i.0-i$.siEe-1-i11(
)
if'F[i];nm..0(
)
!ont11-
2

2
retrn !ont-
2

Page % o$ "%
ITTIHAD UNIVERSITY
COLLEGE OF MANAGEMENT AND INFORMATION SYSTEMS
Student Name: Zubaidah Abdul Rehman Alim Al Din
Student ID: 20042080
Course: Programming 2 (ab Assignment ! "#


&oid main'(
)
int ab![siEe]+i+nm+!-
!ot $$/Please Inpt 8mber nm :/$$endl-
!in%%nm-
!ot$$/Please Inpt 10 Gales for Frra, : /$$endl-
for'i.0-i$.siEe-1-i11(
)
!in%%ab![i]-
2
!.di&'ab!+nm(-
!ot$$/#he total arra, &ales di&isible b, /$$nm$$/ are . /$$!$$endl-
2
Page ' o$ "%
ITTIHAD UNIVERSITY
COLLEGE OF MANAGEMENT AND INFORMATION SYSTEMS
Student Name: Zubaidah Abdul Rehman Alim Al Din
Student ID: 20042080
Course: Programming 2 (ab Assignment ! "#
Problem # @: [10- Marks]

Write a main program that reads an integer arra, aaa of siEe C and passes it to t"o
fn!tions !alled large and small. #he fn!tion large finds the largest nmber in the arra,
and retrns to main program and small finds the smallest nmber in the arra, and retrns
to main program. #he main program shold print the large and small nmbers fond b,
the fn!tions.
#in!lde $iostream.h%
&oid mn 'int a[ ](
)
int i+largest.0+smallest.a[0]-
for ' i.0-i$C-i11(
)
if'a[i]% largest(
largest.a[i]-
else if 'a[i]$ smallest(
smallest.a[i]-
2
!ot$$/#he largest nmber in an arra, aaa is./$$largest$$endl$$endl-
!ot$$/#he smallest nmber in an arra, aaa is./$$smallest$$endl$$endl-
!ot$$/#his is the end of the program to find the largest and smallest in arra,
aaa/$$endl$$endl-
2
&oid main '(
)
int aaa[C].)1000+2000+4000+?000+@000+A000+B000+CCCC2-
mn'aaa(-
2
Page ( o$ "%
ITTIHAD UNIVERSITY
COLLEGE OF MANAGEMENT AND INFORMATION SYSTEMS
Student Name: Zubaidah Abdul Rehman Alim Al Din
Student ID: 20042080
Course: Programming 2 (ab Assignment ! "#
Problem # A: [20-Marks]
Honsider the follo"ing list of monthl, rainfall in a !it, in millimeters.
Ian Jeb Mar Fpr Ma, In Il Fg 3ep 7!t 8o& 6e!
11.@ 10.A D.C 4.B C.@ 1?.0 1C.@ 22.? 2B.A 12.@ 12.0 14.C

Kse an arra, "ith abo&e data. It is desired to determine the month in "hi!h ma*imm and
minimm rainfall o!!rred. Flso find the a&erage monthl, rainfall and its standard
de&iation. Instead of a!tal names ,o !an Lst print the nmber of month ranging from 1-
12. 8o ser inpt is reMired.

9 is the a&erage rainfall and ri are monthl, rainfalls.
Page 8 o$ "%
n
R r
SD
n
i
i

=
"
0
2
# (
ITTIHAD UNIVERSITY
COLLEGE OF MANAGEMENT AND INFORMATION SYSTEMS
Student Name: Zubaidah Abdul Rehman Alim Al Din
Student ID: 20042080
Course: Programming 2 (ab Assignment ! "#
#in!lde $math.h%
#in!lde $iostream.h%
&oid main'&oid(
)
doble 9ainJall[12]. )11.@+10.A+D.C+4.B+C.@+1?.0+1C.@+22.?+2B.A+12.@+12.0+14.C2-
doble sm+ F&g + Min + Ma*-
int i +MinInde*+Ma*Inde*-
sm.0-
MinInde*.0-
Ma*Inde*.0-
Min.9ainJall[0]-
Ma*.9ainJall[0]-
for'i.0-i$12-i11(
)
sm1.9ainJall[i]-
if '9ainJall[i]$Min(
)
Min . 9ainJall[i]-
MinInde*.i-
2
if '9ainJall[i]%Ma*(
)
Ma* . 9ainJall[i]-
Ma*Inde*.i-
2
2
Page ) o$ "%
ITTIHAD UNIVERSITY
COLLEGE OF MANAGEMENT AND INFORMATION SYSTEMS
Student Name: Zubaidah Abdul Rehman Alim Al Din
Student ID: 20042080
Course: Programming 2 (ab Assignment ! "#
F&g . sm =12-
sm.0-
for 'i.0-i$12-i11(
sm 1. '9ainJall[i]-F&g(N'9ainJall[i]-F&g(-
!ot$$/Minimm 9ainJall is in month :/$$MinInde*11$$endl-
!ot$$/Ma*imm 9ainJall is in month :/$$Ma*Inde*11$$endl-
!ot$$/F&erage 9ainJall is:/$$F&g$$endl-
!ot$$/3tandard 6e&iation is:/$$sMrt'sm=12($$endl-
2
Problem # B: [40-Marks]
Write a men dri&en program+ "hi!h has follo"ing options:

1. Ja!torial of a 8mber.
2. Prime or not.
4. 7dd or 0&en.
?. 0*it

It must execute appropriate choice entered by user.
Page "0 o$ "%
ITTIHAD UNIVERSITY
COLLEGE OF MANAGEMENT AND INFORMATION SYSTEMS
Student Name: Zubaidah Abdul Rehman Alim Al Din
Student ID: 20042080
Course: Programming 2 (ab Assignment ! "#
#in!lde$iostream.h%
#in!lde$stdlib.h%

&oid fa!t'int n(
)
int i-
doble ans.1-
for 'i.n - i%.1 - i--(
)
ans . ans N i-
2
!ot$$/#he fa!torial of/$$n$$/is:/$$ans$$endl-
2

&oid prime'int nm(
)

int i-
i.2-

"hile'i$.nm-1(
)

if'nm;i .. 0(
)
!ot$$/is not a prime nmber: /$$nm$$endl-
break-
2

i11-
2 == end of "hile
Page "" o$ "%
ITTIHAD UNIVERSITY
COLLEGE OF MANAGEMENT AND INFORMATION SYSTEMS
Student Name: Zubaidah Abdul Rehman Alim Al Din
Student ID: 20042080
Course: Programming 2 (ab Assignment ! "#
if'i..nm(
!ot$$/is a Prime 8mber /$$nm$$endl-
2 == end of prime fn!tion


&oid e&odd'int n(
)
if'n ; 2 .. 0(
!ot$$/is an e&en nmber/$$n$$endl-
else
!ot$$/is an odd nmber/$$n$$endl-
2


&oid main'&oid(
)
int !hoi!e+ nm-
"hile'!hoi!e :. ?(
)
!ot$$/<n<n<t1. Ja!torial of a 8mber.<n<t2. Prime or not.<n<t4. 7dd or 0&en.<n<t?.
0*it.<n<t/$$endl-
!ot$$/Please sele!t ,or Hhoi!e '1-?( : /$$endl-
!ot$$/---------------------------------------------------/$$endl-
!in%%!hoi!e-

s"it!h '!hoi!e(
)
!ase 1:
!ot$$/Please enter nmber : /$$endl-
!in%%nm-
fa!t'nm(-
break-
!ase 2:
Page "2 o$ "%
ITTIHAD UNIVERSITY
COLLEGE OF MANAGEMENT AND INFORMATION SYSTEMS
Student Name: Zubaidah Abdul Rehman Alim Al Din
Student ID: 20042080
Course: Programming 2 (ab Assignment ! "#
!ot$$/Please enter nmber : /$$endl-
!in%%nm-
prime'nm(-
break-
!ase 4:
!ot$$/Please enter nmber : /$$endl-
!in%%nm-
e&odd'nm(-
break-
!ase ? :
!ot$$/Oood b,e/$$endl-
break-
defalt :
!ot$$/6ear+ Por !hoi!e mst be bet"een '1-?(/$$endl-
2==end of s"it!h
2 == end of While
2 == end of main
Page "& o$ "%
ITTIHAD UNIVERSITY
COLLEGE OF MANAGEMENT AND INFORMATION SYSTEMS
Student Name: Zubaidah Abdul Rehman Alim Al Din
Student ID: 20042080
Course: Programming 2 (ab Assignment ! "#
Page "4 o$ "%
ITTIHAD UNIVERSITY
COLLEGE OF MANAGEMENT AND INFORMATION SYSTEMS
Student Name: Zubaidah Abdul Rehman Alim Al Din
Student ID: 20042080
Course: Programming 2 (ab Assignment ! "#
NNN086 7J F33IO8M08#NNN
Page "% o$ "%

Das könnte Ihnen auch gefallen