资源描述
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
#include<malloc.h>
typedef struct change
{
int data;
struct change *next;
}N;
typedef struct
{
N *head;
int n;
}ES;
void es()
{
N *front,*rear,*head;
ES p;
int count,sum=0;
int i;
p.n=0;
printf("\n\n\n\n\n\n\n\t\t\t\t欢迎使用二-十进制转换功能!");
Sleep(1000);
system("cls");
printf("\n\n\n\n\n\n\n\t\t\t请输入要转换的二进制数据:\n\n");
head=front=rear=(N *)malloc(sizeof(N));
scanf("%d",&rear->data);
for(;rear->data<2&&rear->data>-1;)
{
p.n=p.n+1;
rear=(N *)malloc(sizeof(N));
scanf("%d",&rear->data);
if(rear->data<2&&rear->data>-1)
{
front->next=rear;
front=rear;
}
else
front->next=NULL;
}
front=head;
do
{
count=1;
if(front->data==1)
for(i=1;i<p.n;i++)
count=count*front->data*2;
else
count=0;
sum=sum+count;
p.n=p.n-1;
front=front->next;
}
while(front!=NULL);
printf("%d\n",sum);
}
void se()
{
int data;
int i,j;
N *top,*bottom,*head;
ES p;
printf("\n\n\n\n\n\n\n\t\t\t\t欢迎使用十-二进制转换功能!");
Sleep(1000);
system("cls");
printf("\n\n\n\n\n\n\n\t\t\t请输入要转换的十进制数据:\n\n");
scanf("%d",&data);
i=data%2;
j=data/2;
if(i!=data)
{
head=top=bottom=(N *)malloc(sizeof(N));
top->data=i;
top->next=NULL;
p.n=p.n+1;
do
{
data=j;
i=data%2;
j=data/2;
top=(N *)malloc(sizeof(N));
top->data=i;
p.n=p.n+1;
top->next=bottom;
bottom=top;
}
while(j!=0);
head=top;
printf("转换成的二进制数据为:");
for(;top!=NULL;)
{
printf("%d",top->data);
top=top->next;
}
}
else
{
printf("转换成的二进制数据为:");
printf("%d\n",data);
}
}
void menu()
{
char choice;
int d;
do
{
d=0;
printf("\n");
printf("\t\3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 请选择功能: \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 a. 二进制转换十进制功能 \3\n");
printf("\t\3 \3\n");
printf("\t\3 b. 十进制转换二进制功能 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3\n");
scanf("%c",&choice);
system("cls");
switch(choice)
{
case'a':
es();
break;
case'b':
se();
break;
case'A':
es();
break;
case'B':
se();
break;
default:
d=1;
printf("\n\n\n\n\n\n\n\t\t\t\t选择有误!请重新输入!\n\n\n");
Sleep(1000);
getchar();
system("cls");
}
}
while(d);
}
void main()
{
printf("\n");
system("color 4f");
printf("\t\3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 欢迎使用二-十进制转换系统 \3\n");
printf("\t\3 \3\n");
printf("\t\3 谢谢! \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3\n");
printf("按任意键继续:");
getch();
system("cls");
menu();
}
展开阅读全文