Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C Programming Assignment 5 For Loops Due Wednesday, October 11,2017 For each of

ID: 3590349 • Letter: C

Question

C Programming Assignment 5 For Loops Due Wednesday, October 11,2017 For each of the programs assigned below, submit a copy of the source code (.c ) saved as an electronic attachment to Homework 5 located in Canvas under Assignments. Observe the usual guidelines regarding the initial comment section, indenting, and so on. In addition, In if-else statements, indent statements to be executed for if or else condition three spaces. Align else or else if with corresponding if. Indent statements within loops. Do not use global variables.

Explanation / Answer

#include <stdio.h>
#include <time.h>
#include <conio.h>


int main()
{

int size=10,i,first,second;

int arr[50];
clrscr();
srand((unsigned)time(0));

for(i=0; i<size; i++)
   {
   arr[i] = (rand()%50)+1;
   printf("%d ",arr[i]);
   }

first = second = 0;
for (i = 0; i < size ; i ++)
{

   if (arr[i] > first)
   {
   second = first;
   first = arr[i];
   }


   else if (arr[i] > second && arr[i] != first)
   second = arr[i];
}


   printf("The first largest element is %d ", first);

   printf("The second largest element is %d ", second);
return 0;
}

out put comes correctly.....for 10 random numbers between 1 to 50