How can I handle stray characters input as shown in below code snippet
#include <stdio.h>
int main ()
{
    int i, j=0;
    while (j <3)
    {
        printf("\n Enter the number to be displayed ");
        scanf("%d",&i);
        printf("\n The number to be displayed is %d \n", i);
        j++;
    }
    return 0;
}
Output
philipa@hq1-up-swe-01{1436}: ./a.out
 Enter the number to be displayed 45/
 The number to be displayed is 45
 Enter the number to be displayed
 The number to be displayed is 45
 Enter the number to be displayed
 The number to be displayed is 45
Here '/' is added mistakenly. I want to flush this '/' before it taken as input for next loop. How can I handle this situation?
 
    