Friday, March 22, 2013

C Language Example # 42 Find Maximum and Minimum from Array and Find Sum of Digit of Maximum Number

C Language Example # 42 Find Maximum and Minimum from Array and Find Sum of Digit of Maximum Number.

* First Program will find out maximum and minimum from array elements.
* Then it will find maximum and minimum value from array.

//Written by : Latest Technology Guide
//Title : C Language Example # 42 Find Maximum and Minimum from Array and Find Sum of Digit of Maximum Number..

#include <stdio.h>
#include <conio.h>
void main()
{
    clrscr();
    int arr[70],i,n,j,temp,mul=1,sum=0,digit;

    printf("Enter the number of elements :");
    scanf("%d",&n);

    for(i=0;i<n;i++)
    {
        printf("Enter Element arr[%d] =",i);
        scanf("%d",&arr[i]);
    }

    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(arr[i]<arr[j])    //change < sign to descinding
            {
             //    temp=arr[i];
                arr[i]=arr[i]+arr[j];
              //    arr[i]=arr[j];
                arr[j]=arr[i]-arr[j];
              //    arr[j]=temp;
                arr[i]=arr[i]-arr[j];
            }

        }
    }

    temp=arr[0];

    while(temp>0)
    {
        digit=temp%10;
        sum=sum+digit;
        temp=temp/10;
    }

    temp=arr[n-1];

    while(temp>0)
    {
        digit=temp%10;
        mul=mul*digit;
        temp=temp/10;
    }

    printf("\n\n\tSum of Maximum %3d Number is          : %3d",arr[0],sum);
    printf("\n\tMultiplication of Minimum %3d Number is : %3d",arr[n-1],mul);

    getch();
}

Output:
* Program will display sum of all digits from maximum element from array.
* Program will display multiplication of all digit from minimum element from array. 


--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 42 Find Maximum and Minimum from Array and Find Sum of Digit of Maximum Number.

* You need to enter value of n.
* Enter Number of values.
* Program will find out maximum number from array.
* Program will find out minimum number from array.
* Program will sum all digits of maximum number.
* Program will multiply all digits of minimum number.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.

No comments:

Post a Comment

Post a Comment