//打印一个字符小人 #include<stdio.h> int main() { printf(" o \t o\n"); printf("<H> \t <H>\n"); printf("I I \t I I\n"); }
#include<stdio.h> int main() { printf(" o\n"); printf("<H> \n"); printf("I I \n"); printf(" o\n"); printf("<H> \n"); printf("I I \n"); }
/*用c语言实现的一个简单算数运算程序*/ #include<stdio.h> int main() { int x,y; int r1,r2,r3,r4; x = 1; y = 2; r1 = x + y; r2 = x - y; r3 = x * y; r4 = x / y; printf("r1 = %d \n",r1); printf("r2 = %d \n",r2); printf("r3 = %d \n",r3); printf("r4 = %d \n",r4); return 0; }
/*用c语言实现的一个简单算数运算程序*/ #include<stdio.h> int main() { float x,y; float r1,r2,r3,r4; x = 1; y = 2; r1 = x + y; r2 = x - y; r3 = x * y; r4 = x / y; printf("r1 = %f \n",r1); printf("r2 = %f \n",r2); printf("r3 = %f \n",r3); printf("r4 = %f \n",r4); return 0; }
原因:int 为整型数据 ,float 为浮点数据,float能把小数点后六位显示出来,所以第二次r4=0.500000.而第一次只能显示0
#include<stdio.h> int main() { int n, r1, r2, r3, r4; n = 100; r1 = n*(n+1)/2; r2 = (n+1)*n/2; r3 = n/2*(n+1); r4 = (n+1)/2*n; printf("n = %d \n",n); printf("r1 = %d \n",r1); printf("r2 = %d \n",r2); printf("r3 = %d \n",r3); printf("r4 = %d \n",r4); return 0; }
#include<stdio.h> int main() { int n, r1, r2, r3, r4; n = 101; r1 = n*(n+1)/2; r2 = (n+1)*n/2; r3 = n/2*(n+1); r4 = (n+1)/2*n; printf("n = %d \n",n); printf("r1 = %d \n",r1); printf("r2 = %d \n",r2); printf("r3 = %d \n",r3); printf("r4 = %d \n",r4); return 0; }
line7~10对应数学表达式是1到n的累加
当n=偶数时,r4先计算(n+1)再/2 此时(n+1)为奇数 除以2有小数 因为数据为整型 小数部分舍掉出现偏出
当n=奇数时,r3先计算(n+1)再计算n/2 此时n/2有小数 因为数据为整型 小数部分舍掉出现偏出
#include<stdio.h> int main() { double x,y; char c1,c2,c3; int a1,a2,a3; scanf("%d%d%d ",&a1,&a2,&a3); printf("%d,%d,%d\n",a1,a2,a3); scanf("%c %c %c ",&c1,&c2,&c3); printf("%c,%c,%c\n",c1,c2,c3); scanf("%lf %lf",&x,&y); printf("%lf,%lf\n",x,y); return 0; }
#include<stdio.h> int main() { int a1, a2; char c1, c2; scanf("%d %c %d %c",&a1,&c1,&a2,&c2); printf("a1 = %d,a2 = %d\n",a1,a2); printf("c1 = %c,c2 = %c\n",c1,c2); return 0; }
#include<stdio.h> int main() { int answer; char words[5000]; printf("网课学习让一些人欢喜一些人忧\n"); printf("1.作为一个宅,社恐,觉得这样很好,有网络,自主学习,很ok\n"); printf("2.不喜,不喜,很不喜,眼睛快瞎了,脑壳有点卡。。。。\n"); printf("3.中间派,不知道,说不清。\n"); printf("4.其他。。。\n"); printf("你的选择:"); scanf("%d",&answer); if(answer == 4){ printf("请补充:\n"); getchar(); gets(words); } printf("\n"); printf("当遇到问题时,你会选择:\n"); printf("1.遇到问题,就解决问题,不懂的,搜索式学习,逐个放逐\n"); printf("2.遇到问题,不高兴,然后。就没有了。。\n"); printf("3.其他...\n"); printf("你的选择:"); scanf("%d",&answer); if(answer==1) printf(":)\n"); else if(answer==2) printf("这样不能解决问题啊。。我们选择1好不好:\n"); else if(answer==3) printf("你的想法\n"); getchar(); gets(words); }
include<stdio.h> int main() { int answer,answer2; char words[5000]; printf("\n"); printf("当你在路上时,你会选择:\n"); printf("1.带上耳机哼歌~~~\n"); printf("2.小碎步回家 想着打派派\n"); printf("3.其他...\n"); printf("你的选择:"); scanf("%d",&answer); if(answer==1){ printf("咚咚咚 有人突然靠近\n"); getchar(); gets(words); printf("ohh~太好听了8!你唱歌真的好好听啊,简直就是天籁。我们以后一起唱好不好,一起做学园偶像\n"); printf("你的回答是:\n"); printf("1.你好 谢谢 小笼包 再见 Σ(っ °Д °;)っ\n") ; printf("2.好呀好呀 我最喜欢当school爱抖露了 在舞台上kirakira\n"); scanf("%d",&answer2); } if(answer2==1) printf("你还是没能逃过命运的安排 三个月后你组建了学院偶像Stella!成为了当红idol\n"); else if(answer2==2) printf("你被带到一个不知名的偶像事务所,转生成为了虚拟vtuber 收获了很多粉丝\n"); else if(answer==2) printf("这样不能解决问题啊。。我们选择1好不好:\n"); else if(answer==3) printf("你的想法\n"); getchar(); gets(words); return 0; }
------------恢复内容结束------------