-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patharray replace
More file actions
65 lines (48 loc) · 1.17 KB
/
array replace
File metadata and controls
65 lines (48 loc) · 1.17 KB
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
62
63
64
65
replace the particular key element in a array
#include<stdio.h>
int main(){
int n,i,e=0,o=0;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
int key,rep;
scanf("%d%d",&key,&rep);
for(i=0;i<n;i++)
{
if(a[i]==key)
a[i]=rep;
}
for(i=0;i<n;i++)
printf("%d ",a[i]);
}
--------------------------------------------------------------------------------------------------------------------------------
replace the particular index element
#include<stdio.h>
int main(){
int n,i,e=0,o=0;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
int key,rep;
scanf("%d%d",&key,&rep);
a[key]=rep;
for(i=0;i<n;i++)
printf("%d ",a[i]);
}
--------------------------------------------------------------------------------------------------------------------------------
replace the particular pos element
#include<stdio.h>
int main(){
int n,i,e=0,o=0;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
int key,rep;
scanf("%d%d",&key,&rep);
a[key-1]=rep;
for(i=0;i<n;i++)
printf("%d ",a[i]);
}