c语言入门程序下载,简单实用——C语言入门程序练习
#include
#include
struct structstudent//創建結構體,表示學生信息
{
int No;//學號
char Name[20];//姓名
int Age;//年齡
}
student[3];
void saveFile()//創建函數,寫入文本
{
int i;//循環變量
FILE *fp;//聲明指向結構體的指針
if((fp=fopen("c:\\stu.txt","w"))==NULL)//打開文件
{
puts("can not open file");//文件打開失敗
exit(1);
}
for(i=0;i<3;i++)//打開成功
{
if (fwrite(&student[i],sizeof(struct structstudent),1,fp)!=1);//寫入
//第一個元素,??? 大小,?????? 1個數據塊,文件指針
{
puts("write file error");
fclose(fp);//關閉文件
exit(2);
}
}//第一個元素,大小,1個數據塊,文件指針
fclose(fp);
}
void printFile()//讀取數據打印到屏幕
{
int i=0;
FILE *fp;
struct structstudent *sp;//聲明指針
if((fp=fopen("c:\\stu.txt","r"))==NULL)//只讀操作
{
puts("can not open file");
exit(1);
}
printf("studentNo\t\Name\tAge\n");//表頭
sp=&student[0];//取第一個元素的地址,結構體地址
for(;i<3;i++,sp++)//讀操作
{
if(fread(sp,sizeof(struct structstudent),1,fp)==1)//讀入
{
printf("%d\t\t%s\t\t%d\n",sp->No,sp->Name,sp->Age);//打印
}?????????? // 制表符?????? 指針 指向運算符
}
fclose(fp);//關閉文件
}
void main()
{
int i;
puts("please input student's number,Name,Age:");
for(i=0;i<3;i++)
{
scanf("%d%s%d",&student[i].No,&student[i].Name,&student[i].Age);
}//調用函數,文件數據塊,
saveFile();???? //先寫
printf("===student info ===\n");
printFile();//再讀
}
#include
main()
{
int x,y,z,t;
scanf("%d%d%d",&x,&y,&z);
if(x>y)
{
t=x;x=y;y=t;
}
if(y>z)
{
t=y;y=z;z=y;
}
if(z>x)
{
t=z;z=x;x=t;
}
printf("small to big:%d %d %d\n",x,y,z);
}
#include
main()
{
long f1,f2;
int i;
f1=f2=1;
for(i=1;i<=20;i++)
{
printf("%12ld%12ld",f1,f2);
if(i%2==0)
printf("\n");
f1=f1+f2;
f2=f1+f2;
}
}
**#include
main()
{
int i,j,k,n;
printf("water flowers is: ");
for(n=100;n<1000;n++)
{
i=n/100;
j=n/10%10;
k=n%10;
if(n==i*i*i+j*j*j+k*k*k)
printf("%-5d",n);
}
}
總結
以上是生活随笔為你收集整理的c语言入门程序下载,简单实用——C语言入门程序练习的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux 读取png图片,linux
- 下一篇: 程序设计基础c语言第二版巫,程序设计基础