C语言程序设计基础训练资料

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

广东财经大学信息学院

C语言程序设计课程设计

基础训练

专业:计算机科学与技术(创新实验班)

班级:

学号:14151106144

姓名:黄瑜宏

成绩:

指导老师:赖庆

完成日期:2015年6月25日

一、菜单实现

1、代码

# include

# include

# include

# include

void finnum();

void diamond();

int menu_select ();

void main ()

{

for (; ;)

{

switch ( menu_select() )

{

case 1:

findnum ();break;

case 2:

diamond ();break;

case 3:

printf ( "goodbye" );

exit (0);

}

}

}

int menu_select ()

{

char s;

int cn;

printf ( "dindnum\n" );

printf ( "diamond\n" );

printf ( "goodbye\n" );

printf ( "input 1-3:" );

do{

s= getchar ();

cn = (int)s-48;

}while ( cn < 0||cn>3 );

return cn;

}

void findnum()

{

int i;

printf ( "填上什么数字?可以使得下面的式子成立" );

printf ( "shizi \n" );

printf ( "求解结果为\n" );

for (i=1;i<10;i++)

if ((30+i)*6237 == (10*i+3)*3564 )

{

printf ( "number = %d\n",i );

break;

}

}

void diamond ()

{

int i,j,k;

printf ( "打印菱形图案。\n" );

for ( i=1;i<=4;i++ )

{

for (j=1;j<=16-i;j++)

printf ( " " );

for ( k=1;k<=(2*i-1);k++ );

printf ("\n");

}

}

2、编译截图

二、计算机基础解题

1、寻找成绩最佳者

⑴、代码

# include

void main ()

{

int k = 0, sum = 0, flag = 0;

char tongxue = ' ';

for ( k = 1; k <= 4; k++ )

{

tongxue = 64 + k;

sum = (tongxue != 'A') + (tongxue == 'C') + (tongxue == 'D') + (tongxue != 'D');

if (sum == 3)

{

printf ("%c是最佳成绩者\n",tongxue);

flag = 1;

}

}

if (flag != 1)

printf ( "无解!" );

}

⑵、编译截图

三、使用数组和指针统计成绩

1、使用数组实现

⑴、代码

# include

# include

void main ()

{

int i,sum = 0,min = 100;

int a[8] = { 75,80,83,85,86,30 };

char *meanlow[4] = { "人数","平均成绩","最低分数的科目成绩","最低分数的科目" };// 字符串的长度不一样,所以使用字符指针数组meanlow来实现char name [6][5] = {"数学","物理","外语","政治","体育"};

printf ( "原始信息如下:\n" );

for (i = 0; i < 5; i++)

printf ( "%s:%d\n",name[i],a[i] );

for ( i = 0; i < 3; i++ )

{

printf ( "%s:%d\n",meanlow[i],a[i+5] );

}

printf ( "%s:\n",meanlow[i] );

for ( i = 0; i < 5; i++ )

{

sum = sum +a[i];

if ( min > a[i] ) min = a[i];

}

a[6] = sum/5;

a[7] = min;

for ( i = 0; i < 5; i++ )

if (min == a[i])

{

strcpy( name[5],name[i] );

break;

}

printf ( "\n全班各科的平均成绩如下:\n" );

for ( i = 0;i < 5; i++ )

printf ( "%s:%d\n",name[i],a[i] );

printf ( "\n统计结果如下:\n" );

for ( i = 0;i < 3; i++ )

{

printf ( "%s:%d\n",meanlow[i],a[i+5] );

}

printf ( "%s:%s\n",meanlow[3],name [5] ); }

⑵、编译截图

2、使用分配内存实现

相关文档
最新文档