EmbLogic's Blog

a prog. to insert some more elements in an array…

1 #include<stdio.h>
2 void main()
3 {
4                 int i,j,n,n1,n2;
5
6
7         printf(“\n\nenter the number of values u will enter : “);
8
9 scanf(“%d”,&n1);
10
11                int a[n1];
12
13         printf(“\nnow enter values of elements : \n”);
14
15
16                         for(i=0;i<n1;i++)
17                         {
18                                 scanf(“%d”,&a[i]);
19                         }
20
21         printf(“\nnow enter the number of value u want to insert in an array :”);
22
23 scanf(“%d”,&n2);
24
25                 int b[n2];
26
27
28         printf(“\nnow enter the elements u want to insert in an array : \n”);
29
30
31                         for(i=0;i<n2;i++)
32                         {
33                                 scanf(“%d”,&b[i]);
34                         }
35
36
37
38                         n=n1+n2;
39
40                           int c[n];
41
42
43                                 for(i=0;i<n1;i++)
44                                 {
45                                         c[i]=a[i];
46                                 }
47
48
49
50
51
52                                                 for(j=n-1;j>1;j–)
53                                                 {
54                                                         c[j]=c[j-n2];
55
56                                                 }
57
58
59
60         for(i=0;i<n2;i++)
61         {
62                 c[i]=b[i];
63         }
64
65                                 printf(“\nnow the array is : \n”);
66
67
68                 for(i=0;i<n;i++)
69                 {
70                         printf(“%d\n”,c[i]);
71                 }
72
73
74 }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>