当前位置:首页 > c语言阅读程序题
{
int i,k=sqrt(n); for(i=2;i<=k;i++)
if(n%i==0) return 0; return 1; }
int encode(int a[][4]) {
int i,j,k=0;
for(i=0;i<4;i++)
for(j=0;j<=i;j++)
if(prime(a[i][j])) {
while(!prime(a[i][j]+=2));k++;/*求大于它的最小素数*/ } return k; } main() {
FILE *fp;
int a[4][4]={3,6,4,17,8,5,9,10,12,19,7,20,4,14,21,23},i,j,count=0; if((fp=fopen(\
{printf(\ count=encode(a); for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{fprintf(fp,\ printf(\ }
fprintf(fp,\ }
fprintf(fp,\ fclose(fp);
}
改错题目:
下列程序中函数divfun的功能是对于s指向的一个含有数字字符和非数字字符的字符串(串长不超过80),将其中连续的数字字符转换为一个整数,如果连续的数字字符个数超过4个,则以4个数字字符为一组进行转换。将转换后生成的整数一次存放到整型数组a中。函数返回a数组中整数的个数。例如:若输入的字符串”c123yz45!
786 *56abc123456789”,则a数组中的数值分别为:{123,45,786,56,1234,5678,9} #include
#include
void divfun(char *s, int a) {
char *p=s; int i=0,k,sum; while(*p)
if(isdigit(*p)) {
sum=*p-'0';p++;k=1; while(isdigit(*p)) {
k++;
if(k<=4){sum=sum+*p-'0';p++;} else{a[i++]=sum;
k=1;sum=*p-'0';p++; } }
a[i++]=sum; } else p++; return i-1; } main() {
char *str;int i,n,num[40]; gets(str);n=divfun(str,num); puts(str);
for(i=0;i<=n;i++)
printf(\ printf(\ }
编程题目:
编写函数int value(int bb[ ]),在三位正整数中寻找所有符合以下条件的正整数:它既是完全平方数并且又有两位数字相同。例如:144是12的平方并且有两位数字相同,因此144是符合条件的数。将找到的数按从小到大的次序依次存入bb数组中,函数返回bb数组中有效数据的个数
编写main函数,调用函数value,将结果数组中全部有效数据按照每行5个数据的格式保存到文件myf2.out中。
符合上述条件的整数有:100,121,144,225,400,441,484,676,900
1.将源文件取名为myf2.c,输出结果文件取名为myf2.out。 ?
2.数据文件的打开、使用和关闭等操作均用C标准库中缓冲文件系统的文件操作函数 实现。
3.源程序文件和运行结果文件均须保存在T:盘的根目录下,供阅卷用。 4.不要将myf2.obj、myf2.exe保存到T:盘中。
改错题目答案:
(1) void divfun(char *s, int a)
修改为:int divfun(char *s, int a) (2) void divfun(char *s, int a)
修改为:int divfun(char *s, int a[ ])
(3) if(k<=4){sum=sum+*p-'0';p++;}
修改为:if(k<=4){sum=sum*10+*p-'0';p++;} (4) char *str;
修改为:char str[80]; 编程题目答案: #include
int value(int bb[ ]) {
int i,i2,j=0,a,b,c; for(i=10;i<32;i++) {
i2=i*i;
a=i2/100; b=i2/10;
c=i2;
if((a==b||b==c||c==a)&&!(a==b&&b==c)) /*两个数相同*/ bb[j++]=i2; } return j; }
main(){
int i,n,zz[32]={0};
FILE *fp;
if((fp=fopen(\ { printf(\exit(0);}
n=value(zz); for(i=0;i fprintf(fp,(i+1)%5?\ fprintf(fp,\ fclose(fp);} 江苏计算机C语言结构体与共同体考核 考点1:结构体 例题:已知有结构体定义和变量声明如下:(2008秋) struct student {char name[20]; int score; struct student *h; }stu, *p; int *q; 以下选项中错误的是_________ A.p=&stu; B.q=&stu.score; C.scanf(“%s%d”,&stu); D.stu.h=p; 例题:以下程序运行时输出结果的第一行是________,第二行是__________ #include }*p; int d[5]={10,20,30,40,50}; struct s a[5]={100,&d[0],200,&d[1],300,&d[2],400,&d[3],500,&d[4]}; void main() {p=a; printf(“]”,p->x++); printf(“]\\n”,p->x); printf(“]”,*p->y); printf(“]\\n”,*++p->y); } 考点2:处理链表 例题:以下程序的功能是:函数struct node *insert(struct node *head, struct node *p)将p指向的结点作为首结点插入head指向的链表中,main函数接收从键盘输入的一行字符,每接收一个字符后,申请一个新节点保存该字符,并调用insert函数将新结点插入链表中,最后从表头开始一次输出该链表个结点成员c的值,试完善程序以达到要求的功能 #include struct node *next; }; void main() {struct node *insert(struct node *head, struct node *p); char ch; struct node *head,*p; head=NULL; while((ch=getchar())!=?\\n?) {p=(struct node *)malloc(sizeof(struct node)); _______________=ch; p->next=NULL;
共分享92篇相关文档