How do I get only the units of that number

Asked

Viewed 46 times

-2

#include <stdio.h>
int main(){

    int hora,minuto,dia,mes,ano;
    scanf("%d",&hora);
    scanf("%d",&minuto);
    scanf("%d",&dia);
    scanf("%d",&mes);
    scanf("%d",&ano);
    printf("%02d:%02d %02d/%02d/%02d",hora,minuto,dia,mes,ano);
}

I want the year to be just the last two units, as I do?

  • Look already thought of receiving the year in a char vector, put in the format you want and then convert to int? if you find interesting show how. There may be another way, but I don’t know.

1 answer

1

The year has 4 digits, so divide the year by 1000 and take the rest of the division:

printf("%02d:%02d %02d/%02d/%02d",hora,minuto,dia,mes,(ano % 1000));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.