fork download
  1. #include <stdio.h>
  2. int array[100], position, c, n, value;
  3.  
  4. printf("Enter number of elements in array\n");
  5. scanf("%d", &n);
  6.  
  7. printf("Enter %d elements\n", n);
  8.  
  9. for (c = 0; c < n; c++)
  10. scanf("%d", &array[c]);
  11.  
  12.  
  13. printf("Enter the location where you wish to insert an element\n");
  14. scanf("%d", &position);
  15.  
  16. printf("Enter the value to insert\n");
  17. scanf("%d", &value);
  18.  
  19. for (c = n - 1; c >= position - 1; c--)
  20. array[c+1] = array[c];
  21.  
  22.  
  23. array[position-1] = value;
  24.  
  25. printf("Resultant array is\n");
  26.  
  27. for (c = 0; c <= n; c++)
  28. printf("%d\n", array[c]);
  29.  
  30. return 0;
  31.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:4:12: error: expected declaration specifiers or ‘...’ before string constant
     printf("Enter number of elements in array\n");
            ^
prog.c:5:11: error: expected declaration specifiers or ‘...’ before string constant
     scanf("%d", &n);
           ^
prog.c:5:17: error: expected declaration specifiers or ‘...’ before ‘&’ token
     scanf("%d", &n);
                 ^
prog.c:7:12: error: expected declaration specifiers or ‘...’ before string constant
     printf("Enter %d elements\n", n);
            ^
prog.c:7:35: error: expected declaration specifiers or ‘...’ before ‘n’
     printf("Enter %d elements\n", n);
                                   ^
prog.c:9:5: error: expected identifier or ‘(’ before ‘for’
     for (c = 0; c < n; c++)    
     ^
prog.c:9:19: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
     for (c = 0; c < n; c++)    
                   ^
prog.c:9:25: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘++’ token
     for (c = 0; c < n; c++)    
                         ^
prog.c:13:12: error: expected declaration specifiers or ‘...’ before string constant
     printf("Enter the location where you wish to insert an element\n");
            ^
prog.c:14:11: error: expected declaration specifiers or ‘...’ before string constant
     scanf("%d", &position);
           ^
prog.c:14:17: error: expected declaration specifiers or ‘...’ before ‘&’ token
     scanf("%d", &position);
                 ^
prog.c:16:12: error: expected declaration specifiers or ‘...’ before string constant
     printf("Enter the value to insert\n");
            ^
prog.c:17:11: error: expected declaration specifiers or ‘...’ before string constant
     scanf("%d", &value);
           ^
prog.c:17:17: error: expected declaration specifiers or ‘...’ before ‘&’ token
     scanf("%d", &value);
                 ^
prog.c:19:5: error: expected identifier or ‘(’ before ‘for’
     for (c = n - 1; c >= position - 1; c--)    
     ^
prog.c:19:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘>=’ token
     for (c = n - 1; c >= position - 1; c--)    
                       ^
prog.c:19:41: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘--’ token
     for (c = n - 1; c >= position - 1; c--)    
                                         ^
prog.c:23:5: warning: data definition has no type or storage class [enabled by default]
     array[position-1] = value;
     ^
prog.c:23:5: warning: type defaults to ‘int’ in declaration of ‘array’ [-Wimplicit-int]
prog.c:23:5: error: variably modified ‘array’ at file scope
prog.c:23:5: error: conflicting types for ‘array’
prog.c:2:5: note: previous declaration of ‘array’ was here
 int array[100], position, c, n, value;
     ^
prog.c:23:5: error: invalid initializer
     array[position-1] = value;
     ^
prog.c:25:12: error: expected declaration specifiers or ‘...’ before string constant
     printf("Resultant array is\n");
            ^
prog.c:27:5: error: expected identifier or ‘(’ before ‘for’
     for (c = 0; c <= n; c++)    
     ^
prog.c:27:19: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<=’ token
     for (c = 0; c <= n; c++)    
                   ^
prog.c:27:26: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘++’ token
     for (c = 0; c <= n; c++)    
                          ^
prog.c:30:5: error: expected identifier or ‘(’ before ‘return’
     return 0;
     ^
stdout
Standard output is empty