Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
viakul
/
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
d6a23ad0
authored
6 years ago
by
viakul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
1e96b564
master
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
0 deletions
Lab9/2.c
Lab9/2.c
0 → 100644
View file @
d6a23ad0
#include <stdio.h>
float
average
(
int
*
x
,
int
y
);
int
max
(
int
*
x
,
int
y
);
int
min
(
int
*
x
,
int
y
);
int
main
()
{
int
choice
,
n
,
i
;
float
result
;
i
=
0
;
puts
(
"write the number of values in array"
);
scanf
(
"%d"
,
&
n
);
int
ThisArray
[
n
];
puts
(
"the first element is array"
);
while
(
i
<
n
){
scanf
(
"%d"
,
&
ThisArray
[
i
]);
i
=
i
+
1
;
if
(
i
<
n
){
printf
(
"print another number
\n
"
);
}
}
printf
(
"thank you for numbers
\n
"
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
puts
(
"What do you want to do with numbers?"
);
puts
(
"for average write 1 "
);
puts
(
"for max write 2 "
);
puts
(
"for min write 3 "
);
do
{
puts
(
"make a choice "
);
scanf
(
"%d"
,
&
choice
);
}
while
(
choice
<
1
||
choice
>
4
);
switch
(
choice
){
case
1
:
result
=
average
(
ThisArray
,
n
);
break
;
case
2
:
result
=
max
(
ThisArray
,
n
);
break
;
case
3
:
result
=
min
(
ThisArray
,
n
);
break
;
}
printf
(
"%f"
,
result
);
return
0
;
}
float
average
(
int
*
x
,
int
y
){
int
sum
,
i
;
float
avg
;
i
=
0
;
sum
=
0
;
while
(
i
<
y
){
sum
=
sum
+
x
[
i
];
i
=
i
+
1
;
}
avg
=
sum
/
y
;
return
(
avg
);
}
int
max
(
int
*
x
,
int
y
){
int
maxVal
,
i
;
maxVal
=
x
[
0
];
i
=
1
;
while
(
i
<
y
){
if
(
maxVal
<
x
[
i
])
{
maxVal
=
x
[
i
];
}
i
=
i
+
1
;
}
return
(
maxVal
);
}
int
min
(
int
*
x
,
int
y
){
int
maxVal
,
i
;
maxVal
=
x
[
0
];
i
=
1
;
while
(
i
<
y
){
if
(
maxVal
>
x
[
i
])
{
maxVal
=
x
[
i
];
}
i
=
i
+
1
;
}
return
(
maxVal
);
}
This diff is collapsed.
Click to expand it.
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