Question

C Programming Question 15 4 pts Read four numbers and find the largest value. Check if the largest value is multiple of 3

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:
#include <stdio.h>

int main()
{
   /* variable declaration */
   int i, max;
   int a[50];


   /* asking user to enter 4 numbers as input */  
   for(i = 1; i <= 4; i++){
       printf("\nEnter number %d : ", i);
       scanf("%d", &a[i]);
   }

   /* initializing max to the first element */
   max = a[0];
   /* identifying max out of four numbers given */
   for(i = 2; i <= 4; i++){  
       if(a[i] > max)
           max = a[i];
   }

   /* checking if max number is multiple of 3 */
   if(max % 3 == 0)
       printf("\nMax number %d is a multiple of 3\n", max);
   else
       printf("\nMax number %d is not a multiple of 3\n", max);
  

   return 0;
}


Execution and output:
Unix Terminal> ./a.out

Enter number 1 : 18

Enter number 2 : 29

Enter number 3 : 3

Enter number 4 : 56

Max number 56 is not a multiple of 3
Unix Terminal> ./a.out

Enter number 1 : 10

Enter number 2 : 18

Enter number 3 : 7

Enter number 4 : 4

Max number 18 is a multiple of 3
Unix Terminal>

Add a comment
Know the answer?
Add Answer to:
C Programming Read four numbers and find the largest value. Check if the largest value is...
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
ADVERTISEMENT