Advertisement
KvArt

Obrtanje niza

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