Advertisement
MichalWalczak

Zad 23

Mar 30th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <math.h>
  4. //Niestety program ma problem z obliczaniem ilosci cyfr w liczbach takich jak 1000, 100000 i innych potęgach liczby 10. Nie udalo mi sie tego naprawic.
  5. using namespace std;
  6. int a;
  7. int LICZBA_CYFR(int x){
  8. int y=1;
  9. double liczba;
  10. while(true){
  11. if(x>=pow(10,y-1)&&x<pow(10,y)){
  12.     return y;
  13.     break;
  14. }
  15. else{
  16.     y++;
  17. }
  18. }
  19. }
  20. int main()
  21. {
  22.     cout << "Podaj liczbe, aby sprawdzic ile ma cyfr" << endl;
  23.     cin>>a;
  24.     if(a<0){
  25.         a=abs(a);
  26.         cout<<LICZBA_CYFR(a);
  27.     }
  28.     else if(a==0){
  29.         cout<<"0 to jedna cyfra :)";
  30.     }
  31.     else{
  32.     cout<<LICZBA_CYFR(a);
  33.     }
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement