欢迎来到天天文库
浏览记录
ID:34431816
大小:75.50 KB
页数:8页
时间:2019-03-06
《二维数组字符数组函数》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、二维数组、字符数组和函数⑴按行列方式输出二维数组a[3][4],并计算其中所有值大于10的元素之和。inta[3][4]={2,4,12,16,8,13,5,6,9,32,10,14};#includevoidmain(){inta[3][4]={2,4,12,16,8,13,5,6,9,32,10,14};inti;intj;intsum;sum=0;for(i=0;i<3;i++){for(j=0;j<4;j++){if(a[i][j]>10){sum+=a[i][j];}}}printf("%d",sum);⑵3行3列二维数组,求其中
2、最大元素和最小元素。3行3列二维数组,求其主对角线元素之和。3行3列二维数组,分别求其每行和每列的和。用以下数组初始值序列{{4,5,6},{10,11,12},{61,62,63}}#includevoidmain(){inta[3][3]={{4,5,6},{10,11,12},{61,62,63}};inti;intj;intmax;intmin;intDJXsum=0;inthangsum;intliesum;max=min=a[0][0];for(i=0;i<3;i++){for(j=0;j<3;j++){if(a[i][j]>max
3、){max=a[i][j];}}}for(i=0;i<3;i++){for(j=0;j<3;j++){if(a[i][j]4、=0;i<3;i++){liesum+=a[i][j];}printf("%d",liesum);}}⑶编写程序,生成字符串数组,求其中字符’0’-‘9’分别的个数。charstr={“dlfji34lrj4f433feshgg5423rfe997jhdrth0erg0se1249d084l9fjf.”};#includevoidmain(){charstr[]={"dlfji34lrj4f433feshgg5423rfe997jhdrth0erg0se1249d084l9fjf."};intcount[10]={0};inti;for(i5、=0;str[i]!=' ';i++){switch(str[i]){case'0':count[0]++;break;case'1':count[1]++;break;case'2':count[2]++;break;case'3':count[3]++;break;case'4':count[4]++;break;case'5':count[5]++;break;case'6':count[6]++;break;case'7':count[7]++;break;case'8':count[8]++;break;case'9':count[9]++;brea6、k;default:break;}}for(i=0;i<10;i++){printf("count--%dth=%d,",i,count[i]);}}⑷编写程序,生成字符串数组,将字符串反序。charstr={“dlfji34lrj4f433feshgg5423rfe997jhdrth0erg0se1249d084l9fjf.”};#includevoidmain(){charstr[]={"dlfji34lrj4f433feshgg5423rfe997jhdrth0erg0se1249d084l9fjf."};inti;intnumber7、=0;chart;for(i=0;str[i]!=' ';i++){number++;}for(i=0;ivoidmain(){charstr1[100]={"abcde128、345"};charst
4、=0;i<3;i++){liesum+=a[i][j];}printf("%d",liesum);}}⑶编写程序,生成字符串数组,求其中字符’0’-‘9’分别的个数。charstr={“dlfji34lrj4f433feshgg5423rfe997jhdrth0erg0se1249d084l9fjf.”};#includevoidmain(){charstr[]={"dlfji34lrj4f433feshgg5423rfe997jhdrth0erg0se1249d084l9fjf."};intcount[10]={0};inti;for(i
5、=0;str[i]!=' ';i++){switch(str[i]){case'0':count[0]++;break;case'1':count[1]++;break;case'2':count[2]++;break;case'3':count[3]++;break;case'4':count[4]++;break;case'5':count[5]++;break;case'6':count[6]++;break;case'7':count[7]++;break;case'8':count[8]++;break;case'9':count[9]++;brea
6、k;default:break;}}for(i=0;i<10;i++){printf("count--%dth=%d,",i,count[i]);}}⑷编写程序,生成字符串数组,将字符串反序。charstr={“dlfji34lrj4f433feshgg5423rfe997jhdrth0erg0se1249d084l9fjf.”};#includevoidmain(){charstr[]={"dlfji34lrj4f433feshgg5423rfe997jhdrth0erg0se1249d084l9fjf."};inti;intnumber
7、=0;chart;for(i=0;str[i]!=' ';i++){number++;}for(i=0;ivoidmain(){charstr1[100]={"abcde12
8、345"};charst
此文档下载收益归作者所有