C語(yǔ)言練習(xí)



[例1.1] Hello程序
main()
{
printf("Hello!\n");
}

[例1.2] 兩個(gè)數(shù)相加
main()
{
int a,b,sum; /* 變量說(shuō)明 */
scanf("%d,%d",&a,&b);
sum=a+b;
printf("Sum=%d\n",sum);
}

[例2.1] 符號(hào)常量????
#define PI 3.1415926
main()
{ float r,area;
scanf("%f",&r);
area=PI*r*r;
printf("圓的面積為:%f\n",area);
}

[例2.2] 不同整型數(shù)據(jù)進(jìn)行的混合運(yùn)算
main()
{ int a,b,c,d; /* 定義a,b,c,d為整型變量 */
unsigned u; /* 定義u為無(wú)符號(hào)整型變量 */
a=12;b=-24;u=10;
c=a+u;d=b+u;
printf("a+u=%d,b+u=%d\n",c,d);
}
結(jié)果:22? -14

[例2.3] 實(shí)型變量的說(shuō)明及精度
main()
{ float x;
double y;
x=111111.111;
y=111111.111;
printf("x=%f,y=%f\n",x,y);
}

[例2.5] 字符型數(shù)據(jù)
main()
{ char c1,c2;
c1='A';? c2='B';
printf("%c,%c",c1,c2);
}


標(biāo)簽: