I am solving a question to calculate LCM and highest prime number from a set of 4 integers. I have trouble solving exceptions w.r.t scanf such as
- some inputs are not integers
- if there are more/less than 4 inputs
- if inputs not entered with commas or
- if there is no prime number from input
I tried using the following code:
if((scanf("%d,%d,%d,%d", &num1,&num2,&num3,&num4))!=4) /* for 4 input verification */
if((scanf("%d,%d,%d,%d", &num1,&num2,&num3,&num4))<4) /* for non-integer inputs */
if((scanf("%d,%d,%d,%d", &num1,&num2,&num3,&num4))<4) /* used comma in between %d for comma check, but how to generate error if input is without commas. */
and how to identify prime number & how to implement the program using multiple threads.