请大家帮写画一个C语言的流程图
发布网友
发布时间:2022-04-29 15:39
我来回答
共2个回答
热心网友
时间:2023-10-16 05:21
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
/* 显示帮助信息 */
void help()
{
printf("\nUsage : Translate the number between two number systems\n");
printf("Syntex: TNS <number> <radix1> <radix2>\n");
exit(0);
}
/* 显示错误信息 */
void printerror(errno,num,base1)
char errno,*num,*base1;
{
switch (errno) {
case 1 : printf("\nError : Origin number %s(%s) is valid !!!\n",num,base1);
break;
case 2 : printf("\nError : radix (%s) is invalid !!!\n%s\n",base1,
"Correct : radix>=2 and radix <=36");
break;
}
help();
}
/* 数制转换函数 */
void transnum(num,base1,base2)
char *num,*base1,*base2;
{
int i,k,l,m,j,ibase1,ibase2;
long inum=0;
char temp[20];
double r=0;
i = strlen(num); /* 数值的长度 */
ibase1 = atoi(base1); /* 数基1 */
if ((ibase1<2) || (ibase1>36)) printerror(2,"",base1); /* 有效吗? */
ibase2 = atoi(base2); /* 数基2 */
if ((ibase2<2) || (ibase2>36)) printerror(2,"",base2); /* 有效吗? */
for (j=0;j<i;j++) {
r = pow(ibase1,i-j-1); /* 计算数基的幂指数 */
if (ibase1<=10) l =''9'' - (10 - ibase1); /* 计算有效的数范围 */
else {
m = ''a'' + (ibase1 - 11);
l = ''9'';
}
if ((num[j]>=48) && (num[j]<=l)) /* 求每位数字的十进制值 */
k = num[j]-48;
else if (ibase1>10) {
/* 求每个字母所代表的十进制值 */
if ((num[j]>=''A'') && (num[j]<=m - 32))
k = num[j] - ''A''+10;
else if ((num[j]>=''a'') && (num[j]<=m))
k = num[j] - ''a''+10;
else printerror(1,num,base1);
}
else printerror(1,num,base1);
inum += k * (int) r; /* 累加计算结果 */
}
/* 输出转换结果 */
printf("%s(%d) = %s(%d)\n",num,ibase1,ltoa(inum,temp,ibase2),ibase2);
}
/* 主程序 */
main(argc,argv)
int argc;
char *argv[];
{
static char num[10],base1[10],base2[10];
printf("(TNS)Translator of Number System 1.0 Copyright (c) 1995 Dong Zhanshan\n");
switch (argc) {
case 1:
case 2:
case 3: help();
break;
case 4: strcpy(num,argv[1]);
strcpy(base1,argv[2]);
strcpy(base2,argv[3]);
transnum(num,base1,base2);
}
热心网友
时间:2023-10-16 05:22
老大,什么题啊?
热心网友
时间:2023-10-16 05:21
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
/* 显示帮助信息 */
void help()
{
printf("\nUsage : Translate the number between two number systems\n");
printf("Syntex: TNS <number> <radix1> <radix2>\n");
exit(0);
}
/* 显示错误信息 */
void printerror(errno,num,base1)
char errno,*num,*base1;
{
switch (errno) {
case 1 : printf("\nError : Origin number %s(%s) is valid !!!\n",num,base1);
break;
case 2 : printf("\nError : radix (%s) is invalid !!!\n%s\n",base1,
"Correct : radix>=2 and radix <=36");
break;
}
help();
}
/* 数制转换函数 */
void transnum(num,base1,base2)
char *num,*base1,*base2;
{
int i,k,l,m,j,ibase1,ibase2;
long inum=0;
char temp[20];
double r=0;
i = strlen(num); /* 数值的长度 */
ibase1 = atoi(base1); /* 数基1 */
if ((ibase1<2) || (ibase1>36)) printerror(2,"",base1); /* 有效吗? */
ibase2 = atoi(base2); /* 数基2 */
if ((ibase2<2) || (ibase2>36)) printerror(2,"",base2); /* 有效吗? */
for (j=0;j<i;j++) {
r = pow(ibase1,i-j-1); /* 计算数基的幂指数 */
if (ibase1<=10) l =''9'' - (10 - ibase1); /* 计算有效的数范围 */
else {
m = ''a'' + (ibase1 - 11);
l = ''9'';
}
if ((num[j]>=48) && (num[j]<=l)) /* 求每位数字的十进制值 */
k = num[j]-48;
else if (ibase1>10) {
/* 求每个字母所代表的十进制值 */
if ((num[j]>=''A'') && (num[j]<=m - 32))
k = num[j] - ''A''+10;
else if ((num[j]>=''a'') && (num[j]<=m))
k = num[j] - ''a''+10;
else printerror(1,num,base1);
}
else printerror(1,num,base1);
inum += k * (int) r; /* 累加计算结果 */
}
/* 输出转换结果 */
printf("%s(%d) = %s(%d)\n",num,ibase1,ltoa(inum,temp,ibase2),ibase2);
}
/* 主程序 */
main(argc,argv)
int argc;
char *argv[];
{
static char num[10],base1[10],base2[10];
printf("(TNS)Translator of Number System 1.0 Copyright (c) 1995 Dong Zhanshan\n");
switch (argc) {
case 1:
case 2:
case 3: help();
break;
case 4: strcpy(num,argv[1]);
strcpy(base1,argv[2]);
strcpy(base2,argv[3]);
transnum(num,base1,base2);
}
热心网友
时间:2023-10-16 05:21
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
/* 显示帮助信息 */
void help()
{
printf("\nUsage : Translate the number between two number systems\n");
printf("Syntex: TNS <number> <radix1> <radix2>\n");
exit(0);
}
/* 显示错误信息 */
void printerror(errno,num,base1)
char errno,*num,*base1;
{
switch (errno) {
case 1 : printf("\nError : Origin number %s(%s) is valid !!!\n",num,base1);
break;
case 2 : printf("\nError : radix (%s) is invalid !!!\n%s\n",base1,
"Correct : radix>=2 and radix <=36");
break;
}
help();
}
/* 数制转换函数 */
void transnum(num,base1,base2)
char *num,*base1,*base2;
{
int i,k,l,m,j,ibase1,ibase2;
long inum=0;
char temp[20];
double r=0;
i = strlen(num); /* 数值的长度 */
ibase1 = atoi(base1); /* 数基1 */
if ((ibase1<2) || (ibase1>36)) printerror(2,"",base1); /* 有效吗? */
ibase2 = atoi(base2); /* 数基2 */
if ((ibase2<2) || (ibase2>36)) printerror(2,"",base2); /* 有效吗? */
for (j=0;j<i;j++) {
r = pow(ibase1,i-j-1); /* 计算数基的幂指数 */
if (ibase1<=10) l =''9'' - (10 - ibase1); /* 计算有效的数范围 */
else {
m = ''a'' + (ibase1 - 11);
l = ''9'';
}
if ((num[j]>=48) && (num[j]<=l)) /* 求每位数字的十进制值 */
k = num[j]-48;
else if (ibase1>10) {
/* 求每个字母所代表的十进制值 */
if ((num[j]>=''A'') && (num[j]<=m - 32))
k = num[j] - ''A''+10;
else if ((num[j]>=''a'') && (num[j]<=m))
k = num[j] - ''a''+10;
else printerror(1,num,base1);
}
else printerror(1,num,base1);
inum += k * (int) r; /* 累加计算结果 */
}
/* 输出转换结果 */
printf("%s(%d) = %s(%d)\n",num,ibase1,ltoa(inum,temp,ibase2),ibase2);
}
/* 主程序 */
main(argc,argv)
int argc;
char *argv[];
{
static char num[10],base1[10],base2[10];
printf("(TNS)Translator of Number System 1.0 Copyright (c) 1995 Dong Zhanshan\n");
switch (argc) {
case 1:
case 2:
case 3: help();
break;
case 4: strcpy(num,argv[1]);
strcpy(base1,argv[2]);
strcpy(base2,argv[3]);
transnum(num,base1,base2);
}
热心网友
时间:2023-10-16 05:22
老大,什么题啊?
热心网友
时间:2023-10-16 05:21
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
/* 显示帮助信息 */
void help()
{
printf("\nUsage : Translate the number between two number systems\n");
printf("Syntex: TNS <number> <radix1> <radix2>\n");
exit(0);
}
/* 显示错误信息 */
void printerror(errno,num,base1)
char errno,*num,*base1;
{
switch (errno) {
case 1 : printf("\nError : Origin number %s(%s) is valid !!!\n",num,base1);
break;
case 2 : printf("\nError : radix (%s) is invalid !!!\n%s\n",base1,
"Correct : radix>=2 and radix <=36");
break;
}
help();
}
/* 数制转换函数 */
void transnum(num,base1,base2)
char *num,*base1,*base2;
{
int i,k,l,m,j,ibase1,ibase2;
long inum=0;
char temp[20];
double r=0;
i = strlen(num); /* 数值的长度 */
ibase1 = atoi(base1); /* 数基1 */
if ((ibase1<2) || (ibase1>36)) printerror(2,"",base1); /* 有效吗? */
ibase2 = atoi(base2); /* 数基2 */
if ((ibase2<2) || (ibase2>36)) printerror(2,"",base2); /* 有效吗? */
for (j=0;j<i;j++) {
r = pow(ibase1,i-j-1); /* 计算数基的幂指数 */
if (ibase1<=10) l =''9'' - (10 - ibase1); /* 计算有效的数范围 */
else {
m = ''a'' + (ibase1 - 11);
l = ''9'';
}
if ((num[j]>=48) && (num[j]<=l)) /* 求每位数字的十进制值 */
k = num[j]-48;
else if (ibase1>10) {
/* 求每个字母所代表的十进制值 */
if ((num[j]>=''A'') && (num[j]<=m - 32))
k = num[j] - ''A''+10;
else if ((num[j]>=''a'') && (num[j]<=m))
k = num[j] - ''a''+10;
else printerror(1,num,base1);
}
else printerror(1,num,base1);
inum += k * (int) r; /* 累加计算结果 */
}
/* 输出转换结果 */
printf("%s(%d) = %s(%d)\n",num,ibase1,ltoa(inum,temp,ibase2),ibase2);
}
/* 主程序 */
main(argc,argv)
int argc;
char *argv[];
{
static char num[10],base1[10],base2[10];
printf("(TNS)Translator of Number System 1.0 Copyright (c) 1995 Dong Zhanshan\n");
switch (argc) {
case 1:
case 2:
case 3: help();
break;
case 4: strcpy(num,argv[1]);
strcpy(base1,argv[2]);
strcpy(base2,argv[3]);
transnum(num,base1,base2);
}
热心网友
时间:2023-10-16 05:21
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
/* 显示帮助信息 */
void help()
{
printf("\nUsage : Translate the number between two number systems\n");
printf("Syntex: TNS <number> <radix1> <radix2>\n");
exit(0);
}
/* 显示错误信息 */
void printerror(errno,num,base1)
char errno,*num,*base1;
{
switch (errno) {
case 1 : printf("\nError : Origin number %s(%s) is valid !!!\n",num,base1);
break;
case 2 : printf("\nError : radix (%s) is invalid !!!\n%s\n",base1,
"Correct : radix>=2 and radix <=36");
break;
}
help();
}
/* 数制转换函数 */
void transnum(num,base1,base2)
char *num,*base1,*base2;
{
int i,k,l,m,j,ibase1,ibase2;
long inum=0;
char temp[20];
double r=0;
i = strlen(num); /* 数值的长度 */
ibase1 = atoi(base1); /* 数基1 */
if ((ibase1<2) || (ibase1>36)) printerror(2,"",base1); /* 有效吗? */
ibase2 = atoi(base2); /* 数基2 */
if ((ibase2<2) || (ibase2>36)) printerror(2,"",base2); /* 有效吗? */
for (j=0;j<i;j++) {
r = pow(ibase1,i-j-1); /* 计算数基的幂指数 */
if (ibase1<=10) l =''9'' - (10 - ibase1); /* 计算有效的数范围 */
else {
m = ''a'' + (ibase1 - 11);
l = ''9'';
}
if ((num[j]>=48) && (num[j]<=l)) /* 求每位数字的十进制值 */
k = num[j]-48;
else if (ibase1>10) {
/* 求每个字母所代表的十进制值 */
if ((num[j]>=''A'') && (num[j]<=m - 32))
k = num[j] - ''A''+10;
else if ((num[j]>=''a'') && (num[j]<=m))
k = num[j] - ''a''+10;
else printerror(1,num,base1);
}
else printerror(1,num,base1);
inum += k * (int) r; /* 累加计算结果 */
}
/* 输出转换结果 */
printf("%s(%d) = %s(%d)\n",num,ibase1,ltoa(inum,temp,ibase2),ibase2);
}
/* 主程序 */
main(argc,argv)
int argc;
char *argv[];
{
static char num[10],base1[10],base2[10];
printf("(TNS)Translator of Number System 1.0 Copyright (c) 1995 Dong Zhanshan\n");
switch (argc) {
case 1:
case 2:
case 3: help();
break;
case 4: strcpy(num,argv[1]);
strcpy(base1,argv[2]);
strcpy(base2,argv[3]);
transnum(num,base1,base2);
}
热心网友
时间:2023-10-16 05:22
老大,什么题啊?
热心网友
时间:2023-10-16 05:22
老大,什么题啊?
热心网友
时间:2023-10-16 05:22
老大,什么题啊?