Write comments for the given example to explain your understanding of the C prog
ID: 3748484 • Letter: W
Question
Write comments for the given example to explain your understanding of the C program code:
/***************************************************************************
intro
*****************************************************************************/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <conio.h>
int main()
{
int small;
int large;
int temp;
printf (“ Enter two whole numbers : “);
scanf (“%d %d”, &small, &large);
if(small > large)
{
temp = small;
small = large;
large = temp;
}
else if (small == large)
{
small = -1;
large = -1;
}
printf("Small = %d ", small);
printf("Large = %d ", large);
_getch();
return 0;
}
Explanation / Answer
/***************************************************************************
intro
*****************************************************************************/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <conio.h>
int main()
{
int small;
int large;
int temp;
printf (“ Enter two whole numbers : “);
// get user input
// read the smaller and larger integer
scanf ("%d %d", &small, &large);
// if the user entered in wrong order
// if the element in small is actually bigger than the element stored in large
if(small > large)
{
// swap the elements in variables small and large
// so that the smaller element is in small
// sna the larger element is in lrge
temp = small;
small = large;
large = temp;
}
// if both the elements are equal
else if (small == large)
{
// set both to -1
small = -1;
large = -1;
}
// display the output to user
printf("Small = %d ", small);
printf("Large = %d ", large);
// read c character from user
// this is done such that the program doesn't terminate on its own and
// user needs to press enter in order to terminate
_getch();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.