#include <stdio.h> int main(void) { char beep=7; printf("%c",beep); printf("startled by the sudden sound,sally shouted,\n"); printf("\"by the ggreat pumpkin,wahat was that!\""); }
%d int %ld long int %c char %f float %u unsigned %hd short %lf double %x 以16进制输出int or long int or short int %o 八进制输出 %s 字符串
#include <stdio.h> int main(void) { float a=64.25; printf("enter a floating-point value:64.25\n"); printf("exponential notation: %e\n",a); printf("fixed-point notation:%f\n",a); return 0; }
#include <stdio.h> int main(void) { float a; printf("enter a floating-point value:"); scanf("%f",&a); printf("exponential notation: %e\n",a); printf("fixed-point notation:%f\n",a); return 0; }
#include <stdio.h> #define ADJUST 7.31 int main() { const double SCALE=0.333; //const 常量 double shoe,foot; printf("Shoe size (men's) foot length\n"); shoe=3.0; while (shoe<18.5) //while循环开始 { /*块开始*/ foot=SCALE*shoe+ADJUST; printf("%10.lf %15.2f inches\n",shoe,foot); shoe=shoe+1.0; } //块结束 printf("if the shoe fits,wear it.\n"); return 0; }
#include <stdio.h> #define ADJUST 7.31 int main() { int a=0; int b; while (a<10) { a=a+1; b=a*a; printf("%4d %6d\n",a,b); } return 0; }
#include <stdio.h> #define SQUARES 10 int main() { const double CROP=2E16; double current,total; int count=1; printf("square grains total "); printf(" fraction of \n"); printf(" added grains "); printf(" world total\n"); total=current=1.0; printf("%4d %13d %12.2e %12.2e\n",count,current,total,total/CROP); while (count<SQUARES) { count=count+1; current=2.0*current; total=total+current; printf("%4d %13.2e %12.2e %12.2e\n",count,current,total,total/CROP); } printf("That's all.\n"); getchar(); return 0; }
#include <stdio.h> #define sec_min 60 int main() { int min,sec,left; printf("convert second to minute and second\n"); printf("please input the seconds:\n"); scanf("%d",&sec); while (sec>0) { min=sec/sec_min; left=sec%sec_min; printf("%d seconds is %d minutes and %d seconds\n",sec,min,left); printf("please input another seconds:\n"); scanf("%d",&sec); } printf("Done!\n"); return 0; }