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

Need help with Unix homework. Write a program in C that takes two numbers on the

ID: 3903982 • Letter: N

Question

Need help with Unix homework.

Write a program in C that takes two numbers on the command line and compares them. The program should print the result of the comparison. It should print “<x> is <comparison> <y>”, where <x> is the first number, <y> is the second number and <comparison> is one of “equal to”, “greater than” or “less than”. If the two numbers are equal then the program should have an exit status of zero. The exit status should be non-zero in all other cases.

Explanation / Answer

#include <stdio.h>

int main(int argc, char *argv[]) //Command Line arguments
{
int a,b,comp;
if(argc!=3) //verifying values are entered
{
printf("Enter values ");
return -1;
}
a=atoi(argv[1]); //assigning command line values to variables
b=atoi(argv[2]);  //assigning command line values to variables
  
if(a>b)
{
printf("%d is greater than %d",a,b);
return 1;
}
else if(a==b)
{
printf("%d is equal to %d",a,b);
return 0;
}
else
{
printf("%d is less than %d",a,b);
return 1;
}

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