C语言
将十六进制数转换成十进制数的函数
课程设计任务书
学 院 物电学院 专 业 电子信息科学与技术 学 生 姓 名 张三 学 号 **** 设 计 题 目 编程技术基础实训
内容及要求:
利用C语言编写下题的代码。
题目名称:设计将十六进制数转换成十进制数的函数和员工信息管理程序。
内容及要求:
1、十六进制转换成十进制数:写一个函数,输入一个十六进制数,输出相应的十进制数。 。
软件开发环境
Windows XP,TC2.0或Visual C++ 6.0
进度安排:
第18周:
1(算法设计
2(编写程序代码
3(调试程序
4(答辩、验收程序
指导教师(签字): 学院院长(签字):
年 月 日 年 月 日
feel free to listen to their voices and help the masses solve problems, we were officially opened on May 10 "12345" Mayor calls, formulated rules and regulations, equipped with a full-time staff, a 24-hour on-duty system, people to call to receive, reply, action, reminders, feedback and so on. By year end, handled the crowd calls 1076, 94.7% feedback rate. By Mayor calls active coordination to solve a large number of bears on the immediate interests of the people and issues of great lives, but also for leadership research and decision to collect a lot of good ideas and suggestions, by all sectors of the community alike. Second, start Municipal Government Affairs Hall built. On May 11, we built and launched the city-government lobby, were settled in 12 departments, strict implementation of first asking duty system, service system, system of gratuitous, "receiving, internal coordination, head of the window handle, limited time concluded" one-stop service. By the end of today to accept various types of 3,273, originally of up to 100%. Running Government Affairs Hall, the convenience of the masses, promoting open Government, improve the investment environment and solve their practical problems, and so did a lot of work, masses, serve the community for the Government to play a very good "window, link, model". Third, create a city government public affairs network. We rely on the Government Web site, was completed on May 24, the province's first public affairs network. Over
一、题目要求
题目名称:设计将十六进制数转换成十进制数的函数和员工信息管理程序。
内容:
1、十六进制转换成十进制数:写一个函数,输入一个十六进制数,输出相应的十进制
数。
要求:
利用C语言编写上述程序,开发环境可采用Turbo C 2.0 或Visual C++ 6.0等。
feel free to listen to their voices and help the masses solve problems, we were officially opened on May 10 "12345" Mayor calls, formulated rules and regulations, equipped with a full-time staff, a 24-hour on-duty system, people to call to receive, reply, action, reminders, feedback and so on. By year end, handled the crowd calls 1076, 94.7% feedback rate. By Mayor calls active coordination to solve a large number of bears on the immediate interests of the people and issues of great lives, but also for leadership research and decision to collect a lot of good ideas and suggestions, by all sectors of the community alike. Second, start Municipal Government Affairs Hall built. On May 11, we built and launched the city-government lobby, were settled in 12 departments, strict implementation of first asking duty system, service system, system of gratuitous, "receiving, internal coordination, head of the window handle, limited time concluded" one-stop service. By the end of today to accept various types of 3,273, originally of up to 100%. Running Government Affairs Hall, the convenience of the masses, promoting open Government, improve the investment environment and solve their practical problems, and so did a lot of work, masses, serve the community for the Government to play a very good "window, link, model". Third, create a city government public affairs network. We rely on the Government Web site, was completed on May 24, the province's first public affairs network. Over
No. 1
二、算法设计
1、十六进制转换成十进制数:写一个函数,输入一个十六进制数,输出相应的十进制数。
(1)把输入的十六进制数看成一个数组(char s[N]),十六进制各个位的字符代为相应数组的元素(s[i])。
(2)写出主函数通过调用将十六进制数转为十进制数的函数(fun),实现将十六进制数转为十进制数。
(3)程序
图如下图1
开始
输入十六进制数字符串s[N]
S[i]是否大于10
t=s[i]-‘a’+10 t=s[i]-‘0’
sum=sum*16+t
i=0,i++
i<=N?
输出十进制结果sum
结束
程序
1
三、编程实现
程序的具体C语言代码如下: feel free to listen to their voices and help the masses solve problems, we were officially opened on May 10 "12345" Mayor calls, formulated rules and regulations, equipped with a full-time staff, a 24-hour on-duty system, people to call to receive, reply, action, reminders, feedback and so on. By year end, handled the crowd calls 1076, 94.7% feedback rate. By Mayor calls active coordination to solve a large number of bears on the immediate interests of the people and issues of great lives, but also for leadership research and decision to collect a lot of good ideas and suggestions, by all sectors of the community alike. Second, start Municipal Government Affairs Hall built. On May 11, we built and launched the city-government lobby, were settled in 12 departments, strict implementation of first asking duty system, service system, system of gratuitous, "receiving, internal coordination, head of the window handle, limited time concluded" one-stop service. By the end of today to accept various types of 3,273, originally of up to 100%. Running Government Affairs Hall, the convenience of the masses, promoting open Government, improve the investment environment and solve their practical problems, and so did a lot of work, masses, serve the community for the Government to play a very good "window, link, model". Third, create a city government public affairs network. We rely on the Government Web site, was completed on May 24, the province's first public affairs network. Over
沈阳理工大学
第1题:
#include
long fun(char*s); #define N 50
void main()
{
long m;
char s[N];
printf("输入十六进制数:");
scanf("%s",s);
m=fun(s);
printf("十进制数为:%ld",m); }
long fun(char*s) {
int i,t;
long sum=0;
for(i=0;s[i];i++)
{
if(s[i]<='9')t=s[i]-'0';
else t=s[i]-'a'+10;
sum=sum*16+t;
}
return sum;
}
四、结果分析
第1题:
程序运行结果如图1:
feel free to listen to their voices and help the masses solve problems, we were officially opened on May 10 "12345" Mayor calls, formulated rules and regulations, equipped with a full-time staff, a 24-hour on-duty system, people to call to receive, reply, action, reminders, feedback and so on. By year end, handled the crowd calls 1076, 94.7% feedback rate. By Mayor calls active coordination to solve a large number of bears on the immediate interests of the people and issues of great lives, but also for leadership research and decision to collect a lot of good ideas and suggestions, by all sectors of the community alike. Second, start Municipal Government Affairs Hall built. On May 11, we built and launched the city-government lobby, were settled in 12 departments, strict implementation of first asking duty system, service system, system of gratuitous, "receiving, internal coordination, head of the window handle, limited time concluded" one-stop service. By the end of today to accept various types of 3,273, originally of up to 100%. Running Government Affairs Hall, the convenience of the masses, promoting open Government, improve the investment environment and solve their practical problems, and so did a lot of work, masses, serve the community for the Government to play a very good "window, link, model". Third, create a city government public affairs network. We rely on the Government Web site, was completed on May 24, the province's first public affairs network. Over
No. 3
图1 程序运行结果1
feel free to listen to their voices and help the masses solve problems, we were officially opened on May 10 "12345" Mayor calls, formulated rules and regulations, equipped with a full-time staff, a 24-hour on-duty system, people to call to receive, reply, action, reminders, feedback and so on. By year end, handled the crowd calls 1076, 94.7% feedback rate. By Mayor calls active coordination to solve a large number of bears on the immediate interests of the people and issues of great lives, but also for leadership research and decision to collect a lot of good ideas and suggestions, by all sectors of the community alike. Second, start Municipal Government Affairs Hall built. On May 11, we built and launched the city-government lobby, were settled in 12 departments, strict implementation of first asking duty system, service system, system of gratuitous, "receiving, internal coordination, head of the window handle, limited time concluded" one-stop service. By the end of today to accept various types of 3,273, originally of up to 100%. Running Government Affairs Hall, the convenience of the masses, promoting open Government, improve the investment environment and solve their practical problems, and so did a lot of work, masses, serve the community for the Government to play a very good "window, link, model". Third, create a city government public affairs network. We rely on the Government Web site, was completed on May 24, the province's first public affairs network. Over
沈阳理工大学
五、参考文献
[1]马秀丽,刘志妩,李筠.C语言程序设计.北京:清华大学出版社,2008
[2]谭浩强.C程序设计(第2版).北京:清华大学出版社,2004
feel free to listen to their voices and help the masses solve problems, we were officially opened on May 10 "12345" Mayor calls, formulated rules and regulations, equipped with a full-time staff, a 24-hour on-duty system, people to call to receive, reply, action, reminders, feedback and so on. By year end, handled the crowd calls 1076, 94.7% feedback rate. By Mayor calls active coordination to solve a large number of bears on the immediate interests of the people and issues of great lives, but also for leadership research and decision to collect a lot of good ideas and suggestions, by all sectors of the community alike. Second, start Municipal Government Affairs Hall built. On May 11, we built and launched the city-government lobby, were settled in 12 departments, strict implementation of first asking duty system, service system, system of gratuitous, "receiving, internal coordination, head of the window handle, limited time concluded" one-stop service. By the end of today to accept various types of 3,273, originally of up to 100%. Running Government Affairs Hall, the convenience of the masses, promoting open Government, improve the investment environment and solve their practical problems, and so did a lot of work, masses, serve the community for the Government to play a very good "window, link, model". Third, create a city government public affairs network. We rely on the Government Web site, was completed on May 24, the province's first public affairs network. Over