Commit c21cfaac by otsall

Upload New File

parent a77626a7
Showing with 127 additions and 0 deletions
#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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment