Advertisement
fellpz

Ponteiros @aplicações

Oct 19th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. void main(void){
  2.     float v[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0};
  3.     int i;
  4.     float *p;
  5.         for(i=0; i<9; i++)
  6.             printf ("%.1f | ", v[i]);
  7.             printf("\n");
  8.         for(i=0; i<9; i++)
  9.             printf("%.1f | ", *(v+i));
  10.             printf("\n");
  11.         for(i=0; p=v; i<9; i++, p++)
  12.             printf("%.1f | ", *p);
  13.             printf("\n");
  14.  
  15. system("pause");
  16. }
  17.  
  18. /**********************************************************************************************************/
  19.  
  20. #define LIN 3
  21. #define COL 4
  22.  
  23. void main(void){
  24.     int *matriz;
  25.     int i, j;
  26.  
  27.     matriz = malloc(LIN*COL*sizeof(int));
  28.     if(!matriz){
  29.         printf("Nao consegui alocar a memoria suficiente.\n");
  30.     exit(1);
  31.     }
  32.         for(i=0; i<LIN; i++){
  33.             for(j=0; j<COL; j++){
  34.                 printf("Elemento %d %d = ", i,j);
  35.             scanf("%d", matriz+(i*COL+j));
  36.         }
  37.             }
  38.  
  39. system("pause");
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement