Learn C Language from the Best Tutors
Search in
Program to accept a list of elements and find the maximum number in the list.
The logic will be
1. Create an array of the desired type
2. Sort the array in the descending order
3. Fetch the first elemnet from the array, this will be the maximum element in that array.
Now use this logic to write code in the desired programming language.
read less
C programming code
#include <stdio.h>
int main()
{
int array[100], maximum, size, c, location = 1;
printf("Enter the number of elements in array\n");
scanf("%d", &size);
printf("Enter %d integers\n", size);
for (c = 0; c < size; c++)
scanf("%d", &array[c]);
maximum = array[0];
for (c = 1; c < size; c++)
{
if (array[c] > maximum)
{
maximum = array[c];
location = c+1;
}
}
printf("Maximum element is present at location %d and it's value is %d.\n", location, maximum);
return 0;
}
C programming code
#include <stdio.h>
int main()
{
int array[100], maximum, size, c, location = 1;
printf("Enter the number of elements in array\n");
scanf("%d", &size);
printf("Enter %d integers\n", size);
for (c = 0; c < size; c++)
scanf("%d", &array[c]);
maximum = array[0];
for (c = 1; c < size; c++)
{
if (array[c] > maximum)
{
maximum = array[c];
location = c+1;
}
}
printf("Maximum element is present at location %d and it's value is %d.\n", location, maximum);
return 0;
}
using
System;
using
System.Linq;
public
class
abc {
// returns maximum in arr[] of size n
static
int
MaximumNumber(
int
[]arr,
int
n)
{
return
arr.Max();
}
static
public
void
Main ()
{
int
[]arr = {10, 324, 45, 90, 9808};
int
n = arr.Length;
Console.WriteLine( MaximumNumber(arr, n));
}
}
# include<stdio.h>
#include< conio.h>
void main ()
{
int a[50],n,i ,max;
printf( " Enter no. of elements");
scanf("%d",&n);
printf ("Enter all elements one by one");
for(I=0;I<n;I++)
scanf("%d",&a[i]);
max=a[ 0 ];
for( i=0; i<n; i++)
{
If( a[ i ]>max)
max= a[ i ];
}
printf ("Largest element: %d",max);
getch();
}
read less
#include<stdio.h>
int main()
{
int a[50],i,n,large,small;
printf("How many elements:");
scanf("%d",&n);
printf("Enter the Array:");
for(i=0;i<n;++i)
scanf("%d",&a[i]);
large=small=a[0];
for(i=1;i<n;++i)
{
if(a[i]>large)
large=a[i];
if(a[i]<small)
small=a[i];
}
printf("The largest element is %d",large);
printf("\nThe smallest element is %d",small);
return 0;
}
read lessView 6 more Answers
Related Questions
Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com
Ask a QuestionRecommended Articles
Lasya Infotech: An educational Training...
Lasya Infotech is a Hyderabad based IT training institute founded in 2016 by O Venkat. Believing in his innovation, passion and persistence and with a diverse blend of experience, he started his brainchild to deliver exemplary professional courses to aspiring candidates by honing their skills. Ever since the institute envisions...
Brilliant Academy, a reputed B. Tech Tuition...
Brilliant Academy is one of the reputed institutes for B.Tech tuition classes. This institute is specialised in delivering quality tuition classes for B.E, Engineering - all streams and Engineering diploma courses. Incorporated in 2012, Brillant Academy is a brainchild of Mr Jagadeesh. The main motto of the academy is to...
8 Hottest IT Careers of 2014!
Whether it was the Internet Era of 90s or the Big Data Era of today, Information Technology (IT) has given birth to several lucrative career options for many. Though there will not be a “significant" increase in demand for IT professionals in 2014 as compared to 2013, a “steady” demand for IT professionals is rest assured...
Make a Career as a BPO Professional
Business Process outsourcing (BPO) services can be considered as a kind of outsourcing which involves subletting of specific functions associated with any business to a third party service provider. BPO is usually administered as a cost-saving procedure for functions which an organization needs but does not rely upon to...
Looking for C Language Classes?
Learn from the Best Tutors on UrbanPro
Are you a Tutor or Training Institute?
Join UrbanPro Today to find students near youThe best tutors for C Language Classes are on UrbanPro
The best Tutors for C Language Classes are on UrbanPro