What's new

Pwede pa hingi ng tulong

PHC_LaCe12

Forum Master
Elite
Joined
Sep 2, 2015
Posts
6,242
Solutions
23
Reaction
35,192
Points
4,987
pwede po pasolve to ng actitity namin

c programming po

328102626_488082666862283_5096299259568755940_n.png


salamat sa Dios
 

Attachments

'di ko na din matandaan ang c paps. hehehe.. tanong ko kay chatgpt lols

#include <stdio.h>
#include <math.h>

int to_decimal(char *num, int base_from) {
int decimal = 0;
int length = strlen(num);
for (int i = 0; num != '\0'; i++) {
int digit = (num >= '0' && num <= '9') ? (num - '0') : (num - 'A' + 10);
decimal += digit * pow(base_from, length - i - 1);
}
return decimal;
}

void to_base(int num, int base_to) {
char result[50];
int index = 0;
while (num > 0) {
int remainder = num % base_to;
result[index++] = (remainder >= 0 && remainder <= 9) ? (remainder + '0') : (remainder + 'A' - 10);
num /= base_to;
}
for (int i = index - 1; i >= 0; i--) {
printf("%c", result);
}
printf("\n");
}

int main() {
char num[50];
int base_from, base_to;
printf("Enter a number: ");
scanf("%s", num);
printf("Enter the base of the number: ");
scanf("%d", &base_from);
printf("Enter the desired base: ");
scanf("%d", &base_to);
int decimal = to_decimal(num, base_from);
printf("%s in base %d is %d in base 10\n", num, base_from, decimal);
printf("%s in base %d is ", num, base_from);
to_base(decimal, base_to);
return 0;
}
 
Last edited:
'di ko na din matandaan ang c paps. hehehe.. tanong ko kay chatgpt lols

#include <stdio.h>
#include <math.h>

int to_decimal(char *num, int base_from) {
int decimal = 0;
int length = strlen(num);
for (int i = 0; num != '\0'; i++) {
int digit = (num >= '0' && num <= '9') ? (num - '0') : (num - 'A' + 10);
decimal += digit * pow(base_from, length - i - 1);
}
return decimal;
}

void to_base(int num, int base_to) {
char result[50];
int index = 0;
while (num > 0) {
int remainder = num % base_to;
result[index++] = (remainder >= 0 && remainder <= 9) ? (remainder + '0') : (remainder + 'A' - 10);
num /= base_to;
}
for (int i = index - 1; i >= 0; i--) {
printf("%c", result);
}
printf("\n");
}

int main() {
char num[50];
int base_from, base_to;
printf("Enter a number: ");
scanf("%s", num);
printf("Enter the base of the number: ");
scanf("%d", &base_from);
printf("Enter the desired base: ");
scanf("%d", &base_to);
int decimal = to_decimal(num, base_from);
printf("%s in base %d is %d in base 10\n", num, base_from, decimal);
printf("%s in base %d is ", num, base_from);
to_base(decimal, base_to);
return 0;
}
Eto lods try mo galing chatGPT
 
Back
Top