正在加载图片...
实验6数组的应用 【实验目的】 1掌握数组定义和初始化的方法。 2熟悉使用字符数组处理字符串处理的方法。 【实验内容】 1.输入10个学生的成绩,求平均成绩,并将低于平均成绩的分数打印出来 # include≤ iostream. h> #include <iomanip. h void readdata(float scoreloD cout<<"Please input 10 students score: <<endl; for(int F0; i<10; i++) cin>>score; 1 float aver(float scoreloD f float sum=0; int i; for(i=0;<10;i+) sum+=score i; return(sum/10); void print(float score 10, float ave) Rint 1; cout<< the scores which are below the average for(i=0;<10;i+) if(s core山<ave cout<<score<<; out<<endl: return; void main( i void readdata(float scorel1oD float aver(float score 10 void print(float score[ 10, float ave); float ave, score 10 readdata(score) cout<<average="<<ave<<endl; print(score, ave) 2.编写一程序,从键盘任意输入两个字符串sl和s2,然后比较字符串的大 小,若s1>s2,输出1:若sl=s2,输出0:若sl<s2,输出-1 lude <string. h #include <stdio h> #includesiostream h3 void maino i int k实验 6 数组的应用 【实验目的】 1 掌握数组定义和初始化的方法。 2 熟悉使用字符数组处理字符串处理的方法。 【实验内容】 ⒈输入 10 个学生的成绩,求平均成绩,并将低于平均成绩的分数打印出来。 #include <iostream.h> #include <iomanip.h> void readdata(float score[10]) {cout<<"Please input 10 student's score:"<<endl; for(int i=0;i<10;i++) cin>>score[i];} float aver(float score[10]) { float sum=0; int i; for(i=0;i<10;i++) sum+=score[i]; return(sum/10); } void print(float score[10],float ave) {int i; cout<<"the scores which are below the average:"; for(i=0;i<10;i++) if(score[i]<ave) cout<<score[i]<<" "; cout<<endl; return; } void main( ) { void readdata(float score[10]); float aver(float score[10]); void print(float score[10],float ave); float ave,score[10]; readdata(score); ave=aver(score); cout<<"average="<<ave<<endl; print(score,ave); } ⒉编写一程序,从键盘任意输入两个字符串 s1 和 s2,然后比较字符串的大 小,若 s1>s2,输出 1;若 s1=s2,输出 0;若 s1<s2,输出-1; #include <string.h> #include <stdio.h> #include<iostream.h> void main() { int k;
向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有