Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Im in a C programming class and we are using guru on putty software. We also can

ID: 3681652 • Letter: I

Question

Im in a C programming class and we are using guru on putty software. We also can only 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>
#include<math.h>

//converting to base
int convertBase10(int base, int num){
int res=0,i=0;
while(num>0)
{
res=res+(num%10)*pow(base,i);
num=num/10;
i++;
}
return res;
}

//roatating number
void rotate(int num,int newBase){
int res=0,temp,i=0;
while(num>0)
{
temp = num%10;
if(temp < 5){
temp = temp+5;
}
else{
temp = temp-5;
}
res=res+(temp*10);
num=num/10;
i++;
}
printf(" Rotated Base-10: %d ",res);
convert(res,newBase);
}
//converting to required base
void convert(int num, int base){
int p,rem,digit,temp=0,i;
char arr[100];
p=num;
do
{
rem = p%base;
digit='0'+rem;
if(digit>'9')
digit=digit+7;
arr[temp]=digit;
temp++;
p=p/base;
} while(p!=0);
printf(" converted base %d : %d is ",base,num);
for(i=temp-1;i>=0;--i)
printf("%c",arr[i]);
}

int main()
{
//variables declared
int b,base2,n,i=0,ans=0;
//reading intital data
printf("Enter a number ");
scanf("%d",&n);
printf("Enter the base of the number ");
scanf("%d",&b);
printf("Enter the desired base: ");
scanf("%d",&base2);
//converting to base 10
ans = convertBase10(b,n);
printf(" Original Number (Base-%d):%d",b,n);
printf(" Original Base-10: %d",ans);
//rotating
rotate(ans,base2);
//converting to required base
return 0;
}