Search This Blog

Thursday, October 13, 2011

Write a program to find the maximum element of an array of real num. Read the element of the array in function readdata() and find maximum in another function. Access the array elements through pointers.

   1:  #include<conio.h>
   2:  #include<stdio.h>
   3:  void readdata(int *size,float *addx)
   4:  {
   5:  int i;
   6:  float n;
   7:  char ch;
   8:  printf("\nEnter the elements of the array:\n");
   9:  i=0;
  10:  do
  11:  {
  12:  scanf("%f%c",&n,&ch);
  13:  *(addx+i)=n;
  14:  i++;
  15:  }while(ch!='\n');
  16:  *size=i;
  17:  }
  18:  float maxno(int size,float *addx)
  19:  {
  20:  int i;
  21:  float max=-1.0E38;
  22:  for(i=0;i<size;i++)
  23:      {
  24:      if((*addx+i)>max)
  25:      {
  26:      max=*(addx+i);
  27:      }
  28:      }
  29:  return(max);
  30:  }
  31:  void main()
  32:  {
  33:  int size;
  34:  float max;
  35:  int i;
  36:  float x[50];
  37:  readdata(&size,x);
  38:  max=maxno(size,x);
  39:  printf("\nThe array is: ");
  40:  for(i=0;i<size;i++)
  41:      printf("%.2f ",x[i]);
  42:  printf("\nThe maximum No is: %f",max);
  43:  getch();
  44:  }

No comments:

Post a Comment