程式語言
10/30/2007
10/22/2007
4.4 == 請同學練習找出下列程式錯誤之處並修正
#include
int maim( void ) {
float fMiles;
int iCount, iNum;
double dDist, dTemp;
/* [a] : Announce program
printf( "STORAGE.C will illustrate how variables are stored in memory \n" );
printf( "------------------------------------------------------------ \n" );
/* [b] : Now list variables and their addresses. */
printf( "\"fMiles\" occupies %i bytes of storage that begins at location %x\n",
sizeof( float ), &fMiles );
printf( "\"iCount\" occupies %i bytes of storage that begins at location %x\n",
sizeof( int ), &iCount );
printf( "\"iNum\" occupies %i bytes of storage that begins at location %x\n",
sizeof( int ), iNum );
printf( "\"dDist\" occupies %i bytes of storage that begins at location %x\n",
sizeof( double ), &dDist );
printf( "\"dTemp\" occupies %i bytes of storage that begins at location %x\n",
sizeof( double ), &dTemp );}
}
10/16/2007
4.3 == 請同學練習找出下列程式錯誤之處並修正
*/
#include
int main( void ) {
enum day { Sun = 1, Mon, Tue, Wed, Thur, Fri, Sat };
enum day eDay;
eDay = Sunny;
printf("Day %4d is on the weekend\n", eDay);
eDay = Mon;
printf("Day %4d is a work day \n", eDay);
eDay = Tue;
printf("Day %4d" is a work day \n", eDay);
eDay = Wed;
printf("Day %4d is a work day \n", eDay);
eDay = Thur;
printf("Day %4d is a work day \n", eDay);
eDay = Fri;
printf("Day %4d is a work day \n", eDay);
eDay = Sat;
printf("Day %4d is on the weekend\n", eDay");}
10/15/2007
4.2 == 請同學練習找出下列程式錯誤之處並修正
int main( void ) {
char cName;
float fMiles;
int iCount;
double dDist;
/* [a] : Announce program */
printf( "STORAGE1.C : print size of basic data types \n" );
printf( "------------------------------------------- \n" );
/* [b] : Now list variables and their addresses. */
printf( "\"cName" occupies %2i bytes of storage\n", sizeof( char ));
printf( ""fMiles\" occupies %2i bytes of storage\n", sizeof( float ));
printf( ""iCount" occupies %2i bytes of storage\n", sizeof( int ));
printf( ""dDist" occupies %2i bytes of storage\n", sizeof( double ));
10/08/2007
3.2 == 請同學練習找出下列程式錯誤之處並修正
#include
#include
int main( void ) {
float fRadius; /* Radius of circle */
float fArea; /* Area of circle */
/* [a] : Prompt User for "radius of circle" */
printf("============================================\n");
printf("Please input the circle radius (Radius > 0):");
scanf("%f", &fRadius);
/* [b] : Check that the radius in greater than zero */
if( fRadius <= 0 ) {
printf("ERROR >> Circle radius must be greater than zero\n");
exit (1);
}
/* [c] : Compute Area of Circle */
fPi = 4.0*atan( 2.0 );
fArea = fPi*fRadius*fRadius;
/* [d] : Print Radius and Area */
printf("Radius of Circle = %8.3f \n", fRadius );
printf("Area of Circle = %8.3f \n", fArea );
return (0);
}
3.1 == 請同學練習找出下列程式錯誤之處並修正 98/10/
#define PI 3.1415926
int main( void ) {
/* [a] : Print pi with default floating point output */
printf("My First Program : PI = %f \n, PI" );
/* [b] : Now experiment with conversion specifications */
printf("My First Program : PI = %14.7f \n", PI );
printf("My First Program : PI = %14.7e \n", PI );
printf("My First Program : PI = %14.7E \n", PI );
printf("My First Program : PI = %14.7g \n", PI );
printf("My First Program : PI = %14.7G \n", PI );
printf("My First Program : PI = %-14.7f \n", PI );
printf("My First Program : PI = %-14.7e \n", PI );
}