Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

ilahma / iax0583

  • This project
    • Loading...
  • Sign in
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
Switch branch/tag
  • iax0583
  • Lab 9
  • lab9task2.c
Find file
BlameHistoryPermalink
  • ilahma's avatar
    Upload New File · ca422b9e
    ilahma committed 6 years ago
    ca422b9e
lab9task2.c 1.45 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
#include <stdio.h>

float average(int array[], float count);
int max(int array[], int n); 
int min(int array[], int n); 
int main() 	{
int number;
int i;
int array[number];
char operator;  

printf(" How long is your array? \n");
scanf("%d", &number);
printf("Please, enter numbers \n");
for(i=0; i<number; i++)	{
 scanf("%d", &array[i]);	

}
 
	while(getc(stdin) != '\n'); // scanf function takes /n as a character 
	printf("Please, enter an operator: average (a), max (l) or min (s) \n");
    scanf("%c", &operator);
    
switch(operator)
    {
   
       
		case 'a':
            printf("Average is %.1f", average(array, number));
            break;
        
        case 'l':
            printf("Max number is %d" ,max(array,number));
            break;
            
        case 's':
            printf("Min is %d ",min(array,number));
            break;
        case '\n':
			puts("dickdickdick");
        default:
            printf("Operator is not correct");
    }
    
return 0;

}
float average(int array[], float count){
	float sum =0;
	int i;
	for(i=0; i<count; i++){
		sum=sum+array[i];	

	} 
   
    return sum/count;               
}

int max(int array[], int n){
	int max =array[0];
	int i;
	for (i = 1; i < n; i++) 
        if (array[i] > max) 
            max = array[i]; 
  
    return max; 
} 

int min(int array[], int n){
	int min =array[0];
	int i;
	for (i = 1; i < n; i++) 
        if (array[i] < min) 
            min = array[i]; 
  
    return min; 
}