Question

Write a C program having the following features Use an infinite loop to get a user...

Write a C program having the following features

  • Use an infinite loop to get a user to input an integer in each iteration
  • Include a Max function that returns greater absolute value of two integers
  • Printing the greatest absolute value of all inputs in each iteration
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below:

#include <stdio.h>

//max function returns greater absolute value
int max(int a,int b){
   int c = a;
   int d = b;
   if(c<0) {c = -1*c;}
   if(d<0) {d = -1*d;}

   if(c>d) {return a;}
   else {return b;}
}

int main()
{
   int input;
   int greaterAbsolute=0;
   while(1){
       printf("Enter integer : ");
       scanf("%d",&input);
       greaterAbsolute = max(greaterAbsolute,input);
       printf("Greater absolute value till now is %d\n",greaterAbsolute);
   }
   return 0;

}

output:

Add a comment
Know the answer?
Add Answer to:
Write a C program having the following features Use an infinite loop to get a user...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT