Write a C program accepts an integer and prints the integer after removing 0's at last.
Answers
Answered by
7
The given code 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;
}
- 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