杂碎

减量

#include

#define MAX1 100

void main()

{

    int count = MAX1 + 1;

    while (--count > 0 ) {

        printf("%d bttes pf spromg water on the wall " "%d botton of spring water !\n ", count,count);

        printf("take one down and pass it around , \n ");

        printf("%d bottles of spring water !\n ", count-1 );


    }

}

杂碎_第1张图片
__



自动类型转换

#include

#define MAX1 100

void main()

{

    char ch ;

    int i ;

    float f1;

    f1 = i = ch ='C';

    printf( "ch = %c , i = %d ,f1 = %2.2f \n",ch ,i ,f1);

    ch +=1;

    i = f1 +2 * ch ;

    f1 =2.0 *ch +1;

    printf( "ch = %c , i = %d ,f1 = %2.2f \n",ch ,i ,f1);

    ch =52222.11;

    printf("NOW ch = %c \n",ch);


}




杂碎_第2张图片


定义带有一个参数的函数

#include

void pound (int n)

{

    while (n -- > 0) {

        printf("#");

    }

   printf("\n");

}

void main()

{

    int times = 5;

    char ch = '!';

    float f = 8.9;

    pound( times);

    pound(ch);

    pound((int)f);

}






杂碎_第3张图片

\


#include

const int S_PER_M = 60;

const int S_PER_H = 3600;

const double M_PER_K = 0.62137;

int main()

{

    double distk , distm;

    double rate ;

    int min , sec ;

    int time ;

    double mtime ;

    int mmin , msec ;

    printf("This program converts your time for a metric race \n");

    printf("to a time for running a mile and to your average\n");

    printf("speed in miles per hour .\n");

    printf("please enter , in kilometers , the distance run .\n");

    scanf("%lf",&distk );

    printf("Next enter the time in minutes and seconds .\n");

    printf("Begin by entering the minutes .\n");

    scanf("%d",&min);

    printf("Now enter the secondes \n");

    scanf("%d",&sec);

    time =S_PER_M * min + sec ;

    distm =M_PER_K * distk ;

    rate = distm  / time *S_PER_H;

    mtime = (double) time / distm;

    mmin = (int ) mtime /distk;

    mmin = (int)mtime % S_PER_M;

    printf("you ran %1.2f km  (%1.2f miles ) in %d min , %d sec .\n",distk ,distm ,min ,sec);

    printf("that pace correponds to runing a mile in %d min",mmin);

    printf("%d sec .\n your average speed was %1.2f mph .\n",msec , rate);





}










杂碎_第4张图片

你可能感兴趣的:(杂碎)