Answer to Question #255084 in C++ for Andi

Question #255084
How many zeroes are there after the last non-zero digit of a million? a trillion? To easily identify that, let us make a program to count and print the number of zeroes after the last non-zero digit of a number. For example, in 20400, there are 2 zeroes after the last non-zero digit of the number, 4. Are you up for this challenge?
1
Expert's answer
2021-10-22T16:47:54-0400
#include<iostream>
#include<math.h>
using namespace std;


int main(){
	int x = 0;
	float z;
	cout<<"Enter a number: ";
	cin>>z; 
	for(int k = 0;k <100;k++){
	
	 z = z/10;
	if(z == floor(z)){
	x++;
	}else{
	
	break;
	}
	}
	cout<<"The number of zeros is: "<<x<<endl;
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS