The goal of the program is to switch the 2nd and 4th digit in a double(before comma). Lets say you have 28492.45, it should become 29482.45. The program is working fine. I want to add another option, where the user input is a two digit number(before comma) like 56.78, the 3th and 4th digit should be considered as 5600.78. The switched number should be then 5006. Same goes for a 3 digit number. How can i implement this?
Code:
int main() {
double number;
scanf("%lf", &number);
//printf("%.4f", number);
char arr[sizeof(number)];
snprintf(arr, sizeof(number) + 1, "%f", number);
char aux = arr[1];
arr[1] = arr[3];
arr[3] = aux;
number = atof(arr);
printf("%.4f\n", number);
return 0;
}