Friday, 20 March 2015

Initialize and Edit index value of 1D array.



 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
#include<stdio.h>
int main()
{
 int A[10];
 int i,n,l;
 printf("How many elements you want? : ");
 scanf("%d",&n);
 printf("Enter initial values: ");
  for(int i=0;i<n;i++)
  {
   scanf("%d",&A[i]);
  }

 printf("your array is: \n");
  for(int i=0;i<n;i++)
  {
   printf("%d ",A[i]);
  }
 printf("\n");
 printf("which position element you want to re add: \n");
 scanf("%d",&l);
  for(int j=n;j>=l-1;j--)
  {
   A[j+1]=A[j];
   if(j==l-1)
   {
    scanf("%d",&A[j]);
   }
  }
  for(int i=0;i<n+1;i++)
  {
   printf("%d ",A[i]);
  }
 printf("\n");
return 0;
}

0 comments:

Post a Comment

 

Subscribe to our Newsletter

Contact our Support

Through the contact form

Our Team Memebers