c语言程序例
Ⅰ c语言实例
/*看你挂了一天都没人帮忙,实在是看不过去了.我来给你写.*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void main()
{
FILE *fp;
char c;
int a[5]={0};
if((fp=fopen("data.txt","r"))==NULL)
{
printf("can not open the date.txt\n");
exit(0);
}
c=fgetc(fp);
while(c!=EOF)
{
if(((c>='a')&&(c<='z'))||((c>='A')&&(c<='Z')))
{
a[0]++;
}
if((c>='0')&&(c<='9'))
{
a[1]++;
}
if(c==' ')
{
a[2]++;
}
if(c==',')
{
a[3]++;
}
if(c=='.')
{
a[4]++;
}
c=fgetc(fp);
}
fclose(fp);
printf("############the result is :###########\n");
printf("\n 英文 数字 空格 逗号 句号\n");
for(int i=0;i<5;i++)
printf("%6d",a[i]);
printf("\n");
}
Ⅱ c语言程序举例
printf();就是输出函数
只有在引号里的内容才会被输出
第四行输出x y的目的是为了显示你输入的版数据
让你知权道这两个数要交换
t=x;x=y;y=t;
是交换x y的数据
printf("x=%d y=%d\n",x,y);
是显示交换后的结果