2019年5月8日

C:数组的要点和技巧

摘要: 技巧: 1.数组的初始化 两种方法 (1) for (i = 0; i < 10; i++) { cout[i] = 0; } (2) cout[ ] = {0} 2.对于零散的数组中值的赋值 cout[ ] = {[1] =2, 4,[5]=6 } 输出为 0 2 4 0 0 6 3.search 阅读全文

posted @ 2019-05-08 19:05 zhaoy_shine 阅读(145) 评论(0) 推荐(0) 编辑

C:折半查找法(二分法)

摘要: 主要用于已经做了排序的数字,时间复杂度:log2n 直接贴代码 #include <stdio.h>#include <stdlib.h>int search(int search_num, int a[], int right){ int left = 0; int ret = -1; int m 阅读全文

posted @ 2019-05-08 17:38 zhaoy_shine 阅读(265) 评论(0) 推荐(0) 编辑

2019年5月7日

C:输入数字计数(数组方法)

摘要: 两类题型 1.例如 1 2 3 2 1 -1 然后计数 #include <stdio.h>#include <stdlib.h>int main(){ //解决计数问题,当输入-1的时候代表停止输入 /* 思路 通过数组cout[]作为计数器,每次键入的值如果为0-9,则该cout[i]++ co 阅读全文

posted @ 2019-05-07 21:13 zhaoy_shine 阅读(1238) 评论(0) 推荐(0) 编辑

2019年5月6日

C:得到指定位数的随机值

摘要: 如何得到指定位置的随机值? #include<time.h> srand(time(0)); int a = rand(); 如果希望得到百位的随机值,则a%100,十位则a%10 阅读全文

posted @ 2019-05-06 15:58 zhaoy_shine 阅读(105) 评论(0) 推荐(0) 编辑

C:如何根据输入的值来确定是否停止继续输入

摘要: 求平均值中,最后键入-1表示结束输入,如何通过循环来完成? #include <stdio.h>#include <stdlib.h>int main(){ int number; int sum = 0; int count = 0; scanf("%d",&number); while(numb 阅读全文

posted @ 2019-05-06 15:52 zhaoy_shine 阅读(260) 评论(0) 推荐(0) 编辑

C:如何分解整数(从末位往前取以及从首位往后取)

摘要: 主要都是通过整除与取余来处理 1.从末位往前取 #include<stdio.h>int main(){ int num; int num_1,num_2,num_3; scanf("%d",&num); num_1 = (num/1) % 10; num_2 = (num/10) % 10; nu 阅读全文

posted @ 2019-05-06 14:09 zhaoy_shine 阅读(555) 评论(0) 推荐(0) 编辑

导航