C语言编程题

C语言编程题,第1张

#include<stdioh>

int main()

{

int a,i;

for(i=1;i<=36;i++)

{

a=7i+56;

if(a==105)printf("%d,%d,%d,%d,%d,%d,%d\n",i,i+1,i+3,i+6,i+10,i+15,i+21);

}

}

#include <stdioh>

#include <stdlibh>

typedef struct

{

  char name[16];

  char id[16];

  int scores[4];

  int sum;

} Student;

int main()

{

  int i, j, n;

  Student students[1024];

  Student t;

  printf("请输入学生数量:");

  scanf("%d", &n);

  for(i=0; i<n; i++) {

      printf("请输入第%d个学生的姓名 学号 和 四门成绩:", i+1);

      scanf("%s%s%d%d%d%d", tname, tid, &tscores[0], &tscores[1], &tscores[2], &tscores[3]);

      tsum = tscores[0] + tscores[1] + tscores[2] + tscores[3];

      students[i] = t;

  }

  for(i=0; i<n; i++) {

      for(j=i+1; j<n; j++) {

          if(students[i]sum < students[j]sum) {

              t = students[i];

              students[i] = students[j];

              students[j] = t;

          }

      }

  }

  printf("学生成绩如下:\n");

  printf("姓名\t学号\t成绩一\t成绩二\t成绩三\t成绩四\t总成绩\t平均成绩\n");

  for(i=0; i<n; i++) {

      t = students[i];

      printf("%s\t%s\t%d\t%d\t%d\t%d\t%d\t%lf\n", tname, tid, tscores[0], tscores[1], tscores[2], tscores[3], tsum, tsum1/4);

  }

  return 0;

}

一份曾经的考卷+答案~~//后面的编程题是以前做过的实验~~

程序设计基础-C》试卷

一、单项选择题

1 C 语言程序中可以对程序进行注释,注释部分必须用符号_____括起来。

A、‘{‘ 和’}’ B、‘[‘和’]’ C、“/”和”/” D、“/”和”/”

2 下列运算符中,优先级最低的是_____。

A、 B、!= C、+ D、=

3 若变量已正确定义,表达式 (j=3, j++) 的值是_____ 。

A、3 B、 4 C、5 D、0

4 已知字符 ‘a’ 的ASCII码为 97 ,执行下列语句的输出是_____。

printf ("%d, %c", ’b’, ’b’+1 ) ;

A、98, b B、语句不合法 C、98, 99 D、 98, c

5 表达式strcmp(“box”, “boss”) 的值是一个_______。

A、 正数 B、 负数 C、 0 D、 不确定的数

6 数组定义为 int a[3][2]={1, 2, 3, 4, 5, 6},数组元素_____的值为6。

A、a[3][2] B、a[2][1] C、a[1][2] D、a[2][3]

7 要调用数学函数时,在#include命令行中应包含_____。

A、 ”stdioh” B、 ”stringh” C、 ”mathh” D、 ”ctypeh”

8 判断i和j至少有一个值为非0的表达式是_____。

A、 i!=0 && j!=0 B、ij!=0 C、!(i==0 || j==0) D、i&&j

9 若a是基本整型变量,c是单精度实型变量,输入语句______是错误的。

A、scanf(”%d,%f”, &a, &c); B、scanf(”d=%d, c=%f”, &a, &c);

C、scanf(”%d%f”, &a, &c); D、scanf(”%d%f”, a, c);

10 若变量已正确定义并且指针p已经指向某个变量x,则(p)++相当于_____。

A、p++ B、x++ C、(p++) D、&x++

11 若p1、p2都是整型指针,p1已经指向变量x,要使p2也指向x, _____是正确的。

A、p2=p1; B、p2=p1; C、p2=&p1; D、p2=p1;

12 下列程序段的输出是_____。

int c[]={1, 3, 5};

int k=c+1;

printf("%d", ++k);

A、 3 B、 5 C、 4 D、6

13 不正确的赋值或赋初值的方式是______。

A、char str[]="string";

B、char str[7]={'s', 't', 'r', 'i', 'n', 'g'};

C、char str[10];str="string";

D、char str[7]={'s', 't', 'r', 'i', 'n', 'g', ’\0’};

14 对于以下结构定义,++p->str中的++加在_____。

struct {

int len;

char str;

} p;

