Advertisement
candrei98

Untitled

Dec 15th, 2018
104
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. #include <conio.h>
  3. #include <stdlib.h>
  4.  
  5. int* alocare(int dim) {
  6.  
  7.     int *p;
  8.  
  9.     if ((p = (int*)malloc(sizeof(int) * dim)) == NULL) {
  10.         printf("Nu e saptiu suficient");
  11.         exit(0);
  12.     }
  13.  
  14.     return p;
  15. }
  16.  
  17. int main() {
  18.  
  19.     int n, k, *p, dim = 999999, nr = 0;
  20.  
  21.     p = alocare(dim);
  22.  
  23.     int *p_init = p;
  24.  
  25.     printf("Introduceti n= ");
  26.     scanf("%d", &n);
  27.  
  28.     do {
  29.         scanf("%d", p);
  30.         if (*p >= n || *p == 0) {
  31.             break;
  32.         }
  33.         nr++;
  34.         p++;
  35.     } while (*p <= n || *p != 0);
  36.  
  37.     p = p_init;
  38.  
  39.     for (int i = 0; i < nr; i++) {
  40.         printf("%d ", *p);
  41.         p++;
  42.     }
  43.  
  44.  
  45.     _getch();
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement