wap to find maximum and minimum numbers in array .(method 2)

 




#include<stdio.h>
#include<conio.h>
void main()
   int a[10],b,i,c,n,x[10];
   
   printf("enter the size of an array :\n");
   scanf("%d",&n);

   printf("enter the elements of yr array :\n");
   for(i=0;i< n;i++)
   {
     scanf("%d",&a[i]);
   }
   
   printf("\nyr array is :\n");
   for(i=0;i< n;i++)
   {
     x[i]=a[i];
     printf("  %d",a[i]);
   }
  
   
    
   printf("\n\nfor min. max ");
   for(i=0;i<n;i++)
   {
    if(a[i]>a[i+1])
    {
      b=a[i];
      a[i+1]=b;
      
    }
   }
     if(b<a[n-1])
     b=a[n-1];

   for(i=0;i< n;i++)
   {
    if(x[i]<x[i+1])
    {
      c=x[i];
       x[i+1]=c;
    }
   }
  
   printf("\nmax. no is %d",b);
   printf("\nmin. no is %d",c);


}

output :

enter the size of an array : 6 enter the elements of yr array : 45 21 34 09 78 67 yr array is : 45 21 34 9 78 67 for min. max max. no is 78 min. no is 9

Comments

Popular Post

Write the definition for a class called complex that has floating point data members for storing real and imaginary parts. The class has the following member functions: void set(float, float) to set the specified value in object void disp() to display complex number object complex sum(complex) to sum two complex numbers & return complex number 1. Write the definitions for each of the above member functions. 2. Write main function to create three complex number objects. Set the value in two objects and call sum() to calculate sum and assign it in third object. Display all complex numbers.