sum2+=a[i][j];
a[3][j]=sum2/3;
}
for(i=0;i<4;i++)
{ for(j=0;j<5;j++)
printf("%6.2f",a[i][j]);
printf("\n");
}
}
8、/*完善程序,实现将输入的字符串反序输出,
如输入windows 输出swodniw。*/
#include <string.h>
main()
{ char c[200],c1;
int i,j,k;
printf("Enter a string: ");
scanf("%s",c);
k=strlen(c);
for (i=0,j=k-1;i<k/2;i++,j--)
{ c1=c[i];c[i]=c[j];c[j]=c1; }
printf("%s\n",c);
}
指针法:
void invert(char *s)
{int i,j,k;
char t;
k=strlen(s);
for(i=0,j=k-1;i<k/2;i++,j--)
{ t=*(s+i); *(s+i)=*(s+j); *(s+j)=t; }
}
main()
{ FILE *fp;
char str[200],*p,i,j;
if((fp=fopen("p9_2.out","w"))==NULL)
{ printf("cannot open the file\n");
exit(0);
}
printf("input str:\n");
gets(str);
printf(“\n%s”,str);
fprintf(fp,“%s”,str);
invert(str);