购物网站开发将商品导入数据库,深圳建站公司优化,张家界网站建设企业,电子商务网络营销是干嘛的1. 两数之和 给定一个整数数组 nums 和一个整数目标值 target#xff0c;请你在该数组中找出 和为目标值 target 的那 两个 整数#xff0c;并返回它们的数组下标。
你可以假设每种输入只会对应一个答案。但是#xff0c;数组中同一个元素在答案里不能重复出现。
你可以按…1. 两数之和 给定一个整数数组 nums 和一个整数目标值 target请你在该数组中找出 和为目标值 target 的那 两个 整数并返回它们的数组下标。
你可以假设每种输入只会对应一个答案。但是数组中同一个元素在答案里不能重复出现。
你可以按任意顺序返回答案。
示例 1
输入nums [2,7,11,15], target 9
输出[0,1]
解释因为 nums[0] nums[1] 9 返回 [0, 1] 。
#include stdio.h
#include stdlib.h
#include string.hint main(void){int nums[4] {2,7,11,15};int target 9;for(int a0;a4;a){for(int ba1;b4;b){if(nums[a]nums[b]target){printf(%d %d\n,a,b);}}}return 0;
}
安照这种思路引申
数组排序从小到大
#include stdio.h
#include string.hint main(void)
{int w[5]{1,8,20,4,5};for(int a0;a5;a){for(int ba1;b5;b){if(w[b]w[a]){int cw[a];w[a]w[b];w[b]c;}}}for(int a0;a5;a){ printf(%d ;,w[a]); // 1;4;5;8;20}return 0;
}
如果要遍历数组2元素都可以用这种循环方法甚至3个元素多个元素都可以只是多增加循环而已。