-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.c
More file actions
40 lines (40 loc) · 895 Bytes
/
Copy pathexample.c
File metadata and controls
40 lines (40 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<stdio.h>
#include<stdlib.h>
void main()
{
int *pt,num,j,i=0,k=0,target,sum[10];
printf("Enter the array size:\n");
scanf("%d",&num);
pt=(int*)(malloc(num*sizeof(int)));
printf("enter the elements of the array:\n");
for(i=0;i<num;i++)
{
scanf("%d",&pt[i]);
}
printf("Enter traget number:\n");
scanf("%d",&target);
/*for(i=0;i<num;i++)
{
if((pt[i]+pt[i+1])==target)
{
printf("[%d, %d]",i,i+1);//this is not a generalized case.(logic 1)
}
}*/
for(i=0;i<num;i++)
{
j=i+1;
while(j<num)
{
if(pt[j]==target-pt[i])
{
sum[0]=i;
sum[1]=j;
}
j++;
}
}
printf("[%d, %d]",sum[0],sum[1]);
free(pt);
system("pause");
//return 0;
}