SHARE
TWEET

TASK 2/2

Mary_99 Jan 31st, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int lengthofnumber(int number){
  5.     int length=0;
  6.     int temp = number;
  7.     if(temp!=0)
  8.         while(temp){
  9.             temp = temp / 10;
  10.             length++;
  11.         }
  12.     else
  13.         length = 1;
  14.     return length;
  15. }
  16.  
  17. void finddigits(int number, int separate[]){
  18.     int length;
  19.     length = lengthofnumber(number);
  20.     int j=0;
  21.     int i;
  22.     for(i=length; i>0; i--){
  23.         separate[j] = number / pow(10, i-1);
  24.         separate[j] = separate[j]%10;
  25.         j++;
  26.     }
  27. }
  28.  
  29. int main() {
  30.     int i;
  31.     int number;
  32.     int separate[100];
  33.     int infinity = 1;
  34.     while(infinity){
  35.     printf("Insert a number: ");
  36.     scanf("%d", &number);
  37.         if(number>=0)
  38.             infinity = 0;
  39.     }
  40.     finddigits(number, separate);
  41.     int length;
  42.     length = lengthofnumber(number);
  43.     for(i=0; i<length; i++){
  44.         printf("%d \n", separate[i]);
  45.     }
  46.     return 0;
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top