A、指针str上 B、指针p上 C、str指的内容上 D、以上均不是

15 对于如下说明,语法和语义都正确的赋值是_____。

int c, s, a[]={1, 3, 5};

A、c=s; B、 s[0]=a[0]; C、s=&a[1]; D、 c=a;

二、填空题

1 写出下列程序段的输出结果。

float x1, x2;

x1=3/2;

x2=x1/2;

printf("%d, %1f", (int)x1, x2) ;

2 表达式 (7<<1>>2^2 ) 的值是_______。

3 写出下列程序段的输出结果。

#define A 10

#define B (A<A+2)-2

printf("%d", B2);

4 写出判断字符变量c是英文字母的表达式 。

5 写出下列程序段的输出结果。

int k, x;

for (k=0, x=0; k<=9&&x!=10; k++)

x+=2;

printf ("%d, %d", k, x) ;

6 写出下列程序段的输出结果。

printf(“%d, %d”, NULL, EOF);

7 对于以下递归函数f,调用 f (3) 的返回值是_____。

f (int n)

{ return ((n>0) 2f(n-1)+f(n-2) : -1); }

8 写出下列程序段的输出结果。

char str[]="hello\tworld\n";

printf("%d, %c\n", sizeof(str), (str+10));

9 输入12345#后,写出下列程序的输出结果。

void main()

{ char c;

for(c=getchar(); getchar()!=’#’; c=getchar())

putchar(c);

}

10 执行程序find –nx ould texttxt时,++argv[1]的值是_______。

三、程序阅读题

1 若输入 3 1 2 3 <回车> , 则以下程序的输出结果是_______。

#include "stdioh"

void main()

{ int i, j, n, a[10];

scanf("%d", &n);

for (i=0; i<n; i++)

scanf("%d",&a[i]);

for (i=0; i<n; i++)

for (j=0; j<n; j++)

printf("%d, ", a[(i+j)%n]);

}

2 若输入89 76 24 25 9 8 11 16 35 4 <回车> , 则以下程序的输出结果是_______。

#include "stdioh"

#define N 10

main()

{

int x[N], y1[N], y2[N];

int i, j, n1, n2, t, p;

n1=n2=0;

for(i=0;i<N;i++){

scanf(“%d”, &x[i]);

if(x[i] % 2==0) y1[n1++]=x[i];

else y2[n2++]=x[i];

}

for(i=1; i<n1; i++)

for(j=0; j<n1-1; j++)

if(y1[j]>y1[j+1]){

t=y1[j]; y1[j]=y1[j+1]; y1[j+1]=t;

}

for(i=0; i<n2-1; i++){

p=i;

for(j=i+1; j<n2; j++)

if(y2[p]<y2[j]) p=j;

if(p!=i){

t=y2[i]; y2[i]=y2[p]; y2[p]=t;

}

}

for(i=0; i<n1; i++) printf("%d, ", y1[i]);

for(i=0; i<n2; i++) printf("%d, ", y2[i]);

}

3 以下程序的输出结果是_______。

#include <stdioh>

int z;

void p(int x, int y)

{ ++x;

y--;

z=x+y+z;

printf("%d, %d, %d#", x, y, z);

}

void main()

{ int x=1, y=5, z=9;

p(&x, y);

printf("%d, %d, %d#", x, y, z);

}

4 若输入 -6+153/5=<回车> , 则以下程序的输出结果是_______。

#include <stdioh>

void main()

{

int m=0, sum=0;

char c, oldc='+';

do {

c=getchar();

if(c<='9'&&c>='0') m=10m+c - '0';

else {

if(oldc=='+') sum += m;

else sum -= m;

m=0;

oldc=c;

printf("%d, ", sum);

}

} while(c!='=');

}

四、程序填空题

下列程序的功能是创建单向链表。

#include <stdioh>

#include <alloch>

struct link {

char name[10];

int mark;

struct link next;

};

void insert(char , int);

struct link head = NULL;

main()

{

char name[10];

int mark;

struct link t;

while ( 1 ) {

scanf("%s %d", name, &mark);

if ( strcmp(name, "#") == 0 ) break;

______(1)_______;

}

for (t=head; ______(2)_______)

printf("<%s>: %d\n", t->name, t->mark);

}

void insert(char name, int mark)

{

struct link p;

p = ______(3)_______ ;

strcpy(p->name, name);

p->mark = mark;

______(4)_______;

if ( head != NULL ) ______(5)_______;

head = p;

}

答案

2000~2001学年《程序设计基础C》参考答案

一、单项选择题

C D A D A B C B D B A B C A C

二、填空题

1 1, 05

2 1

3 -3

4 c>=’a’&&c<=’z’|| c>=’A’&&c<=’Z’

5 5, 10

6 0, -1

7 -17

8 13, d

9 13

10 ‘n’

三、程序阅读题

1 1, 2, 3, 2, 3, 1, 3, 1, 2,

2 4, 8, 16, 24, 76, 89, 35, 25, 11, 9,

3 2, 4, 6#2, 5, 9#

4 0, -6, 9, 6, 1,

四、程序填空题

(1) insert(name, mark)

(2) t!=NULL; t=t->next

(3) (struct link )malloc(sizeof(struct link))

(4) p->next = NULL

(5) p->next = head

编程

程序填空,不要改变与输入输出有关的语句。

输入一个正整数repeat (0<repeat<10),做repeat次下列运算:

给定平面任意两点坐标 (x1, y1) 和 (x2, y2),求这两点之间的距离(保留2位小数)。

要求定义和调用函数 dist(x1, y1, x2, y2)计算两点间的距离,函数形参x1、y1、x2和y2的类型都是double,函数类型是double。

输入输出示例:括号内是说明

输入

1 (repeat=1)

10 10 (x1=10, y1=10)

200 100 (x2=200, y2=100)

输出

Distance = 21024

#include <stdioh>

#include <mathh>

double dist(double x1, double y1, double x2, double y2);

int main(void)

{

int repeat, ri;

double distance, x1, y1, x2, y2;

scanf("%d", &repeat);

for(ri = 1; ri <= repeat; ri++){

scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);

/---------/

printf("Distance = %2f\n", distance);

}

}

