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

Write a C program C PROGRAMING - PLEASE INCLUDE COMMENTS AND TEACH CODE - KEEP I

ID: 3674569 • Letter: W

Question

Write a C program

C PROGRAMING - PLEASE INCLUDE COMMENTS AND TEACH CODE - KEEP IT BEGINNER LEVEL

YOU CAN USE : Variables, Expressions and Operators / Logical Operations and Selection Statements / Repetition and Loops / Use Data Files

Only scalar variables are permitted (no arrays) and that the use of helper functions is forbidden (all programming to be done in the main)

Write a program that is capable to find the two largest and the two smallest integers in a list of 20 integers. The list of integers is in a file of two lines of 10 integers. Try your program with these files to make sure it works properly:

https://dl.dropboxusercontent.com/u/18549820/projects/cps125/file1.data

https://dl.dropboxusercontent.com/u/18549820/projects/cps125/file2.data

Explanation / Answer

#include<stdio.h>
int main( )
{
int a[50],size,i,j=0,1st largest,2nd largest,1st smallest,2nd smallest;
printf("Enter the size of the array: ");
scanf("%d",&size);
printf("Enter %d elements in to the array: ", size);
for(i=0;i<size;i++)
scanf("%d",&a[i]);

1st largest=a[0];
for(i=1;i<size;i++)
{
if(1st largest<a[i])
{
1st largest=a[i];
j = i;
}
}

2nd largest=a[size-j-1];
for(i=1;i<size;i++){
if(2nd largest <a[i] && j != i)
2nd largest =a[i];
}
printf("2nd largest: %d", 2nd largest);
  


1st smallest=a[0];
for(i=1;i<size;i++){
if(1st smallest>a[i]){
1st smallest=a[i];
j = i;
}
}

2nd smallest=a[size-j-1];
for(i=1;i<size;i++){
if(2nd smallest > a[i] && j != i)
2nd smallest =a[i];
}

printf("2nd smallest: %d", 2nd smallest);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote