Advertisement
KvArt

Invertovanje dinamickog niza

Aug 19th, 2022
673
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define N 100
  4.  
  5. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  6.  
  7. void main()
  8. {
  9.     while(1)
  10.         {
  11.             int b;
  12.             int *p, *q;
  13.            
  14.             printf("Unesite duzinu niza n: "); int n; scanf("%d",&n);
  15.             if (n<=0 || n>N) break;
  16.            
  17.             printf("Unesite elemente niza: "); int a[N];
  18.             for(p=a;p<a+n;scanf("%d", p++));
  19.            
  20.             for(p=a, q=a+n-1; p<q; p++,q--)
  21.             {
  22.                 b=*p; *p=*q; *q=b;
  23.             }
  24.            
  25.             printf("\n\nRezultujuci niz izgleda ovako:  "); for(p=a;p<a+n;printf(" %d",*p++));
  26.             printf("\n\n");
  27.         }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement