Commit 645b5af6 authored by Standa Vitek's avatar Standa Vitek
Browse files

tut07

parent 84ef6010
#include <stdio.h>
int main()
{
int a = 10;
char ret1[5];
// ret1 = "ahoj";
char *ret2;
ret2 = "ahoj";
printf("velikost ret1: %lu\n", sizeof(ret1));
printf("velikost ret1: %lu\n", sizeof(ret2));
// adresy
printf("a: %p\n", &a);
printf("ret1: %p\n", ret1);
printf("ret2: %p\n", ret2);
ret2[0] = 'X';
printf("%c %s\n", ret2[0], ret2);
// int milion[1000000];
}
\ No newline at end of file
#include <stdio.h>
int f(int i)
{
return i+10;
}
int main()
{
for (int i = 0; i < 5; i++)
{
printf("i = %i\n", i);
printf("i = %i\n", f(i));
}
return 0;
}
\ No newline at end of file
#include <stdio.h>
/*
a[3][4] ~ vystupuji prvky dataveho typu ()[4]
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
^ adresa pole ^ druhy radek ^ treti radek
*/
void matice_napln (int *x, int w, int h)
{
int a = 0;
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
x[i+j*w] = a++;
}
}
}
void matice_tisk (int *x, int w, int h)
{
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
printf("%3i ", x[i+j*w]);
}
printf("\n");
}
}
void vektor_napln (int *x, int velikost)
{
for (int i = 0; i < velikost; i++)
x[i] = velikost - i;
}
void vektor_tisk (int *x, int velikost)
{
for (int i = 0; i < velikost; i++)
{
printf("%2i ", x[i]);
}
printf("\n");
}
int vektor_soucet (int *a, int *b, int *c, int va, int vb, int vc)
{
if (va != vb || vc != va)
{
return 100;
}
for (int i = 0; i < vc; i++)
{
c[i] = a[i] + b[i];
}
return 0;
}
int main()
{
int w = 10;
int a[w], b[w], c[w];
int x = 5, y = 5;
int m[x*y];
vektor_napln (a, 10);
vektor_napln (b, 10);
vektor_soucet (a, a, c, w, w, w);
vektor_tisk (c, w);
matice_napln (m, x, y);
matice_tisk (m, x, y);
}
\ No newline at end of file
#include <stdio.h>
// void vektor_soucet (int velikost_p, velikost_q, int p[velikost], int q[velikost])
void nacti_matici (int *x, int w, int h)
{
int a = 0;
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
x[i+j*w] = a++;
}
}
}
void tisk_matice (int *x, int w, int h)
{
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
printf("%3i ", x[i+j*w]);
}
printf("\n");
}
}
void nacti_vektor (int *x, int w)
{
for (int i = 0; i < w; i++)
{
x[i] = i;
}
}
void tiskni_vektor(int *x, int w)
{
for (int i = 0; i < w; i++)
{
printf("%i ", x[i]);
}
printf("\n");
}
int vektor_soucet (int *vektor_1, int *vektor_2, int *vysledek, int velikost_1, int velikost_2, int velikost_3)
{
if ((velikost_1 != velikost_2) || (velikost_3 != velikost_1))
{
return 100;
}
for (int i = 0; i < velikost_3; i++)
{
vysledek[i] = vektor_1[i] + vektor_2[i];
}
return 0;
}
int main()
{
int w = 10;
// pole variabilni delky nelze inicizalizovat pri deklaraci
int a[w], b[w], c[w];
int d[25];
nacti_vektor(a, w);
nacti_vektor(b, w);
tiskni_vektor(a, w);
tiskni_vektor(b, w);
vektor_soucet(a, b, c, w, w, w);
tiskni_vektor(c, w);
nacti_matici(d, 5, 5);
tisk_matice (d, 5, 5);
}
\ No newline at end of file
#include <stdio.h>
int main()
{
for (int i = 0; i < 5; i++)
{
printf("i = %i\n", i);
}
return 0;
}
\ No newline at end of file
#include <stdio.h>
int main()
{
int w = 4, h = 4;
int pole[w*h];
/*
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
^ ^ ^
adresa pole druhy radek
*/
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
// prvni radek
pole[i] = i; // ~ matice[i][j] ~ pole[i+j*h]
}
}
}
\ No newline at end of file
#include <stdio.h>
// void vektor_soucet (int velikost_p, velikost_q, int p[velikost], int q[velikost])
void nacti_matici (int *x, int w, int h)
{
int a = 0;
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
x[i+j*w] = a++;
}
}
}
void tisk_matice (int *x, int w, int h)
{
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
printf("%3i ", x[i+j*w]);
}
printf("\n");
}
}
void nacti_vektor (int *x, int w)
{
for (int i = 0; i < w; i++)
{
x[i] = i;
}
}
void tiskni_vektor(int *x, int w)
{
for (int i = 0; i < w; i++)
{
printf("%i ", x[i]);
}
printf("\n");
}
int vektor_soucet (int *vektor_1, int *vektor_2, int *vysledek, int velikost_1, int velikost_2, int velikost_3)
{
if ((velikost_1 != velikost_2) || (velikost_3 != velikost_1))
{
return 100;
}
for (int i = 0; i < velikost_3; i++)
{
vysledek[i] = vektor_1[i] + vektor_2[i];
}
return 0;
}
int main()
{
int w = 10;
// pole variabilni delky nelze inicizalizovat pri deklaraci
int a[w], b[w], c[w];
int d[25];
nacti_vektor(a, w);
nacti_vektor(b, w);
tiskni_vektor(a, w);
tiskni_vektor(b, w);
vektor_soucet(a, b, c, w, w, w);
tiskni_vektor(c, w);
nacti_matici(d, 5, 5);
tisk_matice (d, 5, 5);
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment