Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you please explain this C code beside every code on each line: #include #include int main() { int students; int difference; int range1; int

Can you please explain this C code beside every code on each line:

#include #include

int main() { int students; int difference; int range1; int range2; int total1; int total2; int total3;

int result1 = 0; int result2 = 0;

scanf("%d %d", &students, &difference); getchar(); int array[students];

for(int i = 0; i < students; i++) { scanf("%d", &array[i]); getchar(); } for(int i = 0; i < students; i++) { for(int j = i + 1; j < students; j++) { range1 = array[i] - array[j]; total1 = abs(range1); if(total1 <= difference) { for(int k = j + 1; k < students; k++) { range1 = array[j] - array[k]; range2 = array[i] - array[k]; total1 = abs(range1); total2 = abs(range2); if(total1 <= difference && total2 <= difference) { result1 = result1 + 1; total3 = array[i] + array[j] + array[k]; if(result2 < total3) { result2 = total3; } } } } } }

if(result1 > 0) { printf("%d %d ", result1, result2); } else { printf("-1 "); } return 0; }

Thank you!!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions

Question

Include a branded social experience for your social media audience.

Answered: 1 week ago