本文目錄一覽:
- 1、C語言考試題目
- 2、簡單的C語言題目,要考試了,求大神幫助
- 3、C語言考試題
- 4、C語言題目,100分懸賞
- 5、幫我找點C語言的考試題唄!
- 6、C語言程序設計考試題
C語言考試題目
#include stdio.h
#includedos.h
#includestdlib.h /*其它說明*/
#includestring.h /*字符串函數*/
#includemem.h /*內存操作函數*/
#includectype.h /*字符操作函數*/
#includealloc.h /*動態地址分配函數*/
#define LEN sizeof(STUDENT)
typedef struct stu /*定義結構體數組用於緩存數據*/
{char num[6];
char name[5];
int score[3];
int sum;
float average;
int order;
struct stu *next;
}STUDENT;
/*函數原型*/
STUDENT *init(); /*初始化函數*/
int menu_select(); /*菜單函數*/
STUDENT *create(); /*創建鏈表*/
void print(STUDENT *head); /* 顯示全部記錄*/
void search(STUDENT *head); /*查找記錄*/
STUDENT *delete(STUDENT *head); /*刪除記錄*/
STUDENT *sort(STUDENT *head); /*排序*/
STUDENT *insert(STUDENT *head,STUDENT *new); /*插入記錄*/
void save(STUDENT *head); /*保存文件*/
STUDENT *load(); /*讀文件*/
/*主函數界面*/
main()
{STUDENT *head,new;
head=init(); /*鏈表初始化,使head的值為NULL*/
for(;;) /*循環無限次*/
{switch(menu_select())
{
case 1:head=create();break;
case 2:print(head);break;
case 3:search(head);break;
case 4:head=delete(head);break;
case 5:head=sort(head);break;
case 6:head=insert(head,new);break; /*new表示返回地址*/
case 7:save(head);break;
case 8:head=load(); break;
case 9:exit(0); /*如菜單返回值為9則程序結束*/
}
}
}
/*初始化函數*/
STUDENT *init()
{
return NULL; /*返回空指針*/
}
/*菜單選擇函數*/
menu_select()
{int n;
struct date d; /*定義時間結構體*/
getdate(d); /*讀取系統日期並把它放到結構體d中*/
printf(“press any key to enter the menu……”); /*按任一鍵進入主菜單*/
getch(); /*從鍵盤讀取一個字符,但不顯示於屏幕*/
clrscr(); /*清屏*/
printf(“********************************************************************************\n”);
printf(“\t\t Welcome to\n”);
printf(“\n\t\t The student score manage system\n”);
printf(“*************************************MENU***************************************\n”);
printf(“\t\t\t1. Enter the record\n”); /*輸入學生成績記錄*/
printf(“\t\t\t2. Print the record\n”); /*顯示*/
printf(“\t\t\t3. Search record on name\n”); /*尋找*/
printf(“\t\t\t4. Delete a record\n”); /*刪除*/
printf(“\t\t\t5. Sort to make new a file\n”); /*排序*/
printf(“\t\t\t6. Insert record to list\n”); /*插入*/
printf(“\t\t\t7. Save the file\n”); /*保存*/
printf(“\t\t\t8. Load the file\n”); /*讀取*/
printf(“\t\t\t9. Quit\n”); /*退出*/
printf(“\n\t\t Made by Hu Haihong.\n”);
printf(“********************************************************************************\n”);
printf(“\t\t\t\t%d\\%d\\%d\n”,d.da_year,d.da_mon,d.da_day); /*顯示當前系統日期*/
do{
printf(“\n\t\t\tEnter your choice(1~9):”);
scanf(“%d”,n);
}while(n1||n9); /*如果選擇項不在1~9之間則重輸*/
return(n); /*返回選擇項,主函數根據該數調用相應的函數*/
}
/*輸入函數*/
STUDENT *create()
{int i,s;
STUDENT *head=NULL,*p; /* 定義函數.此函數帶回一個指向鏈表頭的指針*/
clrscr();
for(;;)
{p=(STUDENT *)malloc(LEN); /*開闢一個新的單元*/
if(!p) /*如果指針p為空*/
{printf(“\nOut of memory.”); /*輸出內存溢出*/
return (head); /*返回頭指針,下同*/
}
printf(“Enter the num(0:list end):”);
scanf(“%s”,p-num);
if(p-num[0]==’0′) break; /*如果學號首字符為0則結束輸入*/
printf(“Enter the name:”);
scanf(“%s”,p-name);
printf(“Please enter the %d scores\n”,3); /*提示開始輸入成績*/
s=0; /*計算每個學生的總分,初值為0*/
for(i=0;i3;i++) /*3門課程循環3次*/
{
do{
printf(“score%d:”,i+1);
scanf(“%d”,p-score[i]);
if(p-score[i]0 || p-score[i]100) /*確保成績在0~100之間*/
printf(“Data error,please enter again.\n”);
}while(p-score[i]0 || p-score[i]100);
s=s+p-score[i]; /*累加各門成績*/
}
p-sum=s; /*將總分保存*/
p-average=(float)s/3; /*先用強制類型轉換將s轉換成float型,再求平均值*/
p-order=0; /*未排序前此值為0*/
p-next=head; /*將頭結點做為新輸入結點的後繼結點*/
head=p; /*新輸入結點為新的頭結點*/
}
return(head);
}
/* 顯示全部記錄函數*/
void print(STUDENT *head)
{int i=0; /* 統計記錄條數*/
STUDENT *p; /*移動指針*/
clrscr();
p=head; /*初值為頭指針*/
printf(“\n************************************STUDENT************************************\n”);
printf(“——————————————————————————-\n”);
printf(“| Rec | Num | Name | Sc1 | Sc2 | Sc3 | Sum | Ave | Order |\n”);
printf(“——————————————————————————-\n”);
while(p!=NULL)
{
i++;
printf(“| %3d | %4s | %-4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n”,
i, p-num,p-name,p-score[0],p-score[1],p-score[2],p-sum,p-average,p-order);
p=p-next;
}
printf(“——————————————————————————-\n”);
printf(“**************************************END**************************************\n”);
}
/*查找記錄函數*/
void search(STUDENT *head)
{STUDENT *p; /* 移動指針*/
char s[5]; /*存放姓名用的字符數組*/
clrscr();
printf(“Please enter name for searching.\n”);
scanf(“%s”,s);
p=head; /*將頭指針賦給p*/
while(strcmp(p-name,s) p != NULL) /*當記錄的姓名不是要找的,或指針不為空時*/
p=p-next; /*移動指針,指向下一結點*/
if(p!=NULL) /*如果指針不為空*/
{printf(“\n*************************************FOUND************************************\n”);
printf(“——————————————————————————-\n”);
printf(“| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n”);
printf(“——————————————————————————-\n”);
printf(“| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n”,
p-num,p-name,p-score[0],p-score[1],p-score[2],p-sum,p-average,p-order);
printf(“——————————————————————————-\n”);
printf(“***************************************END**************************************\n”);
}
else
printf(“\nThere is no num %s student on the list.\n”,s); /*顯示沒有該學生*/
}
/*刪除記錄函數*/
STUDENT *delete(STUDENT *head)
{int n;
STUDENT *p1,*p2; /*p1為查找到要刪除的結點指針,p2為其前驅指針*/
char c,s[6]; /*s[6]用來存放學號,c用來輸入字母*/
clrscr();
printf(“Please enter the deleted num: “);
scanf(“%s”,s);
p1=p2=head; /*給p1和p2賦初值頭指針*/
while(strcmp(p1-num,s) p1 != NULL) /*當記錄的學號不是要找的,或指針不為空時*/
{p2=p1; /*將p1指針值賦給p2作為p1的前驅指針*/
p1=p1-next; /*將p1指針指向下一條記錄*/
}
if(strcmp(p1-num,s)==0) /*學號找到了*/
{printf(“**************************************FOUND************************************\n”);
printf(“——————————————————————————-\n”);
printf(“| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n”);
printf(“——————————————————————————-\n”);
printf(“| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n”,
p1-num,p1-name,p1-score[0],p1-score[1],p1-score[2],p1-sum,p1-average,p1-order);
printf(“——————————————————————————-\n”);
printf(“***************************************END**************************************\n”);
printf(“Are you sure to delete the student Y/N ?”); /*提示是否要刪除,輸入Y刪除,N則退出*/
for(;;)
{scanf(“%c”,c);
if(c==’n’||c==’N’) break; /*如果不刪除,則跳出本循環*/
if(c==’y’||c==’Y’)
{
if(p1==head) /*若p1==head,說明被刪結點是首結點*/
head=p1-next; /*把第二個結點地址賦予head*/
else
p2-next=p1-next; /*否則將一下結點地址賦給前一結點地址*/
n=n-1;
printf(“\nNum %s student have been deleted.\n”,s);
printf(“Don’t forget to save.\n”);break; /*刪除後就跳出循環*/
}
}
}
else
printf(“\nThere is no num %s student on the list.\n”,s); /*找不到該結點*/
return(head);
}
/*排序函數*/
STUDENT *sort(STUDENT *head)
{int i=0; /*保存名次*/
STUDENT *p1,*p2,*t,*temp; /*定義臨時指針*/
temp=head-next; /*將原表的頭指針所指的下一個結點作頭指針*/
head-next=NULL; /*第一個結點為新表的頭結點*/
while(temp!=NULL) /*當原表不為空時,進行排序*/
{
t=temp; /*取原表的頭結點*/
temp=temp-next; /*原表頭結點指針後移*/
p1=head; /*設定移動指針p1,從頭指針開始*/
p2=head; /*設定移動指針p2做為p1的前驅,初值為頭指針*/
while(t-averagep1-averagep1!=NULL) /*作成績平均分比較*/
{
p2=p1; /*待排序點值小,則新表指針後移*/
p1=p1-next;
}
if(p1==p2) /*p1==p2,說明待排序點值大,應排在首位*/
{
t-next=p1; /*待排序點的後繼為p*/
head=t; /*新頭結點為待排序點*/
}
else /*待排序點應插入在中間某個位置p2和p1之間,如p為空則是尾部*/
{
t-next=p1; /*t的後繼是p1*/
p2-next=t; /*p2的後繼是t*/
}
}
p1=head; /*已排好序的頭指針賦給p1,準備填寫名次*/
while(p1!=NULL) /*當p1不為空時,進行下列操作*/
{
i++; /*結點序號*/
p1-order=i; /*將結點序號賦值給名次*/
p1=p1-next; /*指針後移*/
}
printf(“Sorting is sucessful.\n”); /*排序成功*/
return (head);
}
/*插入記錄函數*/
STUDENT *insert(STUDENT *head,STUDENT *new)
{STUDENT *p0,*p1,*p2;
int n,sum1,i;
p1=head; /*使p1指向第一個結點*/
p0=new; /*p0指向要插入的結點*/
printf(“\nPlease enter a new record.\n”); /*提示輸入記錄信息*/
printf(“Enter the num:”);
scanf(“%s”,new-num);
printf(“Enter the name:”);
scanf(“%s”,new-name);
printf(“Please enter the %d scores.\n”,3);
sum1=0; /*保存新記錄的總分,初值為0*/
for(i=0;i3;i++)
{
do{
printf(“score%d:”,i+1);
scanf(“%d”,new-score[i]);
if(new-score[i]100||new-score[i]0)
printf(“Data error,please enter again.\n”);
}while(new-score[i]100||new-score[i]0);
sum1=sum1+new-score[i]; /*累加各門成績*/
}
new-sum=sum1; /*將總分存入新記錄中*/
new-average=(float)sum1/3;
new-order=0;
if(head==NULL) /*原來的鏈表是空表*/
{head=p0;p0-next=NULL;} /*使p0指向的結點作為頭結點*/
else
{while((p0-averagep1-average)(p1-next!=NULL))
{p2=p1; /*使p2指向剛才p1指向的結點*/
p1=p1-next; /*p1後移一個結點*/
}
if(p0-average=p1-average)
{if(head==p1)head=p0; /*插到原來第一個結點之前*/
else p2-next=p0; /*插到p2指向的結點之後*/
p0-next=p1;}
else
{p1-next=p0;p0-next=NULL;} /*插到最後的結點之後*/
}
n=n+1; /*結點數加1*/
head=sort(head); /*調用排序的函數,將學生成績重新排序*/
printf(“\nStudent %s have been inserted.\n”,new-name);
printf(“Don’t forget to save the new file.\n”);
return(head);
}
/*保存數據到文件函數*/
void save(STUDENT *head)
{FILE *fp; /*定義指向文件的指針*/
STUDENT *p; /* 定義移動指針*/
char outfile[10];
printf(“Enter outfile name,for example c:\\score\n”);
scanf(“%s”,outfile);
if((fp=fopen(outfile,”wb”))==NULL) /*為輸出打開一個二進制文件,為只寫方式*/
{
printf(“Cannot open the file\n”);
return; /*若打不開則返回菜單*/
}
printf(“\nSaving the file……\n”);
p=head; /*移動指針從頭指針開始*/
while(p!=NULL) /*如p不為空*/
{
fwrite(p,LEN,1,fp); /*寫入一條記錄*/
p=p-next; /*指針後移*/
}
fclose(fp); /*關閉文件*/
printf(“Save the file successfully!\n”);
}
/* 從文件讀數據函數*/
STUDENT *load()
{STUDENT *p1,*p2,*head=NULL; /*定義記錄指針變量*/
FILE *fp; /* 定義指向文件的指針*/
char infile[10];
printf(“Enter infile name,for example c:\\score\n”);
scanf(“%s”,infile);
if((fp=fopen(infile,”rb”))==NULL) /*打開一個二進制文件,為只讀方式*/
{
printf(“Can not open the file.\n”);
return(head);
}
printf(“\nLoading the file!\n”);
p1=(STUDENT *)malloc(LEN); /*開闢一個新單元*/
if(!p1)
{
printf(“Out of memory!\n”);
return(head);
}
head=p1; /*申請到空間,將其作為頭指針*/
while(!feof(fp)) /*循環讀數據直到文件尾結束*/
{
if(fread(p1,LEN,1,fp)!=1) break; /*如果沒讀到數據,跳出循環*/
p1-next=(STUDENT *)malloc(LEN); /*為下一個結點開闢空間*/
if(!p1-next)
{
printf(“Out of memory!\n”);
return (head);
}
p2=p1; /*使p2指向剛才p1指向的結點*/
p1=p1-next; /*指針後移,新讀入數據鏈到當前表尾*/
}
p2-next=NULL; /*最後一個結點的後繼指針為空*/
fclose(fp);
printf(“You have success to read data from the file!\n”);
return (head);
}
簡單的C語言題目,要考試了,求大神幫助
#includestdio.h
int main()
{char s1[200],s2[200],*p,*q;
int k,m;
gets(s1);
scanf(“%d%*c”,k);
gets(s2);
for(m=0;s2[m];m++);
p=s1+k;
for(q=p;*q;q++);
for(;q=p;q–)*(q+m)=*q;
for(q=s2;*q;*p++=*q++);
puts(s1);
return 0;
}
C語言考試題
我來回答下把:
1.1
2.9
解釋:t = (ab)?a:b等價於t = ((ab)?a:b),這下應該知道了把
3.96 `(和~鍵是同一個鍵)
解釋:a=96;96是那個字符的ACSII碼值的十進制表示,它的十六進制表示的ASCII碼值為60,你可以對96進行除16取余法得到60,然後你去查看下字符的ASCII碼 16進制表示的那個表就會發現,它對應的是這個字符,所以就是他了,別和單引號混淆就好,單引號的ASCII碼十六進制表示為27
4.a[0] a[1] a[2]
5.1600
6.文本文件 二進制文件 [這個拿的不是很准]
7.fopen fclose fseek
下面:
1.C
解釋:a+=a-=a*=a,首先要知道+=,-=,*=的優先級是相同的,但是他們的結合性是由右向左的,所以,他相當於a+=a-=(a=a*a),你還要知道,這是在同一條語句中多次修改同一個變量的值,這裡有結合性,可以保證,但是有的時候並不可以,因為語言中明確規定,求值順序未定義,一般儘可能不要在同一條語句里多次修改同一個變量的值,有的時候還和編譯器有關的,a+=a-=(a=a*a)相當於a+=(a=a-(a=a*a)),在a=(a+(a=a-(a=a*a))),所以為0
2.B
3.D
解釋:你定義一個帶參數的宏#define ADD(x) (x)+(x)
你要知道,宏替換是機械化的替換,不會很智能化的,也就是說
在這裡,替換的時候是替換成了這樣d=(a+b)+(a+b)*c;所以最後就是80了
4. A
解釋:這樣理解把, char a[5]; char *p=a;這個是把數組的首地址賦給指針p來初始化指針,你後面再加一句p=”abcd”;不就是對指針的賦值嗎,使指針不再指向數組的首地址,而是指向了字符串的首地址了.相信char *p=”abcd”;很常見把,呵呵…
5.C
解釋:因為k=2,然後執行關係表達式k==0,結果顯然判斷結果為假,所以不執行循環體
6.C
7.A
指針是不能相加的
8.D
解釋:這個應該好好解釋下,這個題還好了
struct st{ int n;struct st *next;};
static struct st a[3]={5,a[1],7,a[2],9,‘\0’},*p; p=a[0];
A p++-n B p-n++ C (*p).n++ D ++p-n
分析:首先你要知道,這是定義了一個結構體數組,這個static struct st a[3]={5,a[1],7,a[2],9,‘\0’}寫的易讀一點就是static struct st a[3]={{5,a[1]},{7,a[2]},{9,’\0′}},是不是明了了好多.
你做這個題目之前還需要明白一點,即箭頭操作符的優先級高於++運算符,然後分析選項
選項A.p++是後綴加,所以執行(p++)-n(即p++-n) 相當於執行p-n,即得到的值是5
選項B. p-n++相當於(p-n)++,由於是後綴加,所以得到的值也是5
選項C.(*p).n++ 就是相當於((*p).n)++,更相當於(p-n)++,所以和上面的是一樣的,也是5,為什麼它相當於它呢,這就要你看看箭頭操作符的由來了,箭頭操作符的由來就是為了結合解引用操作符*和點操作符.於一起的.來簡化書寫,增加可讀性
選項D.++p-n 相當於++(p-n),由於是前綴加,所以得到的值為6了
9.C,選擇W會格式化
10. B ,數組名其實就相當於一個指針,這裡對指針做運算,加1使指針下移
寫出運行結果:
1.
10623-9003
2.
6 7 8
填空題:
1.
#include stdio.h
#include math.h
2. 2
3.break;
4.k+1
編程題:
1.代碼如下:
#includestdio.h
int main()
{
int i,n;
long s=1;
scanf(“%d”,n);
for(i=1;i=n;i++)
s*=i;
printf(“%ld”,s);
return 0;
}
2.代碼如下
#includestdio.h
int main()
{
int i,s=0;
for(i=1;i=100;i++)
s+=i;
printf(“%d”,s);
return 0;
}
應該沒錯把,樓主有什麼問題可以發消息給我
C語言題目,100分懸賞
/*
第一題:已知某班N(〈=50)名學生進行了高數、英語和C語言等3門課考試,將3門課
的成績以及計算3門課的總分存放於一個二維數組中,將學生姓名存放在另一個二維字
符數組中,按總分(由高到低)將學生姓名排序並輸出排序結果(序號和姓名)。
*/
#include “stdafx.h”
#include “stdio.h”
struct scoreInfo{
int scoreMath;
int scoreProC;
int scoreEng;
int scorSum;
};
struct studentInfo{
char name[20];
struct scoreInfo _scoreInfo;
};
void inputInfo(struct studentInfo *stu,int n)
{
int i = 0;
for(i = 0; i n; i++)
{
printf(“第%d個學生的姓名:”,i+1);
gets(stu[i].name);
printf(“第%d個學生的數學成績:”,i+1);
scanf(“%d”,stu[i]._scoreInfo.scoreMath);
getchar();
printf(“第%d學生的C語言成績:”,i+1);
scanf(“%d”,stu[i]._scoreInfo.scoreProC);
getchar();
printf(“第%d個學生的英語成績:”,i+1);
scanf(“%d”,stu[i]._scoreInfo.scoreEng);
getchar();
}
printf(“\n”);
}
void outputInfo(struct studentInfo *stu,int n)
{
int i = 0;
for (i = 0; i n; i++)
{
stu[i]._scoreInfo.scorSum = stu[i]._scoreInfo.scoreEng + stu[i]._scoreInfo.scoreMath
+ stu[i]._scoreInfo.scoreProC;
}
printf(“姓名\t數學成績\tC語言成績\t英語成績\t總分\n”);
for (i = 0; i n; i++)
{
printf(“%s\t%d\t\t%d\t\t%d\t\t%d\n”,stu[i].name,stu[i]._scoreInfo.scoreMath, stu
[i]._scoreInfo.scoreProC
,stu[i]._scoreInfo.scoreEng,stu[i]._scoreInfo.scorSum);
}
}
void arry_max_to_min(struct studentInfo *stu,int n)
{
int indexi;
int indexj;
struct studentInfo _temp;
// struct stdentInfo *ptemp;
// ptemp = stu;
for (indexi = 0; indexi n;indexi++)
{
for (indexj = indexi+1; indexj n; indexj++)
{
if (stu[indexi]._scoreInfo.scorSum stu[indexj]._scoreInfo.scorSum)
{
_temp = stu[indexj];
stu[indexj] = stu[indexi];
stu[indexi] = _temp;
}
}
}
printf(“總分從高到低排列:\n”);
for (indexi = 0 ; indexi n; indexi++)
{
printf(“%s\t%d\t\t%d\t\t%d\t\t%d\n”,stu[indexi].name,stu[indexi]._scoreInfo.scoreMath, stu
[indexi]._scoreInfo.scoreProC
,stu[indexi]._scoreInfo.scoreEng,stu[indexi]._scoreInfo.scorSum);
}
}
int main()
{
int studentNum;
struct studentInfo stu[50];
printf(“輸入學生數:”);
scanf(“%d”,studentNum);
getchar();
inputInfo(stu,studentNum);
outputInfo(stu,studentNum);
arry_max_to_min(stu,studentNum);
return 0;
}
運行結果:
輸入學生數:3
第1個學生的姓名:Jack
第1個學生的數學成績:89
第1學生的C語言成績:86
第1個學生的英語成績:96
第2個學生的姓名:Tom
第2個學生的數學成績:95
第2學生的C語言成績:94
第2個學生的英語成績:92
第3個學生的姓名:Star
第3個學生的數學成績:98
第3學生的C語言成績:78
第3個學生的英語成績:89
姓名 數學成績 C語言成績 英語成績 總分
Jack 89 86 96 271
Tom 95 94 92 281
Star 98 78 89 265
總分從高到低排列:
Tom 95 94 92 281
Jack 89 86 96 271
Star 98 78 89 265
Press any key to continue
/*
第二題:編寫函數fun(char s[ ], int num[ ]),其功能是統計字符串 s 中數字字符、大寫字母、
小寫字母和空格字符的出現次數,統計結果存於num數組中。再設計main函數,調用fun函數,
實現預期功能。
*/
#include “stdafx.h”
#include “stdio.h”
#include “string.h”
void fun(char *s, int *num)
{
int length;
int index;
int sum_number = 0;
int sum_char = 0;
int sum_spac = 0;
int sum_CHAR = 0;
length = strlen(s);
for (index = 0; index length; index++)
{
if ((*s = ‘0’) (*s = ‘9’) )
{
sum_number++;
}
if ((*s = ‘a’) (*s ‘z’) )
{
sum_char++;
}
if ((*s = ‘A’) (*s = ‘Z’) )
{
sum_CHAR++;
}
if (*s == 0x20 )
{
sum_spac++;
}
s++;
}
num[0] = sum_number;
num[1] = sum_CHAR;
num[2] = sum_char;
num[3] = sum_spac;
}
int main()
{
char testarry[50];
int num[4];//用來放數字num[0],num[1]大寫字母,num[2]小寫字母,num[3]空格數字的個數
//num = (int *)malloc(sizeof(int) * 4);
printf(“請輸入字符串:”);
gets(testarry);
fun(testarry,num);
// printf(“%s”,testarry);
printf(“數字的個數:%d\n大寫字母的個數:%d\n小寫字母的個數:%d\n空格數字的個數:%d\n”,
num[0],num[1],num[2],num[3]);
return 0;
}
運行結果:
請輸入字符串:12345 AFASDFE 74897 asfdasf
數字的個數:10
大寫字母的個數:7
小寫字母的個數:7
空格數字的個數:3
Press any key to continue
第三題:
#include “stdafx.h”
#include “stdio.h”
int main()
{
int i;
int j;
int k;
int half = 0;
char prin;
prin = ‘A’;
for (i = 0; i 26; i++)
{
prin = ‘A’;
for (j = 26-i-1;j 0; j–)
{
printf(” “);
}
for (k = 1; k= 2*i+1 ;k++)
{
half = k;
if (–half = i)
{
printf(“%c”,prin++);
}
else
{
printf(“%c”,–prin – 1);
}
}
printf(“\n”);
}
return 0;
}
運行結果:
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
Press any key to continue
[附加說明:]由於百度在欄目里屏蔽了空格和TAB,所以看不出效果,把
需要的話你可以把Email給我 我發給你。打印效果這個上面看不出來。呵呵
Press any key to continue
幫我找點C語言的考試題唄!
C語言綜合考試題
班級____________
姓名_____________
學號______________
總分_____
一選擇題:(包括單選和多選)【每題2.5分】
1.一個C程序的執行是從(
)
A:本程序的main函數開始,到main函數結束
B:本程序文件的第一個函數開始,到本程序文件的最後一個函數結束
C:本程序main函數開始,到本程序文件的最後一個函數結束
D:本程序文件的第一個函數開始,到本程序main函數結束
2.一個C語言程序是由(
)
A:一個主程序和若干子程序組成
B:函數組成
C:若干過程組成
D:若干子程序組成
3.下列四組選項中,均是C語言保留字的選項是(
)
A:define,IF,type
B:getc,char,printf
C:include,scanf,case
D:while,go,pow
4.對以下各代數式中,若變量a和x均為double類型,則不正確的C語言表達式是(
)
A:(e^(x^2/2))/√2π
exp(x*x/2)/sqrt(2*3.14159)
B:
1/2(ax+(a+x)/4a)
1.0/2.0*(a*x+(a+x))/(4*a)
C:√((sinx)^2.5)
sqrt((pow(sin(x*3.14159/180),2.5)))
D:x^2-e^5
x*x-exp(5.0)
5.一下程序,輸入
25,13,10回車
正確的輸出結果是:(
)
int
x,y,z;
scanf(“%d%d%d”,x,yz);
printf(“x+y+z=%d\n”,x+y+z);
A:
x+y+z=48
B:
x+y+z=35
C:
x+z=35
D:
不確定的值
6.以下if語句正確的是(
)
A:
if(x0)printf(“%f”,x)else
printf(“%f”,-x);
B:if(x0){x=x+y;printf(“%f”,
x);}else
printf(“%f”,-x);
C:
if(x0){x=x+y;printf(“%f”,x);};else
printf(“%f”,-x);
D:if(x0);{x=x+y;printf(“%f”,x);}else
printf(“%f”,-x);
7.請閱讀以下程序,以下程序是(
)
main()
{int
a=5,b=0,c=0;If(a=b+c)printf(“*
*
*\n”);else
printf(“$
$
$\n”);}
A:有語法錯誤,無法通過編譯
B:可以通過編譯但不能通過連接
C:輸出***
D:輸出$$$
8.以下敘述正確的是(
)
A:do-while語句構成的循環不能用其它語句構成的循環來代替。
B:do-while語句構成的循環只能用break語句退出。
C:用do-while語句構成的循環,在while後的表達式為非零時結束循環。
D:用do-while語句構成的循環,在while後的表達式為零時結束循環。
9.以下程序段輸出幾顆
*(
)
for(int
i=0;i2;i++)
{
printf(“*
“);
for(int
j=0;j2;j++){
printf(“*
“);}}
A:4
B:6
C:8
D:2
10.程序段要輸出無限顆的*號,while的條件應該是:(
)
int
i=0;
while(____
)
printf(“*”);
A:i=0
B;i++
C:i=1;
D:i–
11.若二維數組a有m列,則計算任一元素a[i][j]在數組中位置的公式為(假設a[0][0]位於數組的第一個位置上。)(
)
A:i*m+j
B:j*m+I
C:j*m+j-1
D:i*m+j+1
12.定義如下變量和數組,則其輸出結果是:(
)
int
k;
int
a[3][3]={1,2,3,4,5,6,7,8,9};
for(k=0;k3;k++)
printf(“%d”,a[k][2-k]);
A:3
5
7
B:3
6
9
C:1
5
9
D:1
4
7
你的QQ好多的啦
我發給你的啦
我在我們老師那裡弄的
C語言程序設計考試題
main函數
scanf函數,printf函數
-60
6 ,4, 2
, || , !
B 66
2 1
6
main
5
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/195483.html