Problem 34

author
By Supreme2023-03-15
Problem Statement :
Write a program to find maximum element from 1-Dimensional array.
Code:

#include <stdio.h>

int main(){

//Write a program to find maximum element from 1-Dimensional array.

printf("\tEven/Odd");
printf("\n======================================\n\n");

int max,num[50],n,i;

printf("How Many Numbers You Want To Enter : ");
scanf("%d",&n);
printf("\n");
for(i=0;i<n;i++){
printf("Enter The Number [%d] : ",i+1);
scanf("%d",&num[i]);

if(i==0){
max = num[i];
}
else{
if(num[i]>max){
max = num[i];
}
}
}
printf("\n\n======================================");
printf("\nMaximum From Given Values : %d",max);
printf("\n\n======================================");
return 0;
}

Description :
  • This program finds the maximum element from a 1-Dimensional array of numbers.
  • The program first prints out a message asking the user how many numbers they want to enter.
  • It then reads in the value of n, which represents the number of elements in the array.
  • Next, the program uses a loop to read in each element of the array and store it in the num[] array. It also compares each number with the current maximum value to find the maximum element.
  • Finally, the program prints out the maximum element.
Output Image:
Output-image

© Copyright 2022. All right reserved, GTU Coder.