Print multiples of Unit Digit of Given Number in C Program


Input number N and fetch the unit digit of a given number and display the multiples of that number.

Input − N=326

Output − unit digit is 6 and its multiples are 2 and 3

Note − Unit digit of any number can be fetched by calculating the %10 with that number

For example − if your’re given with a number N and you need to find its unit digit that

you can use N%10 it will return you unit digit of number N

ALGORITHM

START
Step 1 -> Declare start variables num, num2 and i
Step 2 -> input number num
Step 3 -> store num%10 in num2 to fetch unit digit
Step 4 -> print num2
Step 5 -> Loop For i=2 and i<=num2/2 and ++i
   IF num2%i=0\
      Print i
   End IF
Step 6 -> End For Loop
STOP

Example

#include<stdio.h>
int main() {
   int num,num2,i;
   printf("\nenter a number");
   scanf("%d" , &num);
   num2=num%10;    //storing unit digit in num2
   printf("\n unit digit of %d is: %d",num,num2);
      for(i=2;i<=num2/2;++i) {    //loop till half of unit digit
      if(num2%i==0) { //calculate multiples
         printf("\n multiple of %d is : %d ",num2,i);
      }
   }
return 0;
}

Output

If we run above program then it will generate following output

enter a number329
unit digit of 329 is: 9
multiple of 9 is : 3
raja
Published on 08-Aug-2019 12:20:18
Advertisements