传奇sf诛仙私服变态传奇私服传奇合击私服传奇归来私服传奇连击私服热血传奇私服新开传奇私服诛仙sf诛仙2私服变态传奇sf中变传奇合击私服英雄合击私服1.85合击传奇私服1.76传奇私服发布网1.85传奇私服发布网连击传奇私服连击私服

首页上机实践题


刘甲耀、严桂兰教授新著作问世

Core Java应用程序设计教程

C++程序设计简明教程

C#程序设计

我校开展省级精品课程建设



软件系上机教学
 
 

指针与一维数组

xt10_1
/*p148 5.11,指针与一维数组*/
#include <stdio.h>
main()
{
float y=0.0,a[]={2.0,4.0,6.0,8.0,10.0},*p;
int i;
p=&a[1];
for(i=0;i<3;i++) y+=*(p+i);
printf("%f\n",y);
}
/*18.000000*/

xt10_2
#include <stdio.h>
main()
{
int i,j,a[]={1,2,3,4,5},*p;
for(i=0;i<5;i++)
{
p=&a[i];
for(j=0;j<5-i;j++)
printf("%d",*(p+j));
printf("\n");
}
}

xt10_4
#include <stdio.h>
main()
{
int i,j,a[]={1,2,3,4,5},*p;
for(i=4;i>=0;i--)
{
p=&a[i];
for(j=0;j<=4-i;j++)
printf("%d",*(p+j));
printf("\n");
}
}
/*5
45
345
2345
12345*/

xt10_5

#include <stdio.h>
main()
{
char a[][7]={"for","switch","do"},*str[]={"for","switch","do"};
int i;
printf("%d,%d\n",sizeof(a),sizeof(str));
for(i=0;i<3;i++) printf("%s%c",a[i],i<3?' ':'\n');
}

xt10_6

/*p148 5.16*/
#include <stdio.h>
#include <string.h>
main()
{
char s[10],*sp="HELLO";
strcpy(s,sp);
s[0]='h';s[6]='!';
printf("%s\n",s);
}

xt10_7

/*p148 5.16字符指针变量*/
#include <stdio.h>
#include <string.h>
main()
{
char s[10],*sp="HELLO";
//(*sp)++; sp不能改变字符串的内容
strcpy(s,sp);
s[0]='I'; //数组元素值可改变
printf("%s\n",s);
}

xt10_8

/*z231 24*/
#include <stdio.h>
main()
{
char ch[]="I am student!",*p;
p=ch;
printf("%p,%p\n",p,p+9);
printf("%c,%c\n",*p,*(p+9));
}

xt10_9

/*z231 24*/
#include <stdio.h>
#include <string.h>
main()
{
char ch[10],*p;
int i,j;
p=ch;
scanf("%s",ch);
j=strlen(ch);
for(i=0;i<j;i++)
printf("%c",ch[i]);
printf("\n%s\n",ch);
}

xt10_10

/*z231 24*/
#include <stdio.h>
main()
{
char ch[20],*p;
p=ch;
scanf("%s",p);
printf("%s\n",p);
}

xt10_11

/*z237 5*/
#include <stdio.h>
main()
{
int j,a[]={1,3,5,7,9,11,15},*p;
for(j=3;j;j--)
{
p=&a[j];
switch(j)
{
case 1:case 2:printf("%d ",*p);break;
case 3:printf("%d ",*p);
}
}
printf("\n");
}

xt10_12

/*z81 5.7*/
#include <stdio.h>
#include <string.h>
main()
{
char str1[5],str2[5],*s=str1,*t=str2;
gets(s);gets(t);
while((*s)&&(*t)&&(*s==*t))
{
t++;s++;
}
printf("%d\n",*s-*t);
}


xt10_21

#include <stdio.h>
main()
{
int i,j,a[]={1,2,3,4,5},*p;
for(i=0;i<5;i++)
{
p=&a[0];
for(j=0;j<i+1;j++)
printf("%d",*(p+j));
printf("\n");
}
}
/*5
45
345
2345
12345*/


 
   

2006年 私立华联学院 版权所有