/---------/

程序填空。

求1~100中能被6整除的所有整数的和

#include <stdioh>

int main(void)

{

int i, sum = 0;

/---------/

printf("%d", sum);

}

程序填空,不要改变与输入输出有关的语句。

输入一个正整数repeat (0<repeat<10),做repeat次下列运算:

读入1 个实数x和正整数 n(n<=50),计算并输出 x 的 n 次幂(保留2位小数),不允许调用pow函数求幂。

输入输出示例:括号内是说明

输入

2 (repeat=2)

15 2 (x=15,n=2)

2 7 (x=2,n=7)

输出

225

12800

#include <stdioh>

int main(void)

{

int i, n;

int repeat, ri;

double mypow, x;

scanf("%d", &repeat);

for(ri = 1; ri <= repeat; ri++){

scanf("%lf%d", &x, &n);

/---------/

printf("%2f\n", mypow);

}

}

……编程题还有好多~~需要的话可以发给你~

计算给定公式的近似值,直到最后一项的绝对值小于eps:

#include <stdioh>

#include <mathh>

double factorial(int n) {

double result = 1;

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

result = i;

}

return result;

}

double power(double x, int n) {

double result = 1;

for (int i = 0; i < n; ++i) {

result = x;

}

return result;

}

double approximate(double x, double eps) {

double sum = 0;

int k = 0;

double term;

do {

term = (pow(-1, k) / 20) (factorial(2 k) / factorial(2 k + 1)) (power(x, 2 k + 1) / (2 k + 1));

sum += term;

k++;

} while (fabs(term) >= eps);

return sum;

}

int main() {

double x, eps;

printf("请输入x: ");

scanf("%lf", &x);

printf("请输入eps (epx > 0): ");

scanf("%lf", &eps);

double result = approximate(x, eps);

printf("近似值: %10lf\n", result);

return 0;

}

这个程序首先定义了两个辅助函数factorial()和power(),分别用于计算阶乘和幂。approximate()函数计算给定公式的近似值,当最后一项的绝对值小于eps时停止计算。在main()函数中,我们从用户那里接收x和eps的值,然后调用approximate()函数计算近似值,并将结果打印到控制台。

以上就是关于C语言编程题全部的内容,包括:C语言编程题、C语言编程题,写出代码、求C语言的笔试题和编程题!!~~~谢谢~~!!等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10064662.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-04
下一篇 2023-05-04

发表评论

登录后才能评论

评论列表(0条)

保存