printf(\}
6. 编程,输出一个3行4列(记作3?4)矩阵A的转置矩阵AT(行列互换)。 参考程序: #include void main()
{ int a[3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}}; int b[4][3],i,j; printf(\ for(i=0;i<3;i++) { for(j=0;j<4;j++)
}
printf(\ for(i=0;i<4;i++) { for(j=0;j<3;j++) printf(\ printf(\ } }
7. 编程,求3×3矩阵的主对角线上元素之和。 参考程序: #include void main() {
int a[3][3],i,j,sum=0; for(i=0;i<3;i++) for(j=0;j<3;j++) scanf(\
{ printf(\}
printf(\
b[j][i]=a[i][j];
for(i=0;i<3;i++) for(j=0;j<3;j++)
if(i==j) sum=sum+a[i][j]; printf(\}
8. 编程,求6×6矩阵下三角形元素之和。 参考程序: #include void main() {
int a[6][6],i,j,sum=0; for(i=0;i<6;i++) for(j=0;j<6;j++) scanf(\for(i=0;i<=5;i++) for(j=5;j>=5-i;j--) sum=sum+a[i][j]; printf(\}
9. 编程,输入一个字符串,然后以反序输出。 参考程序: #include #include main() { char c[20]; int i;
printf(\ gets(c);
printf(\for(i=strlen(c)-1;i>=0;i--) printf(\}
10. 编程,输出给定的字符串的长度。 参考程序: #include #include void main() {char s[80]; int i=0,num=0; gets(s); while(s[i]!='\\0')
{
num++; i++; } puts(s); printf(\
printf(\ }
11. 编程,输入一行字符,要求统计有多少个单词。 参考程序: #include \#include void main() { char string[81]; int i, num=0,word=0; char c; gets(string);
for(i=0;(c=string[i])!='\\0';i++)
if(c==' ') word=0; else if(word==0) { word=1; num++; }
printf(\ are %d words in the line\\n\}
12. 编程,密码输入程序。设计要求:以星号‘*’代替密码字符的显示,6≤密码长度≤12。 参考程序: #include \#include \#define MIN 6
/*密码最小长度*/
#define MAX 12 /*密码最大长度*/ void main() { int loop;
char password[13];
/*为密码字符串预留1个结束标志位*/
printf(\for( loop = 0; loop < MAX; loop++) { password[loop] = getch(); printf(\
/*以星号代替密码字符显示*/
if(password[loop]=='\\n') /*回车,结束密码输入*/
{ if( loop < MIN ) /*长度<6,提示重输*/
{ printf(\ress any key to continue…\
getch();
/*暂停,按任意键继续*/
printf(\
loop = -1; /*执行“loop++”后,使下标复位为0*/ }
else
/*密码长度在6~11之间*/
{ password[loop] = '\\0'; /*置密码串结束标志*/ break; }
if( loop == MAX -1) /*密码长度达到最大值MAX*/ password[loop] = '\\0'; /*置密码串结束标志*/ }
/*for循环尾*/
} /*main()函数尾*/
以上是由77cn范文大全为大家整理的C语言第7章 习题及实验参考答案~1的相关范文,本文关键词为语言,7章,习题,实验,参考,答案,7章,习题,参考,答案,,您可以从右上方搜索框检索更多相关文章,如果您觉得有用,请继续关注我们并推荐给您的好友,您可以在综合文库中查看更多范文。
C语言第7章 习题及实验参考答案~1.doc
免费范文网为全国范文类知名网站,下载全文稍作修改便可使用,即刻完成写稿任务。
已有11人下载
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库C语言第7章 习题及实验参考答案~1在线全文阅读。
本文来自:免费范文网(www.77cn.com.cn) 转载请注明出处!