mirror pairs - print \"mirror\" pa specified ranae irs of integers in a The prog
ID: 3728398 • Letter: M
Question
mirror pairs - print "mirror" pa specified ranae irs of integers in a The program should read two integer values, min and max. It should then print a single line of output with a series of comma separated values of the form 3 i 4 min,max min+1,max-1, min+2,max-2 Only pairs where the first value in the pair is less than the second should be printed. There should be at least one space between each pair. There should be no space before or after the comma separating the numbers in a pair 7 Example: if the input is 1 10, then the output should be 1,10 2,9 3,8 4,7 5,6 Another example, if the input is 5 15, then the output should be 5,15 6,14 7,13 8,12 9,11 Hints You can assume that min (the first input value) will be less than max (the second input value.)Explanation / Answer
Hello There,
PFC code in C for the requested functionality and the output of test runs:
prog.c
-----------------------
#include <stdio.h>
void main(){
int min, max;
printf("Enter two numbers: ");
scanf("%d%d",&min, &max);
while(min < max){
printf("%d,%d ", min, max);
min++;
max--;
}
printf(" ");
}
-------------------------------
Test runs:
--------------------------------------
$ gcc prog.c
$ ./a.out
Enter two numbers:
1 10
1,10 2,9 3,8 4,7 5,6
$ ./a.out
Enter two numbers:
5 15
5,15 6,14 7,13 8,12 9,11
$
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.