🔒 Closed Pwede pa hingi ng tulong

Status
Not open for further replies.

PHC_LaCe12

Forum Master
pwede po pasolve to ng actitity namin

c programming po

328102626_488082666862283_5096299259568755940_n.webp


salamat sa Dios
 
'di ko na din matandaan ang c paps. hehehe.. tanong ko kay ᑕᕼᗩTGᑭT 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;
}
 
'di ko na din matandaan ang c paps. hehehe.. tanong ko kay ᑕᕼᗩTGᑭT 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 ᑕᕼᗩTGᑭT
 
Status
Not open for further replies.

About this Thread

  • 4
    Replies
  • 408
    Views
  • 4
    Participants
Last reply from:
f0rbidd3n_sin2

Trending Topics

Online now

Members online
1,101
Guests online
3,168
Total visitors
4,269

Forum statistics

Threads
2,278,156
Posts
28,981,276
Members
1,228,248
Latest member
Taguroooo
Back
Top