5. Покажчики і функції

void main()

{    int **ptr;

  int k,n,i,j;

  printf("\ninput row  ");

  scanf("%d",&k);

  printf("\ninput column  ");

  scanf("%d",&n);

  ptr=(int**) malloc (k*sizeof(int*));

  for(i=0;i<k;i++) ptr[i]=(int*) malloc (n*sizeof(int));

  input(k,n,ptr);

  output(k,n,ptr);

 printf("\nRezult:\n");

work(k,n,ptr);

 free(ptr);

  getch();

}

Приклад. Зчитати елементи одновимірного масиву з клавіатури, вивести на екран,

вивести елементи на непарних місцях

 #include <stdio.h>

 #include <stdlib.h>

 input(int si,float *A)

 {int ix;

    for (ix = 0; ix < si; ix++)

  {  printf ("\nInput element: ");

   scanf("%f",A+ix);

  }

 }

  output(int si,float *A)

 {int ix;

    for (ix = 0; ix < si; ix++)

  {  printf ("%.2f  ",*(A+ix));

  }

 }



int main()

{

  int size, ix;

  float *arrayPtr;

 printf("\n Input number of elements: ");

  scanf("%d",&size);

  arrayPtr=(float*)calloc(size,sizeof(float));

   if (arrayPtr == NULL) return 1;

  input(size,arrayPtr);

  output(size,arrayPtr);

  printf("\n");

  for (ix = 0; ix < size; ix++)

  {  if(ix%2!=0)

   printf("%.2f       ",*(arrayPtr+ix));

  } free(arrayPtr);

  return 0;}





Приклад 2. 

Зчитати елементи двовимірного масиву з клавіатури, вивести на екран,

Вивести парні елементи  в кожному рядку на екран



#include <stdio.h>

#include <conio.h>

void work(int k,int n,int **ptr);

void input(int r,int t,int **pp)

{

  int i,j;

for(i=0;i<r;i++)

  for(j=0;j<t;j++)

   scanf("%d",&pp[i][j]);

}



void output(int r,int t,int **pp)

{

  int i,j;

for(i=0;i<r;i++){

  for(j=0;j<t;j++)

   printf("%3d",pp[i][j]);

   printf("\n");

}

}


void work(int k,int n,int **ptr)

{

    int i,j;

    for (i=0;i<k;i++){

        for(j=0;j<n;j++)

    {

        if(ptr[i][j]%2==0) printf("%4d",ptr[i][j]);

    }

    printf("\n");

}

}






Доступність

Шрифти Шрифти

Розмір шрифта Розмір шрифта

1

Колір тексту Колір тексту

Колір тла Колір тла

Кернінг шрифтів Кернінг шрифтів

Видимість картинок Видимість картинок

Інтервал між літерами Інтервал між літерами

0

Висота рядка Висота рядка

1.2

Виділити посилання Виділити посилання

Вирівнювання тексту Вирівнювання тексту

Ширина абзацу Ширина абзацу

0