教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 高等教育 >

c - 程序设计课后习题与解答[1](8)

来源:网络收集 时间:2026-08-28
导读: int a = 0; for(int i=1; i int c=0, b=2; a+=3; c=a+b; Console.write (c + “ “ ); } } 答案:5 8 11 14 14 写出以下程序运行结果。 using System; class Test { static void LE(ref int a, ref int b) { int x

int a = 0;

for(int i=1; i

int c=0, b=2; a+=3; c=a+b;

Console.write (c + “ “ ); } }

答案:5 8 11 14

14 写出以下程序运行结果。 using System; class Test {

static void LE(ref int a, ref int b) { int x = a;

a = b; b = x;

Console.writeLine (a + “ “ +b); }

public static void Main () {

int x=10, y=25; LE(ref x, ref y);

Console.writeLine (x + “ “ +y); } }

答案:25 10 25 10

15.写出以下程序的功能。

static void WA(ref int[] a, int n) { for(int i=0;i

for(int j=i+1;j int x=a[i]; a[i]=a[k]; a[k]=x; } }

答案:采用选择排序的方法对数组a中的n个整数按照从小到大的次序重新排列。

16. 写出以下程序的运行结果。 using System;

第 26 页 共 88 页

class Test {

public static void Main () {

int[ ] a ={2,4,6,8,10,12,14,16,18}; for (int i=0; i<9; i++) {

Console.write(“ ”+a[i]);

if ((i+1)%3==0) Console.writeLine(); } } }

答案:2 4 6 8 10 12 14 16 18

17. 写出以下程序运行结果。 using System; class Test {

public static void Main () {

int s=0;

for (int i=1; ; i++) {

if (s>50) break; if (i%2==0) s+=i; }

Console.writeLine (\} }

答案:i,s = 15, 56

18下面代码的输出结果是(12.56 )。

static void Main(string[ ] args) {

int radius = 2;

double area = GetArea(radius);

Console.WriteLine(area); Console.ReadLine(); }

private static double GetArea(int r) {

第 27 页 共 88 页

return 3.14 * r * r; }

19. static void Main(string[] args)

c - 程序设计课后习题与解答[1](8).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/614362.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)