-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.cpp
More file actions
61 lines (59 loc) · 834 Bytes
/
array.cpp
File metadata and controls
61 lines (59 loc) · 834 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<stdio.h>
#include<stdlib.h>
int common(int *a,int *b,int *c,int na,int nb)
{
int i,j,k=0;
for(i=0;i<na;i++)
{
for(j=0;j<nb;j++)
{
if(a[i]==b[j])
c[k++]=a[i];
}
}
return k;
}
int main()
{
int a[100],b[100],c[100],i,na=0,nb=0,k,u,l,m,n,h,t;
printf("enter lower and upper limits:");
scanf("%d%d",&l,&u);
if(l<1 || u>99999)
{
printf("invalid input");
exit(1);
}
printf("enter the value of m:");
scanf("%d",&m);
n=1;
while(1)
{
h=n*(2*n-1);
if(h>=l && h<u)
{
a[na++]=h;
n++;
}
else if(h>u)
break;
else
n++;
}
n=1;
while(1)
{
t=n*(n+1)/2;
if(t>u)
break;
if(t>=l)
b[nb++]=t;
n++;
}
k=common(a,b,c,na,nb);
printf("\n");
m-=1;
if(m>=0 && m<k)
printf("the required output is %d ",c[m]);
else
printf("No number present in this index");
}