Week1 Assignment

This commit is contained in:
Citlali del Rey 2024-01-31 15:37:05 -08:00
parent 46ffca0872
commit 3517cb4e8d
Signed by: nullobsi
GPG Key ID: 933A1F44222C2634
1 changed files with 32 additions and 0 deletions

32
Week1/q1.c Normal file
View File

@ -0,0 +1,32 @@
#include<stdio.h>
int main() {
// scan integer from input
int x;
scanf("%d", &x);
// Get the 5 digits, starting from 1s place
int ones = x %10;
x/=10;
int tens = x % 10;
x/=10;
int hundreds = x % 10;
x/=10;
int thousands = x % 10;
x/=10;
int tenthousands = x % 10;
// In reverse order, create the reversed number.
int reversed = tenthousands
+ 10*thousands
+ 100*hundreds
+ 1000*tens
+ 10000*ones;
// Output number.
printf("%d\n", reversed);
}