热门

最新

红包

立Flag

投票

同城

我的

发布
m0_53303019
布灵布灵大可爱
5 年前
truem0_53303019

求数组内两个数和等于数组内某一个数,输出两个数的下标
#include<stdio.h>
int main()
{
int target,i,j,n;
int nums[20];
printf("Enter the number of the nums:\n");
scanf("%d",&n);

printf("Enter the nums:\n");
for(i=0;i<n;i++)
scanf("%d",&nums[i]);
printf("Enter the target:\n");
scanf("%d",&target);

for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(nums[i]+nums[j]==target) printf("%d %d",i,j);
return 0;
}

CSDN App 扫码分享
分享
评论
1
打赏
  • 复制链接
  • 举报
下一条:
【CFD之道】2017年原创文章汇总
立即登录