Extracting the digits of a number, I want to extract the digits of this number using the following program

Draco D. :

I want to use this program to extract the digits of a number:

#include <stdio.h>

int main ()
{
  int a,b,c,d;
  printf("524");
  scanf("%d%d%d", &a,&b,&c);
  a=d%10;
  b=(d%10)/10;
  c=d/10;
  printf("Centenas:%d\nDecenas:%d\nUnidades:%d\n",a,b,c);
  return 0;
}
Jabberwocky :

Are you looking for this?

#include <stdio.h>

int main()
{
  int number;
  scanf("%d", &number);

  int hundreds = (number / 100) % 10;
  int tenths =( number / 10) % 10;
  int units = number % 10;

  printf("Centenas: %d\nDecenas: %d\nUnidades: %d\n", hundreds, tenths, units);
  return 0;
}

Example of input and output:

456
Centenas: 4
Decenas: 5
Unidades: 6

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=293470&siteId=1