Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
otsall
/
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
c21cfaac
authored
Nov 05, 2018
by
otsall
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
a77626a7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
127 additions
and
0 deletions
Lab9/task1and2.c
Lab9/task1and2.c
0 → 100644
View file @
c21cfaac
#include <stdio.h>
float
multiply
(
float
a
,
float
b
);
float
divide
(
float
a
,
float
b
);
float
add
(
float
a
,
float
b
);
float
subst
(
float
a
,
float
b
);
float
minval
(
float
array
[],
int
i
);
float
maxval
(
float
array
[],
int
i
);
float
avgval
(
float
array
[],
int
i
);
int
main
(){
int
choice
,
i
,
j
;
float
a
,
b
,
c
;
puts
(
"input 1 to do simple arithmetic, input anything else to find min/max/avg value of series"
);
scanf
(
"%d"
,
&
i
);
if
(
i
==
1
){
puts
(
"input first number"
);
scanf
(
"%f"
,
&
a
);
puts
(
"input second number"
);
scanf
(
"%f"
,
&
b
);
puts
(
"input 1 for multiplication, 2 for division, 3 for addition and 4 for substraction"
);
scanf
(
"%d"
,
&
choice
);
while
(
i
==
1
){
switch
(
choice
){
case
1
:
c
=
multiply
(
a
,
b
);
printf
(
"result is %f
\n
"
,
c
);
i
=
0
;
break
;
case
2
:
c
=
divide
(
a
,
b
);
printf
(
"result is %f
\n
"
,
c
);
i
=
0
;
break
;
case
3
:
c
=
add
(
a
,
b
);
printf
(
"result is %f
\n
"
,
c
);
i
=
0
;
break
;
case
4
:
c
=
subst
(
a
,
b
);
printf
(
"result is %f
\n
"
,
c
);
i
=
0
;
break
;
default
:
puts
(
"what"
);
scanf
(
"%d"
,
&
choice
);
break
;
}
}
}
else
{
puts
(
"enter the length of the series"
);
scanf
(
"%d"
,
&
i
);
float
numbers
[
i
];
puts
(
"fill the series with numbers"
);
for
(
j
=
0
;
j
<
i
;
j
++
){
printf
(
"%d. number is "
,
j
+
1
);
scanf
(
"%f"
,
&
numbers
[
j
]);
}
puts
(
"input 1 to find maxvalue of the series, 2 to find minvalue, anything else to find the average value of the series"
);
scanf
(
"%d"
,
&
choice
);
switch
(
choice
){
case
1
:
c
=
maxval
(
numbers
,
i
);
printf
(
"result is %f
\n
"
,
c
);
break
;
case
2
:
c
=
minval
(
numbers
,
i
);
printf
(
"result is %f
\n
"
,
c
);
break
;
default
:
c
=
avgval
(
numbers
,
i
);
printf
(
"result is %f
\n
"
,
c
);
break
;
}
}
return
0
;
}
float
multiply
(
float
a
,
float
b
){
float
c
=
a
*
b
;
return
c
;
}
float
divide
(
float
a
,
float
b
){
float
c
=
a
/
b
;
return
c
;
}
float
add
(
float
a
,
float
b
){
float
c
=
a
+
b
;
return
c
;
}
float
subst
(
float
a
,
float
b
){
float
c
=
a
-
b
;
return
c
;
}
float
minval
(
float
array
[],
int
i
){
float
highscore
=
array
[
0
];
int
j
;
for
(
j
=
1
;
j
<
i
;
j
++
){
if
(
highscore
>
array
[
j
]){
highscore
=
array
[
j
];
}
}
return
highscore
;
}
float
maxval
(
float
array
[],
int
i
){
float
highscore
=
array
[
0
];
int
j
;
for
(
j
=
1
;
j
<
i
;
j
++
){
if
(
highscore
<
array
[
j
]){
highscore
=
array
[
j
];
}
}
return
highscore
;
}
float
avgval
(
float
array
[],
int
i
){
float
sum
=
0
;
int
j
;
for
(
j
=
0
;
j
<
i
;
j
++
){
sum
+=
array
[
j
];
}
sum
=
sum
/
i
;
return
sum
;
}
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