Home > Backend Development > C++ > body text

Print single digit multiples of a given number in C program

王林
Release: 2023-09-06 11:17:15
forward
1247 people have browsed it

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
Copy after login

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;
}
Copy after login

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
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template