Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
matjul
/
iax0583
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
890c94e3
authored
Oct 29, 2018
by
matjul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
99399728
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
0 deletions
lab9task2.c
lab9task2.c
0 → 100644
View file @
890c94e3
#include <stdio.h>
float
ave
(
int
array
[],
int
numbers
);
int
max
(
int
array
[],
int
numbers
);
int
min
(
int
array
[],
int
numbers
);
int
main
(){
int
i
;
int
numbers
;
int
choice
;
int
result
;
float
resultf
;
puts
(
"Enter the amount of numbers"
);
scanf
(
"%d"
,
&
numbers
);
int
array
[
numbers
];
puts
(
"Enter the numbers"
);
for
(
i
=
0
;
i
<
numbers
;
i
++
){
scanf
(
"%d"
,
&
array
[
i
]);
}
printf
(
"The action with numbers:
\n
1 - average
\n
2 - max
\n
3 - min
\n
"
);
do
{
puts
(
"pick the numbers"
);
scanf
(
"%d"
,
&
choice
);
}
while
(
choice
<
1
||
choice
>
3
);
switch
(
choice
){
case
1
:
puts
(
"The average thing"
);
resultf
=
ave
(
array
,
numbers
);
printf
(
"%f"
,
resultf
);
break
;
case
2
:
puts
(
"The maximum thing"
);
result
=
max
(
array
,
numbers
);
printf
(
"%d"
,
result
);
break
;
case
3
:
puts
(
"The minimum thing"
);
result
=
min
(
array
,
numbers
);
printf
(
"%d"
,
result
);
break
;
}
return
0
;
}
float
ave
(
int
array
[],
int
numbers
){
float
A
=
0
;
int
i
;
for
(
i
=
0
;
i
<
numbers
;
i
++
){
A
+=
array
[
i
];
}
A
=
A
/
numbers
;
return
A
;
}
int
max
(
int
array
[],
int
numbers
){
int
B
=
0
;
int
i
=
1
;
int
tmp
=
0
;
tmp
=
array
[
0
];
for
(
i
=
1
;
i
<
numbers
;
i
++
){
if
(
tmp
<
array
[
i
]){
tmp
=
array
[
i
];
}
}
B
=
tmp
;
return
B
;
}
int
min
(
int
array
[],
int
numbers
){
int
C
=
0
;
int
i
=
1
;
int
tmp
=
0
;
tmp
=
array
[
0
];
for
(
i
=
1
;
i
<
numbers
;
i
++
){
if
(
tmp
>
array
[
i
]){
tmp
=
array
[
i
];
}
}
C
=
tmp
;
return
C
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment