欢迎来到三一文库! | 帮助中心 三一文库31doc.com 一个上传文档投稿赚钱的网站
三一文库
全部分类
  • 幼儿/小学教育>
  • 中学教育>
  • 高等教育>
  • 研究生考试>
  • 外语学习>
  • 资格/认证考试>
  • 论文>
  • IT计算机>
  • 法律/法学>
  • 建筑/环境>
  • 通信/电子>
  • 医学/心理学>
  • ImageVerifierCode 换一换
    首页 三一文库 > 资源分类 > DOC文档下载
    分享到微信 分享到微博 分享到QQ空间

    南昌大学C程序设计双语作业与答案.doc

    • 资源ID:49267       资源大小:150.50KB        全文页数:26页
    • 资源格式: DOC        下载积分:5
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录 微博登录
    二维码
    微信扫一扫登录
    下载资源需要5
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    南昌大学C程序设计双语作业与答案.doc

    1、Chapter 1 Introduction1、1. Which of the following are illegal identifiers?Circle the illegal identifiers. A.3id B._yes C.star*it D.int 教师批改:A C D 2、1. Which of the following are illegal identifiers?Circle the illegal identifiers. A. xyshouldI B. me_to-2 C. one_i_arent D. 2_i_am 教师批改:B C D Chapter 2

    2、Learning by Example1、What is correct about the following program? #include #define count 6 void main(void) count = count + 1 ; printf(%d, count) ; A. 7 is output and count becomes 7 B 7 is output and count becomes 7 C. Runtime Error D. 7 is output but count remains 6 教师批改:C 2、Indicate which of the f

    3、ollowing are legal variable names in C: A、X B、formula1 C、average_rainfall D、%correct 教师批改:ABC 3、Indicate which of the following are legal variable names in C: A、short B、tiny C、total rainfall D、aReasonablyLongVariableName 教师批改:BD 4、Indicate which of the following are legal variable names in C: A、12Mo

    4、nthTotal B、marginal-cost C、b4hand D、_stk_depth 教师批改:CD 5、Indicate which of the following are legal variable names in C: A、short B、4formula C、average_rainfall D、%correct 教师批改:C 6、Indicate which of the following are legal variable names in C: A、short B、formula_5 C、average_rainfall D、4correct 教师批改:BC 7

    5、Indicate which of the following are legal variable names in C: A、short B、formula6 C.float D.printf 教师批改:BD 8、Consider the following code fragment:int dblarray10,*dblPointer;Which of the following statements are valid (i.e. which ones will compile)? Circle all the correct answers (there may be more

    6、than one correct answer). A. dblPointer = dblArray; B. dblPointer = dblArray4; C. dblPointer = &(dblArray2); D. dblPointer = *dblArray; 教师批改:AC 9、Indicate the values and types of the following expressions:2+3 value:_type:_ 教师批改:5 integer 10、Indicate the values and types of the following expressions:

    7、19/5 value:_ type:_ 教师批改:3 integer 11、Indicate the values and types of the following expressions:19.0/5 value:_type:_ 教师批改:3.8 double 12、Indicate the values and types of the following expressions:3*6.0 value:_type:_ 教师批改:18.0 double 13、Indicate the values and types of the following expressions:19%5

    8、value:_type:_ 教师批改:4 integer 14、Indicate the values and types of the following expressions:2%7 value:_type:_ 教师批改:4 integer 15、By applying the appropriate precedence rules,calculate the result of the following expression:6+5/4-3,result is _ 教师批改:4 16、By applying the appropriate precedence rules,calc

    9、ulate the result of the following expression:10+9*(8+7)%6)+5*4%3*2+1,result is _ 教师批改:42 17、By applying the appropriate precedence rules,calculate the result of the following expression:1+2+(3+4)*(5*6%7*8)-9)-10,result is _ 教师批改:42 18、Rewrite the following floating-point constants in Cs form for sci

    10、entific notation:29979250000.0_ 教师批改:29979250000 19、Rewrite the following floating-point constants in Cs form for scientific notation:0.00000000529167_ 教师批改:0.00000000529 20、Evaluate the following expression: (2 Points)int i=1,j=2,k=3,m=4;i+=j+k; / i=_j*=k=m+5; / j=_ 教师批改:6 18 21、The variables are i

    11、nitialized as follows,char c=A; int i=7,j=7;double x=0.0,y=2.3;Evaluate the following expressions: (5 Points)!c _!(i-j)_!i-j_!(x+y)_!x*!y_ 教师批改:0 1 -7 1 1 22、Indicate the values and types of the following expressions:2%7 value:_type:_ 教师批改:2 integer 23、By applying the appropriate precedence rules,ca

    12、lculate the result of the following expression:2+2*(2*2-2)%2/2,result is _ 教师批改:2 24、The following C program is compiled and runs successfully. Write the output the following program produces. #include void main( ) int k = 42; printf(%dn, k+);_ printf(%dn, +k);_ return 0; 教师批改:42 44 25、Write a progr

    13、am that reads in a list of integers until the user enters the value -1 as a sentinel.At that point,the program should display the average of the values entered so far. Chapter 3 Problem Solving1、 What is the output of the following code? #include void main(void) int a ; a = 1; printf(%i,+a) ; A. Com

    14、pile-time Error B. 0 C.1 D. 2 教师批改:D2、Use #define to introduce a constant named pi with the value 3.14159_ 教师批改:#define pi 3.14159 3、Write a printf statement to display the floating-point value stored in the variable distance so that exactly three digits appear to the right of the decimal point_ 教师批

    15、改:printf(%.3f,distance); 4、Use for control line to count from 15 to 25_ 教师批改:for(i=15;i=25;i+) 5、Write a program that displays the message Hello,world. 10 times on separate lines._ 教师批改:main() int k;for(k=1;k=10;k+)printf(Hello,world.n); 6、Write a program that prints a tabular version of both the sq

    16、uares and cubes of the number from 1 to 10. Chapter 4 Statement Forms1、Consider the following program:#include void main() int a=1,b=2,c=3,d=0;if(a=1 & b+=2)if(b!=2|c-!=3) printf(“%d,%d,%dn”,a,b,c);else printf(“%d,%d,%dn”,a,b,c);else printf(“%d,%d,%dn”,a,b,c);The output of the program is: A)1,2,3 B)

    17、1,3,2 C)1,3,3 D)3,2,1 教师批改:C 2、Consider the program fragment and give the output:For (i=0;i4;i+,i+) for(k=1;k k) & (i + j) = k) _ b) (i+j) != k) | (j*j) k) & (i*i) k) _c) k (j i) _ 教师批改:0 1 0 4、The following C program is compiled and runs successfully. Write the output that this program produces.#in

    18、clude main()int x = 4;int y = 4;if ( (x = y) ) printf(“Bingo”);else printf(“No go”); 教师批改:Bingo 5、What will be printed to the screen if we execute the code? #include void main( ) int index = 0; if(index = 0) printf(A); if(index = 1) printf(B); 教师批改:B 6、What are the values of the following statement,

    19、assuming that i,j,and k are declared as integer variables:i=(j=4)*(k=16) i=_j=_,k=_ 教师批改:64,4,16 7、Write a for loop control line to count from 1 to 100_ 教师批改:for(k=1;k=0;k=k-2) 9、The following C program compiles and runs without errors. Write the output of this program._#include void main( ) int i =

    20、 -1; int j = 1; if( 0 i | i i) printf(A); else printf(B); elseprintf(C); 教师批改:A 10、What is the output of the following code?#include void main() int day_of_week = 4; switch (day_of_week) case 0: printf(today is Sunday.n); case 1: printf(today is Monday.n); case 2: printf(today is Tuesday.n); case 3:

    21、 printf(today is Wednesday.n); case 4: printf(today is Thursday.n); case 5: printf(today is Friday.n); case 6: printf(today is Saturday.n); default: printf(Something is missing.); break; /*_*/ 教师批改:today is Thursdaytoday is Friday.Today is Saturday.Something is missing.11、The following C program is

    22、compiled and runs successfully. Write the output the following program produces. #include #define NRows 5void main() int i, j; for (i = 1; i = NRows; i+) for (j = i; j NRows; j+) printf( ); for (j = 0; j 2 * i - 1; j+) printf(*); printf(n); 教师批改:* * * * * * * * * * * * * * * * * * * * * * * * * 12、T

    23、he following C program is compiled and runs successfully. Write the output the following program produces.#include void main() int a66,i,j; for(i=1;i6;i+) for(j=1;j6;j+) aij=(i/j)*(j/i); for(i=1;i6;i+) for(j=1;j=0;i-=3) printf(%d,i-1);/*_*/ 教师批改:9630 14、How many lines of output does the following pr

    24、ogram print? #include void main( ) int i,j; for(i=0;i5;i+) for(j=0;j5;j+); printf(Hello world!n); 教师批改:1 15、Complete the program below to produce the following output:1 x 12 = 122 x 12 = 243 x 12 = 3610 x 12 = 12011 x 12 = 13212 x 12 = 144#include void main(void) int i; for( _ ; _ ; _ ) printf(%d x

    25、12 = %dn, _ , _ ); 教师批改:i=1 i12 i+ i*12 n 16、The following C program is compiled and runs successfully. Write the output the following program produces.#define LowerLimit 1#define UpperLimit 4#includevoid main()int i;printf(Number Square Cuben);for (i = LowerLimit; i = UpperLimit; i+) printf( %2d %3

    26、d %4dn, i, i * i, i * i * i); 教师批改:1 1 1 、2 4 8 、3 9 27 17、While were on the subject of silly songs,another old standby is This Old Man for which the first verse is This old man,he played 1.He played knick-knack on my thumb.With a knick-knack,paddy-whack,Give your dog a bone.This old man come rollin

    27、g home.Each subsequent verse is the same,except for the number and the rhyming word at the end of the second line,which gets replaced as follows: 2-shoe 3-knee 4-door 5-hive 6-sticks 7-heaven 8-pate 9-spine 10-shin Chapter 5 Function 1、Consider the following program:#include int f(int x,int y)return

    28、 (y-x)*x);void main() int a=3,b=4,c=5,d; d=f(f(a,b),f(a,c); printf(%dn,d);A)10 B)9 C)8 D)7 教师批改:B2、The following program compiles and executes without errors. Write the output of this program. (8 Points)#include int foo(int x) x+;return x;int bar(int y) y-;return y;void main() int x = 1; int y = 3;f

    29、oo(x);bar(y);printf(%d %dn,x,y);y = foo(x);x = bar(y);printf(%d %dn,x,y);_ _ 教师批改:1 3 1 2 3、The following program compiles and executes without errors. Write the output of this program.#include int count1(int k) int x = 1; x = x + k; printf(%d ,x); return x;int count2(int k) static int x = 1; x = x

    30、 k; printf(%d,x); return x;void main( ) count1(count1(1); count2(count2(2);_ 教师批改:2 33 6 4、The following C program is compiled and runs successfully. Write the output the following program produces.int fun(int x, int y, int z) z=x*x+y*y; void main( ) int a=31; fun(5,2,a); printf(%d,a);/*_*/ 教师批改:31

    31、 5、The following program compiles and executes without errors. Write the output of this program. #include int pfft(int x) if (x=0) return 0; /* Hint: % gives the remainder, example 5%2 is 1 */ if( (x % 2) != 0 ) return (1 + pfft(x - 1); else return (3 + pfft(x - 1);void main() printf(%d n,pfft(7); 教

    32、师批改:13 6、The following C program is compiled and runs successfully. Write the output the following program produces.#include void main( ) int w=2; void fun(int); fun(w);void fun(int k) if (k0) fun(k-1); printf(“%d”,k); 教师批改:0 1 2 7、What output will the following piece of code produce?void foo(int c)

    33、 c = 20;void bar(int d) d1 = 30;void main(void) int x = 10; int y = 15; int a2 = 1, 2; int b2 = 3, 4; foo(a0); printf(%d %d %d %d %d %dn, x, y, a0, a1, b0, b1); /*_*/ bar(b); printf(%d %d %d %d %d %dn, x, y, a0, a1, b0, b1); /*_*/ foo(y); printf(%d %d %d %d %d %dn, x, y, a0, a1, b0, b1); /*_*/ bar(a

    34、); printf(%d %d %d %d %d %dn, x, y, a0, a1, b0, b1); /*_*/ 教师批改:10 15 1 2 3 410 15 1 2 3 3010 15 1 2 3 3010 15 1 30 3 30 8、The following C program is compiled and runs successfully. Write the output that this program produces.#includevoid main() int a=1,b=2,c=3;a+=b+=+c;printf(%5d%5d%5dn,a,b,c);/(1)

    35、 float b=4.0; int c; a+=c=5*b; printf(%5d%5.1f%5dn,a,b,c);/(2)_printf(%5d%5d%5dn,a,b,c);(3)_ 教师批改:(1)7 6 4 (2)27 4.0 20 (3)27 6 4 9、Write a function Fib(n) to calculate the nth Fibonacci number. Chapter 11 Arrays1、It is an array declaration: int a3;Which one is invalid to refer to particular member

    36、s of arrays : A a0 B a1*2 C a4-2 D a3 教师批改:D2、Assume we have declared the two dimensional array A in the C language,int A32 = 0, 1, 2, 3, 4, 5 ;Write the value of A21._ 教师批改:5 3、This program computes the average of all the values of an array named list. Assume that the count of the number of values

    37、is 100 or fewer.#include #define ARRAY_SIZE 100main( ) int listARRAY_SIZE; int count = 0; double total = 0.0; while( scanf(%d, &list count )=1) total =_; count =_; printf(average = %lf n,_); 教师批改:total=total+listcount; count=count+1; total/count 4、This program reads in an array of integers, reverses the elements of the array, and then displays the elements in their reversed order. Please complete the program.#define MaxElement 5#include void input(


    注意事项

    本文(南昌大学C程序设计双语作业与答案.doc)为本站会员(飞猪)主动上传,三一文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一文库(点击联系客服),我们立即给予删除!




    宁ICP备18001539号-1

    三一文库
    收起
    展开