add 1 - 2
This commit is contained in:
parent
0bdac22c20
commit
c4981436af
25
pset5/1-numbers.c
Normal file
25
pset5/1-numbers.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
// To store answer
|
||||
int nums[10];
|
||||
long long n;
|
||||
int i = 0;
|
||||
|
||||
scanf("%lld", &n);
|
||||
while (n > 0) {
|
||||
nums[i] = n % 10;
|
||||
n /= 10;
|
||||
i++;
|
||||
}
|
||||
|
||||
for (int j = i - 1; j >= 0; j--) {
|
||||
if (j == 0) {
|
||||
printf("%i\n", nums[j]);
|
||||
} else {
|
||||
printf("%i ", nums[j]);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
32
pset5/2-swap.c
Normal file
32
pset5/2-swap.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <stdio.h>
|
||||
|
||||
// Function prototypes
|
||||
void swap(int *a, int *b);
|
||||
|
||||
int main(void) {
|
||||
// Initialize variables
|
||||
int n;
|
||||
int length = 0;
|
||||
int nums[10];
|
||||
|
||||
// Get input
|
||||
scanf("%d", &n);
|
||||
|
||||
// Tabulate nums[]
|
||||
while (n > 0) {
|
||||
nums[length] = n % 10;
|
||||
n /= 10;
|
||||
length++;
|
||||
}
|
||||
|
||||
// See if anything is wrong
|
||||
if (nums[0] == 0) {
|
||||
printf("The number cannot be changed.\n");
|
||||
} else { // Print answer
|
||||
for (int i = 0; i < length; i++) {
|
||||
printf("%i", nums[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue