Im in a C programming class and we are using guru on putty software. We also mus
ID: 3681654 • Letter: I
Question
Im in a C programming class and we are using guru on putty software. We also must use stdio.h and math.h. We must use user-defined functions and cannot use pointers, text input/output, or arrays. We can use for loops, while loops, do...while loops, summation, powers, if-else statements, switch, modulus, logical operators, (if this may clarify the restrictions. we can only use material up through chapter 6 of the textbook: Computer Science A Structured Programming Approach Using C by Behrouz A. Forouzan and Richard F. Gilberg)
Thanks in advance!
Given an integer value, the current number system of the integer (2-10), and the desired number system to which the value is to be converted (2-10), display the following:
1. The original number as input by the user along with its current number system (also known as its base).
2. The input number converted to the decimal number system (base 10).
3. The base 10 value from #2 after the ROT-5 algorithm has been applied to it (see below).
4. The base 10 value generated from #3 then converted to the desired number system as input by the user.
The ROT-5 algorithm does the following to a decimal number system (base 10) integer:
Digits from 0 to 4 will each be added with 5. • Digits from 5 to 9 will have 5 subtracted from each.
Example: The number 9036 would be 4581 after the ROT-5 algorithm is applied.
Example Execution #1: Enter a number: 674
Enter the base of the number: 10
Enter the desired base: 2
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Original Number (Base-10): 674
Original Base-10: 674
Rotated Base-10: 129
Converted Base- 2: 10000001
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Example Execution #2:
Enter a number: 10000001
Enter the base of the number: 2
Enter the desired base: 10
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Original Number (Base- 2): 10000001
Original Base-10: 129
Rotated Base-10: 674
Converted Base-10: 674
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Example Execution #3:
Enter a number: 1001
Enter the base of the number: 8
Enter the desired base: 2
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Original Number (Base- 8): 1001
Original Base-10: 513
Rotated Base-10: 68
Converted Base- 2: 1000100
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Example Execution #4:
Enter a number: 125
Enter the base of the number: 8
Enter the desired base: 10
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Original Number (Base- 8): 125
Original Base-10: 85
Rotated Base-10: 30
Converted Base-10: 30
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Example Execution #5:
Enter a number: 375
Enter the base of the number: 8
Enter the desired base: 5
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Original Number (Base- 8): 375
Original Base-10: 253
Rotated Base-10: 708
Converted Base- 5: 10313
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Explanation / Answer
#include <stdio.h>
int main()
{
printf("Enter a number:");
int num;
scanf("%d",&num);
printf("Enter the base of the number:");
int givenBase;
scanf("%d",&givenBase);
int desiredBase;
printf("Enter the desired base:");
scanf("%d",&desiredBase);
printf("Original Number (Base-%d): %d ",givenBase, num);
int num_base10=0;
int powe = 1;
while(num){
num_base10 += (powe*(num%10));
powe*=givenBase;
num/=10;
}
printf("Original Base-10: %d ",num_base10);
int rotated_base10=0;
powe=1;
while(num_base10)
{
int tem = (num_base10%10);
if(tem<5) tem+=5;
else tem-=5;
rotated_base10 += (tem*powe);
powe*=10;
num_base10/=10;
}
printf("Rotated Base-10: %d ", rotated_base10);
int desiredConversion=0;
powe = 1;
while(rotated_base10)
{
desiredConversion +=(powe*(rotated_base10%desiredBase));
powe*=10;
rotated_base10/=desiredBase;
}
printf("Converted Base-%d: %d ",desiredBase, desiredConversion);
return 0;
}