Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<stdbool.h>
- // bin - двоичная, dec - десятичная, hexdec - шестнадцатеричная
- int binToOct() {
- }
- int decToOct() {
- }
- int hexdecToOct() {
- }
- int main(){
- int base, i, a_atoi;
- char a[10];
- scanf("%d %s", &base, a);
- a[6] = '\0';
- if (base != 2 && base != 10 && base != 16) {
- printf("Base is wrong");
- exit(0);
- }
- switch (base)
- {
- case 2:
- for (int i = 0; i <= sizeof(a); i++) {
- if (a[i] != 48 && a[i] != 49) {
- printf("Number is wrong");
- exit(0);
- }
- }
- break;
- case 10:
- for (int i = 0; i < sizeof(a); i++) {
- if (a[i] < 48 || a[i] > 57) {
- printf("Number is wrong");
- exit(0);
- }
- }
- break;
- case 16:
- for (int i = 0; i <= sizeof(a); i++) {
- if (a[i] < 48 || (a[i] < 65 && a[i] > 57) || a[i] > 70) { //65 A 70 F
- printf("Number is wrong");
- exit(0);
- }
- }
- break;
- default:
- //exit(0);
- break;
- }
- a_atoi = atoi(a);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement