C Saved Program: kind-dog

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


#include<stdio.h>
int main()//Function main begin
{
    int array[50];
    int i=0, largest, large, k, size;
   largest=array[0]; //assign 1st element as largest

printf("Enter the number of elements:\n");
scanf("%d", &size);  //Reseave the size of the array
printf("Enter the elements:\n");
for(i=0; i<size; i++)  //Reseaving the elements of the array
{
    scanf("%d", &array[i]);
    printf("\n");
} //End for
 for(i=1; i<size; i++)
 {
  if(largest<array[i])//Checking for the largest element
  {
     largest=array[i];
     k=i;
  }// End if
 }//End for
 array[k]=0;//Assigning largest element to 0
 large=array[0];
 for(i=1; i<size; i++)//Checking for the next largest element
 {
  if(large<array[i])
  {
     large=array[i];
  }//End if
 }//End for
 printf("The second largest number of the array is %d", large);
}//End function main
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs