Computer Science, asked by suruthiit2019, 2 months ago

Write a C program accepts an integer and prints the integer after removing 0's at last.​

Answers

Answered by anindyaadhikari13
7

\texttt{\textsf{\large{\underline{Solution}:}}}

The given co‎‎de is written in C.

#include <stdio.h>

int main() {

   int n;

   printf("Enter a number: ");

   scanf("%d",&n);

   while(n%10==0)

       n/=10;

   printf("The number after removing zeros at last is: %d",n);

   return 0;

}

\texttt{\textsf{\large{\underline{Explanation}:}}}

  • If a number is divisible by 10, then it must have 0 at its end. Here, the loop iterates till n%10==0 is true i.e., it iterates only when the number is divisible by 10. After each iteration, number is divided by 10 so as to remove the zeros.

See the attachment for output.

Attachments:
Similar questions