#include <stdio.h> int main() { int num; scanf("%d",&num); printf("2049%04d\n",num); scanf("%d",&num); printf("2049%04d\n",num); scanf("%d",&num); printf("2049%04d\n",num); return 0; }
控制双精度浮点型位数
#include <stdio.h> int main() { int num; while(1) { scanf("%d",&num); printf("2049%04d\n",num); } return 0; }
#include <stdio.h> int main() { char ans1,ans2; printf("复习了没?(输入y或Y表示复习了,输入n或N表示没复习):"); ans1=getchar(); getchar(); printf("\动手敲代码了没?(输入y或Y表示敲了,输入n或N表示木有敲):"); ans2=getchar(); if ((ans1 == 'y'||ans1 == 'Y')&&(ans2 == 'y'||ans2 == 'Y')) printf("\n罗马不是一天建成的:)\n"); else printf("\n罗马不是一天毁灭的。。。\n"); return 0; }
#include <stdio.h> int main() { char x; x = getchar(); if(x<='9'&&x>='0') printf("%c是数字字符\n",x); else if((x>='a'&&x<='z')||(x>='A'&&x<='Z')) printf("%c是英文字母\n",x); else printf("%c是其他字符\n",x); return 0; }
#include <stdio.h> int main() { int n,a,b,c; float sum; while(scanf("%d%d",&n,&a)!=EOF){ sum = 0; b = 1; c = a; while(b<=n) { sum = sum + (float)b/a; a = a*10 + c; b++; } printf("n = %d,a = %d,sum = %f\n",n,c,sum); } return 0; }
#include <stdio.h> #include <stdlib.h> #include <time.h> const int N = 5; int main() { int x, n; srand(time(0)); for (n = 1;n<=N;n++) { x = rand() % 100; printf("%3d",x); } printf("\n"); return 0; }
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int x, n,i; srand(time(0)); x = rand()%31 +1; printf("猜猜十二月哪一天是你的luck day\n"); printf("开始喽,你有三次机会,猜吧(1`31) : \n"); for (i = 1;i<=3;i++) { scanf ("%d", &n); if (x==n) { printf("猜对了,恭喜\n"); break; } else if (n>x) printf("你猜的日期晚了,luck day还没到呢\n"); else if (n<x) printf("你猜的日期早了,luck day 还没到呢\n"); } if (i==4); printf("次数用完了。偷偷告诉你:十二月,你的luck day 是%d号\n",x); return 0; }
#include <stdio.h> int main() { int a,b; scanf("%d",&a); b=1; while (b<=a) { printf(" o \n"); printf("<H>\n"); printf("| |\n"); printf("\n"); b++; } return 0; }