了解湖南/长沙凯时app资讯,从湖南凯时app网开始!湖南凯时app报名湖南凯时app本科
您当前的位置:凯时app > 湖南凯时app考前练习

凯时app“高级语言程序设计”经典习题及答案(18)

凯时app“高级语言程序设计”经典习题及答案(18)

 

  4.编程序按下列公式计算S的值(其中X1、X2、…、Xn由键盘输入):OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  s=∑(xi-x0)(xi-x0) (其中x0是X1、x2、…、Xn的平均值)OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  “解”输入数组x的n个元素的值,按公式计算。程序首先输入n,设n<100,然后输入n个数据,接着求它们的平均值,最后按计算公式求出s,并输出。程序如下:OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  # includeOGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  # define N 100OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  main()OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  { double x[N+1], s;OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  int i,n;OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  do {OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  printf(“Enter n(<100)”); scanf(“%d”, &n);OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  } while(<=0||n>=100);OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  for(i=1; i<=n;i++){OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  scanf(“%lf”, &s);x=s;OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  for(s=0.0,i=1;i<=n; i++)OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  s+=x ;OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  x[0] = s/n;OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  for(s=0.0, i=1;i<= n;i++)OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  s+=(x-x[0])*(x-x[0]);OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  printf(“s=%f/n”, s);OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  5.输入一个3X5的整数矩阵,输出其中最大值、最小值和它们的下标。OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  “解”输入一个二维数组,寻找二维数组的最大值和最小值。其中寻找最大值和最小值的工作可用两重循环实现,即按行按列考察二维数组的元素。程序如下:OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  # includeOGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  main()OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  { int a[3][5], i,j,t,n=3, m=5,OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  min,max, minrow, mincol, maxrow, maxcol;OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  printf(“Enter %d*%d numbers !/n” , n,m);OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  for(i=0; iOGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  for( j=0;jOGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  scanf(“%d”, &t); a[j]= t;OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  min=max=a[[0][0]; minrow=mincol=maxrow=maxcol=0;OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  for(i=0;iOGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  for(j=0;jOGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  if( a[j]> max ){OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  max= a[j] ;maxrow= i;maxcol=j ;OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  if( a[j]OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  min=a[j] ; minrow= i; mincol=j ;OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  printf(“MAX=a[%d][%d] =%d MIN= a[%d][%d] =%d /n”,OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  maxrow,maxcol,max,minrow,mincol,min) ;OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  6.输入一个字符串,将其中的所有大写字母改为小写字母,而所有小写字母全部改为大写字母,然后输出。OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  “解”程序先输入字符率,然后顺序考察输入字符串中的字符,当发现是大写字母时,将它改写成对应的小写字母,而当它是小写字母时,就将它改写成对应的大写字母。若变量ch中的字符是大写字母,则与它对应的小写字母的表达式可以写成ch- ‘A’+‘a’ ;类似地,若变量ch中的字符是小写字母,则与它对应的大写字母的表达式可以写成ch-‘a’+‘A’ .完整程序如下:OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  # includeOGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  # define N 200OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  main()OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  { char s[N] ;OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  int i;OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  printf(“ Enter string! /n”);OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  scanf (“%s” ,s);OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  for(i=0; s!=‘/0’;i++)OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  if(s >=‘A’&&s <=‘Z’ )OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  s=s -‘x’+‘a’ ;OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  else if(s >=‘a’&& s <=‘z’)OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  s= s-‘a’ +‘A’ ;OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  printf(“s=%s/n”,s);OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  7.设某班50名学生的三科成绩表如下:OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  课程一 课程二 课程三OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  …… …… ……OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  试编一个程序,输入这50个学生的三科成绩,计算并输出每科成绩的平均分。OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  “解”程序定义一个50行3列的二维数组,用于存储全班学生的成绩。程序顺序输入各个学生的三科成绩,然后按列的顺序,累计各科总分,并计算平均分。完整程序如下:OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  # includeOGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  # define N 50OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  # define M 3OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  main()OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  {int score[N][M], i,j,t;OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  double a[M];OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  printf(“Enter scores!/n”);OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  for(i=0;i< N; i++)OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  for(j=0;jOGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  scanf(“%d”,&t);score[j]=t;OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  for(j=0;jOGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  for(j=0;j< M;j++){OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  for(i=0;i< N; i++)OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  a[j]+= score[j];OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  a[j]/= N;OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  for(j=0;jOGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  printf(“课程%d的平均分是%.2f/n”, j+1,a[j]);OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

  }OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

 OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

OGN湖南凯时app网_湖南凯时app本科_湖南凯时app报名_凯时app

 

凯时app“高级语言程序设计”经典习题及答案(18)

    湖南凯时app网——致力于打造湖南凯时app网第一网,以努力服务于广大湖南凯时app学子、提供最全的湖南凯时app资讯为己任,发布湖南凯时app最新的新闻资讯,提供湖南凯时app专科湖南凯时app本科湖南凯时app报名湖南凯时app成绩查询等综合信息

 

湖南凯时app
相关文章
    无相关信息
湖南网站主页
湖南凯时app政策
凯时app30年大事
湖南凯时app专业
湖南凯时app问答
名家访谈
湖南凯时app故事
湖南凯时app院校
湖南凯时app大纲
凯时app复习方法
凯时app笔记串讲
凯时app应试技巧
湖南凯时app真题
湖南凯时app就业
湖南论文指导
湖南凯时app实践
湖南凯时app学位
凯时app成绩查询
凯时app考籍查询
凯时app学历查询


咨询QQ:137847917
13548661633(微信同号)

w66利来国际 w66利来国际 w66利来国际 w66利来国际 w66利来国际