哈工大C语言程序设计精髓MOOC慕课 周编程题答案 下载本文

{

flag=1; break; } }

str[i] != str[i+1],则计数器重新初始化为1。遍历结束时,函数返回程序运行结果示例1: Input a string: 5:5

程序运行结果示例2: Input a string: sgf222257↙ 2:4

输入提示信息:\输入格式: 用gets()输入字符串 输出格式:\*/

#include <> #include <> int main() {

char a[80];

max的值。 int b, i,j,t=1,tl,num=0; printf(\ gets(a);

for (i=0;i

for (j=i+1;j

if (t>tl){ tl=t; num=i; } } }

printf(\}\

\

从键盘输入一串字符(假设字符数少于8个),以回车表示输入结束,编程将其中的数字部分转换为整型数并以整型的形式输出。 函数原型为 int Myatoi(char str[]);

其中,形参数组str[]对应用户输入的字符串,函数返回值为转换后的整型数。 解题思路的关键是:1)判断字符串中的字符是否是数字字符;2)如何将数字字符转换为其对应的数字值;3)如何将每一个转换后的数字值加起来形成一个整型数。 程序运行结果示例1: Input a string:7hg09y↙ 709

程序运行结果示例2: Input a string:9w2k7m0↙ 9270

程序运行结果示例3: Input a string:happy↙ 0

输入提示信息:\输入格式: \输出格式:\*/

#include <> #include <>

#include <> int Myatoi(char str[]){ int i,j;

for (i=0,j=0;str[i]!='\\0';i++){

if (str[i] >='0' && str[i]<='9'){ str[j]=str[i]; j++; } } str[j]='\\0'; return atoi(str); } int main() {

char s[7];

printf(\ scanf(\ printf(\ printf(\ return 0; }\

\输入n个整数(n从键盘输入,假设n的值不超过100),按奇偶数分成两组并

输出。输出两行,第一行为所有奇数,第二行为所有偶数,保持数据的相对顺序与输入顺序相同。 函数原型如下所示:

void Seperate(int a[], int n);?ame);

printf(\

printf(\ printf(\not?(Y/N):\ printf(\not?(Y/N):\

printf(\papers:\ stu[i].scholarship=0;

if (stu[i].finalScore>80 && stu[i].paper >=1) stu[i].scholarship+=8000;

if (stu[i].finalScore>85 && stu[i].classScore> 80) stu[i].scholarship+=4000;

if (stu[i].finalScore>90) stu[i].scholarship+=2000;

if (stu[i].finalScore>85 && stu[i].west=='Y') stu[i].scholarship+=1000; if (stu[i].classScore> 80 && stu[i].work=='Y') stu[i].scholarship+=850; printf(\