Find Largest Element in Array : C Program

Computer Science » C Program » Find Largest Element in Array

Program :

#include<stdio.h>
 
int main() 
{
   int a[30], i, num, largest;
 
   printf("nEnter no of elements : ");
   scanf("%d", &num);
 
   //Read n elements in an array
   for (i = 0; i < num; i++)
      scanf("%d", &a[i]);
 
   //Consider first element as largest
   largest = a[0];
 
   for (i = 0; i < num; i++) { if (a[i] > largest) {
         largest = a[i];
      }
   }
 
   // Print out the Result
   printf("nLargest element is : %d", largest);
 
   return (0);
}

Output :

Enter no of elements : 5
10 20 30 40 50 
Largest element is : 50
Subject Name : Computer Science
Exam Name : IIT GATE, UPSC ESE, RRB, SSC, DMRC, NMRC, BSNL, DRDO, ISRO, BARC, NIELIT
Posts Name : Assistant Engineer, Management Trainee, Junior Engineer, Technical Assistant
Computer Science Books

GATE 2023 Total InfoENGG DIPLOMAUGC NET Total Info
IES 2023 Total InfoPSUs 2022 Total InfoCSIR UGC NET Total Info
JAM 2023 Total InfoM TECH 2023 Total InfoRAILWAY 2022 Total Info

Related Posts

  • Find Smallest Element in Array : C ProgramComputer Science » C Program » Find Smallest Element in Array  Program : [php]#include<stdio.h> int main() { int a[30], i, num, smallest; printf("nEnter no of elements : "); scanf("%d", &num); //Read n elements in an array for (i = 0; i < num; i++) scanf("%d", &a[i]); //Consider first element as smallest smallest = a[0]; for (i = 0; i < num; i++) { if (a[i] < smallest) { smallest = a[i]; } } // Print out the Result printf("nSmallest element is : %d", smallest); return (0); }[/php] Output : [php]Enter no of elements : 5 10 20 30 40 50 Smallest element is : 10[/php]
    Tags: program, find, element, array, computer, science, output, programs
  • Find Sum of Two Float Numbers : C ProgramComputer Science » C Program » Find Sum of Two Float Numbers Program : [php]#include<stdio.h> int main() { float a, b, sum; printf("Enter two numbers : "); scanf("%f %f", &a, &b); sum = a + b; printf("nSum : %.2f", sum); return(0); }[/php] Output : [php]Enter two numbers : 2.2 3.6 Sum : 5.80[/php]
    Tags: program, find, computer, science, output, programs
  • 1-10 Numbers in Pyramid : C ProgramComputer Science » C Program » 1-10 Numbers in Pyramid Program : [php]#include<stdio.h> int main() { int i, j; int count = 1; for (i = 0; i <= 4; i++) { printf("n"); for (j = 0; j < i; j++) { printf("%dt", count); count++; } } return(0); }[/php] Output : [php]1 2 3 4 5 6 7 8 9 10 [/php]
    Tags: program, computer, science, output, programs
  • Find Average of Two Numbers : C ProgramComputer Science » C Program » Find Average of Two Numbers Program : [php]#include <stdio.h> int main() { int num1, num2; float avg; printf("nEnter first number : "); scanf("%d",&num1); printf("nEnter second number : "); scanf("%d",&num2); avg= (float)(num1+num2)/2; printf("nAverage of %d and %d is : %f",num1,num2,avg); return 0; }[/php] Output : [php]Enter first number : 5 Enter second number : 3 Average of 5 and 3 is : 4.00[/php]
    Tags: program, find, computer, science, output, programs
  • Searching Element in an Array : C ProgramComputer Science » C Program » Searching Element in an Array Program : [php]#include<stdio.h> int main() { int a[30], element, num, i; printf("nEnter no of elements : "); scanf("%d", &num); printf("nEnter the values : "); for (i = 0; i < num; i++) { scanf("%d", &a[i]); } //Read the element to be searched printf("nEnter the element to be searched : "); scanf("%d", &element); //Search starts from the zeroth location i = 0; while (i < num && element != a[i]) { i++; } //If i < num then Match found if (i < num) { printf("nNumber found at the location : %d", i + 1); } else { printf("nNumber not found."); } return (0); }[/php] Output 1: [php]Enter no of elements : 5 Enter the values : 10 20 30 40 50 Enter the element to be searched : 30 Number found at the location : 3[/php] Output 1: [php]Enter no of elements : 5 Enter the values : 10 20 30 40 50 Enter the element to be searched : 60 Number not found.[/php]
    Tags: program, element, array, output, computer, science, programs

LEAVE A REPLY

Please enter your comment!
Please enter your name here