-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencryption.c
More file actions
40 lines (32 loc) · 888 Bytes
/
encryption.c
File metadata and controls
40 lines (32 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// The program asks the user to enter an encrypted 3-digit code and then prints the real 3-digit code.
//
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(void){
int code, firstDigit, lastDigit, middleDigit, newMiddleDigit, exponent;
//Prompts user to enter code
printf("Enter an encrypted 3-digit code: ");
scanf("%d", &code);
//Determines the exponent for which the number should be divided by
if(code < 100){
exponent = 1;
} else {
exponent = 2;
}
//Checks if there the first number is 0
if(code < 100){
firstDigit = 0;
} else {
firstDigit = code / pow(10, exponent);
}
//Gets the last number
lastDigit = code % 10;
//Gets the middle number
middleDigit = (code / 10) % 10;
newMiddleDigit = abs(middleDigit - 9);
//Prints the code
printf("The real 3-digit code is: %d%d%d\n", lastDigit, newMiddleDigit, firstDigit);
return 0;
}