Write a menu driven C programe which will create the reverse of the array will get you the maximum value from the array and also get the sum of the elements from the array

  

Hey guys once again welcome to the Decoders blog, I hope you all are doing well and today I'm present with another logic but this time with something different it is a C logic which will create the reverse of the array will get you the maximum value from the array and also get the sum of the elements from the array 

Here's the code which you can go through...........

#include<stdio.h>
int main()
{
    int n,cont;
    int array[10];
    int i,j,max,sum=0;
     max=array[0];
    do
    {
        printf("1:Reverse the array\n2:Sum of the elements of the array\n3:Maximum of an array\n");
        scanf("%d",&n);
        switch(n)
        {
            case 3:
                //Storing the values for a given array
                printf("Enter the values for the array must be distinct");
                for(i=0;i<6;i++)
                {
                    scanf("%d",&array[i]);
                }

                for(i=0;i<6;i++)
                {
                    if(array[i]>max)
                    {
                        max=array[i];
                    }
                }

                printf("\nThe maximum value is %d",max);
                break;

             case 2:
                    printf("Enter the values in the array:\n");
                    //Storing the values in the array
                    for(i=0;i<6;i++)
                    {
                        scanf("%d",&array[i]);
                    }
                    //Displaying the stored array
                    for(i=0;i<6;i++)
                    {
                        printf("%d\t",array[i]);
                    }
                    //Logic for finding the sum of the elements from the array
                    for(i=0;i<6;i++)
                    {
                        sum += array[i];
                    }

                    printf("\nThe required sum is %d",sum);
                    break;

            case 1:
                    printf("Enter the values in the array:\n");
                    //Storing the values in the array

                    for(i=0;i<6;i++)
                    {
                        scanf("%d",&array[i]);
                    }

                    //Displaying the stored array
                    for(i=0;i<6;i++)
                    {
                        printf("%d\t",array[i]);
                    }

                    //Logic to reverse the elements of the array
                    printf("\nThe reverse order of the array is \n");
                    for(i=5;i>=0;i--)
                    {
                        printf("%d\t",array[i]);
                    }
                    break;
       
        default:
            printf("Enter any operation you want to do:");
            break;
        }
    printf("\nDo you want to run the operatio again:\n");
    scanf("%d",&cont);
    } while (cont==1);
   
}

Comments

Popular Posts