时间总是记忆最大的毒药,今天要是不是同学提起,我已全然忘记我竟然学过C语言。
如果上天能给我一次机会我愿意再看一遍书,然而,太难!
例题1猜数游戏:知识点:随机数、输入、输出、while、if、头文件、基本运算法则
#include<stdio.h> #include<stdlib.h> #include<time.h> void main() { int computer_number,user_number,count=3; srand(time(NULL)); computer_number = rand()%100+1;//??? while(count--) // 3-- 2-- 1-- 0-- // count -1 {printf("please input your guess number:"); scanf("%d",&user_number); if(user_number<computer_number) printf("your guessed too small please again input:"); else if(user_number>computer_number) printf("your guessed too big please again input:"); else {printf("you are a genius\n"); break; } } if(count==-1) {printf("I am so sorry\n"); printf("computer_number is %d",computer_number); } }
例题2找到10个人中最有钱的大佬:知识点:数组、循环、选择、求最大值、顺序比较、下标记录,数组输入
#include<stdio.h> void main() { int a[10],i,max,index; for(i=0;i<=9;i++) {printf("input how much of the NO.%d \n",i+1); scanf("%d",&a[i]); } max=a[0]; for(i=0;i<=9;i++) {if(max<=a[i]) {max = a[i]; index = i; } } printf("NO.%d has %d yuan become DaLao",index+1,max); }
例题3简单函数题目:知识点:函数参数、函数定义、函数声明、函数形参、函数实参、局部全局变量、生命周期
#include<stdio.h> int fun(int a,int b,int c) {int i,sum=0; for(i=a;i<=b;i++) if(i%c==0) sum+=i; return sum; } void main() {int a,b,c,sum; scanf("%d,%d,%d",&a,&b,&c); sum=fun(a,b,c);//求a到b中的c的倍数和 printf("sum is %d",sum); }