Advertisement
KvArt

Brisanje odredjene vrednosti iz niza

Aug 14th, 2022
739
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. #define N 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=0;
  11.             printf("Unesite duzinu niza n: "); scanf("%d",&n);
  12.             if (n<=0 || n>N) break;
  13.             printf("Unesite elemente niza: "); int a[N];
  14.             for(i=0;i<n; scanf("%d",&a[i++]));
  15.             printf("Unesite vrednost koju zelite da obrisete iz niza: "); int b; scanf("%d", &b);
  16.             for(i=0; i<n; i++) if (a[i] != b) a[j++] =a[i];
  17.             n=j;
  18.             printf("Niz nakon obrade izgleda ovako: "); for(i=0; i<n; printf("%d ",a[i++]));
  19.             printf("\n\n");
  20.         }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement