Home  >  Article  >  Backend Development  >  Print single digit multiples of a given number in C program

Print single digit multiples of a given number in C program

王林
王林forward
2023-09-06 11:17:151203browse

Print single digit multiples of a given number in C program

Enter the number N, take out the single digit of the given number and display the multiple of the number.

Input− N=326

Output− The single digit is 6, and its multiples are 2 and 3

Note − The single digit of any number can be obtained by calculating You can use N it will return you the single digit 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("</p><p>enter a number");
   scanf("%d" , &num);
   num2=num%10;    //storing unit digit in num2
   printf("</p><p> 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("</p><p> multiple of %d is : %d ",num2,i);
      }
   }
return 0;
}

Output

If we run the above program , then it will generate the following output

enter a number329
unit digit of 329 is: 9
multiple of 9 is : 3

The above is the detailed content of Print single digit multiples of a given number in C program. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete