Monday, June 18, 2012

To find the maximum value in an array using functions


/* Program to find the maximum value in an array using functions */

#include<stdio.h>

#include<conio.h>

/* Function Declaration */

int maximum(int a[10][10]);

int n,m;

void main()

{

  int values[10][10],i,j,max;

  clrscr();

  printf("Enter the number of rows and columns:\n");

  scanf("%d%d",&n,&m);

  printf("\nEnter the elements:\n");

  for(i=0;i<n;i++)

    for(j=0;j<m;j++)

      scanf("%d",&values[i][j]);

  max=maximum(values);   /* Function Call*/

  printf("\n\n Maximum value in given array is %d",max);

  getch();

}

 

/* Function Definition */

int maximum(int a[10][10])

{

  int i,j,max_value;

  max_value=a[0][0];

  for(i=0;i<n;i++)

    for(j=0;j<m;j++)

    {

      if(a[i][j]>max_value)

            max_value=a[i][j];

    }

  return max_value;

}

 

OUTPUT

Enter the number of rows and columns:

3

2

 

Enter the elements:

6

4

2

9

4

3

 

 

 Maximum value in given array is 9

 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.