2009年10月13日 星期二

程式語言 練習

70 points

程式語言 第五課 part2

/*
* ======================================================================
* Print Days of the work week and weekend
*
* Copyright (C) 1998 by Mark Austin and David Mazzoni.
*
* This software is provided "as is" without express or implied warranty.
* Permission is granted to use this software on any computer system,
* and to redistribute it freely, subject to the following restrictions:
*
* 1. The authors are not responsible for the consequences of use of
* this software, even if they arise from defects in the software.
* 2. The origin of this software must not be misrepresented, either
* by explicit claim or by omission.
* 3. Altered versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
* 4. This notice is to remain intact.
*
* Written by : David Mazzoni.
* ======================================================================
*/

#include

int main( void ) {
enum day { Sun = 1, Mon, Tue, Wed, Thur, Fri, Sat };
enum day eDay;

eDay = Sun;
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);
}

程式語言 第五課 part1

/*
* =====================================================================
* Print size of basic data types in C.
*
* Copyright (C) 1994-96 by Mark Austin and David Mazzoni.
*
* This software is provided "as is" without express or implied warranty.
* Permission is granted to use this software on any computer system,
* and to redistribute it freely, subject to the following restrictions:
*
* 1. The authors are not responsible for the consequences of use of
* this software, even if they arise from defects in the software.
* 2. The origin of this software must not be misrepresented, either
* by explicit claim or by omission.
* 3. Altered versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
* 4. This notice is to remain intact.
*
* Written By : D. Mazzoni and M. Austin January 1994
* =====================================================================
*/

#include

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 ));

}

程式語言 debug 3

#include /* Standard Input/Output function declarations */
#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);

}

===============================================================================

#include /* Standard Input/Output function declarations */
#include

int main( void )
{
float fRadius; /* Radius of circle */
float fArea; /* Area of circle */
float fPi; /*Variable for "Pi" */
/* [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( 1.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);

}

程式語言 debug 2

#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 );
}

=======================================================================

#include
#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 );
}

2009年9月29日 星期二

程式語言 第三課 part3

/* * =========================================================================== * Compute Area of a Circle : Coefficients are defined in main program. * : Radius and area of circle are printed to screen. * * Copyright (C) 1998 by Mark Austin and David Chancogne. * * This software is provided "as is" without express or implied warranty. * Permission is granted to use this software on any computer system, * and to redistribute it freely, subject to the following restrictions: * * 1. The authors are not responsible for the consequences of use of * this software, even if they arise from defects in the software. * 2. The origin of this software must not be misrepresented, either * by explicit claim or by omission. * 3. Altered versions must be plainly marked as such, and must not * be misrepresented as being the original software. * 4. This notice is to remain intact. * * Written by: Mark Austin January, 1994 * =========================================================================== */
#include /* Standard Input/Output function declarations */#include /* Math functions, such as sqrt(x), and constant M_PI */#include
int main( void ) {float fRadius; /* Radius of circle */float fArea; /* Area of circle */float fVolume; /* Volume of circle */float fPi; /* Variable for "pi" */
/* [a] : Prompt User for "radius of circle" */
printf("============================================\n"); printf("請輸入要計算的圓半徑 (半徑需大於0):"); scanf("%f", &fRadius);
/* [b] : Check that the radius in greater than zero */
if( fRadius <= 0 ) { printf("ERROR >> 圓半徑必需大於0 \n"); exit (1); }
/* [c] : Compute Area and Volume of Circle */
fPi = 4.0*atan( 1.0 ); fArea = fPi*fRadius*fRadius; fVolume = fPi*fRadius*fRadius*fRadius*4.0/3.0;
/* [d] : Print Radius, Area and Volume */
printf("圓半徑 = %8.3f \n", fRadius ); printf("圓面積 = %8.3f \n", fArea ); printf("圓體積 = %8.3f \n", fVolume );
return (0);}

程式語言 第三課 part2

/* * =========================================================================== * Compute Area of a Circle : Coefficients are defined in main program. * : Radius and area of circle are printed to screen. * * Copyright (C) 1998 by Mark Austin and David Chancogne. * * This software is provided "as is" without express or implied warranty. * Permission is granted to use this software on any computer system, * and to redistribute it freely, subject to the following restrictions: * * 1. The authors are not responsible for the consequences of use of * this software, even if they arise from defects in the software. * 2. The origin of this software must not be misrepresented, either * by explicit claim or by omission. * 3. Altered versions must be plainly marked as such, and must not * be misrepresented as being the original software. * 4. This notice is to remain intact. * * Written by: Mark Austin January, 1994 * =========================================================================== */
#include /* Standard Input/Output function declarations */#include /* Math functions, such as sqrt(x), and constant M_PI */#include
int main( void ) {float fRadius; /* Radius of circle */float fArea; /* Area of circle */float fPi; /* Variable for "pi" */
/* [a] : Prompt User for "radius of circle" */
printf("============================================\n"); printf("請輸入要計算的圓半徑 (半徑需大於0):"); scanf("%f", &fRadius);
/* [b] : Check that the radius in greater than zero */
if( fRadius <= 0 ) { printf("ERROR >> 圓半徑必需大於0 \n"); exit (1); }
/* [c] : Compute Area of Circle */
fPi = 4.0*atan( 1.0 ); fArea = fPi*fRadius*fRadius;
/* [d] : Print Radius and Area */
printf("圓半徑 = %8.3f \n", fRadius ); printf("圓面積 = %8.3f \n", fArea );
return (0);}

程式語言 第三課 part1

/*
* ===========================================================================
* Compute Area of a Circle : Coefficients are defined in main program.
* : Radius and area of circle are printed to screen.
*
* Copyright (C) 1998 by Mark Austin and David Chancogne.
*
* This software is provided "as is" without express or implied warranty.
* Permission is granted to use this software on any computer system,
* and to redistribute it freely, subject to the following restrictions:
*
* 1. The authors are not responsible for the consequences of use of
* this software, even if they arise from defects in the software.
* 2. The origin of this software must not be misrepresented, either
* by explicit claim or by omission.
* 3. Altered versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
* 4. This notice is to remain intact.
*
* Written by: Mark Austin January, 1994
* ===========================================================================
*/
#include /* Standard Input/Output function declarations */
#include /* Math functions, such as sqrt(x), and constant M_PI */
#include
int main( void ) {
float fRadius; /* Radius of circle */
float fArea; /* Area of circle */
float fPi; /* Variable for "pi" */
/* [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( 1.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);
}

2009年9月22日 星期二

程式語言 debug

#include <>

#define PI 3.1415926;

int main( void )
{
/* [a] : Print pi with default floating point output */

printf("My First Program : PI = %f \n, PI);

==========我是改錯分隔線===========

#include <>

#define PI 3.1415926

int main(void)
{
/* [a] : Print pi with default floating point output */

printf("My First Program : PI = %f \n",PI);
}

程式語言 第二課

#include <>

#define PI 3.1415926

int main(void)
{
printf("Approximate value of PI=%f \n",PI");

return(0);
}

程式語言 第一課

#include <>

main()
{
printf("大家好嗎?\n\n一定很好!\n\n");
}