Search This Blog

Thursday, October 13, 2011

write a program to read a set of real nums in one line of the keyboard and using the function maxno(), display the largest num entered.

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

No comments:

Post a Comment