Computer >> 컴퓨터 >  >> 프로그램 작성 >> C 프로그래밍

C 프로그램에서 주어진 숫자의 단위 자릿수의 배수 인쇄

<시간/>

숫자 N을 입력하고 주어진 숫자의 단위 자릿수를 가져와 그 숫자의 배수를 표시합니다.

입력 - N=326

출력 - 단위 자릿수는 6이고 배수는 2와 3입니다.

참고 − 해당 숫자로 %10을 계산하여 임의의 숫자의 단위 자릿수를 가져올 수 있습니다.

예를 들어 - 숫자 N이 주어지고 해당 단위 자릿수를 찾아야 하는 경우

N%10을 사용하면 숫자 N의 단위 자릿수를 반환합니다.

알고리즘

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

예시

#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;
}

출력

위의 프로그램을 실행하면 다음 출력이 생성됩니다.

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