Sunteți pe pagina 1din 11

# 1)

#include <stdio.h>
#include <stdlib.h>

int main()
{
int niz[5] = {5, 4, 3, 2, 1};

## for (int i = 0; i < sizeof(niz)/4; i++) {

printf("%d", niz[i]);

## for (int j = sizeof(niz)/4 - 1; j > i; j--) {

printf("%d", niz[j]);
}
}
}

2)

#include <stdio.h>
#include <stdlib.h>

int main()
{
int niz[10] = {1, 2, 3, 4, 5, 6, 7};
int matrica[2][5] = {1, 2, 3, 4, 5, 6, 7};
printf("%d", sizeof(niz));
printf("%c", '1' - (sizeof(niz) == sizeof(matrica)));
for(int i=0; i<1; i++) {
printf("%d", sizeof(matrica[i]));
for (int j=0; j<2; j++) {
printf("%c", matrica[i][j] + 'B' - 6 + sizeof(matrica[i][j]));
}
}
}
3)

#include <stdio.h>
#include <stdlib.h>

int main()
{
int niz1[4][3] = {1, 2, 3, 5, 7, 9, 0, -2, 6, 3};
int niz2[12] = {1, 6, -9, 6, 0, 1, -4, 5, 5, 5, 1, 2};
int niz3[4][3] = {1, -5, 3, 5, 6, -2, 6, 0, 3};
int niz4[5][4] = {{1, 2, 3}, {-4, 3, 2}, {2, 3, 4}, {1, 2, 5}};

## for (int i = 0; i < sizeof(niz1[3])/4; i++) {

for (int j = 0; j < sizeof(niz3[3])/4; j++) {
printf("%d", niz1[i][j] + niz2[i*j] + niz3[i][j] + niz4[i][1+j]);
}
}
}
4)

#include <stdio.h>
#include <stdlib.h>

int main()
{
int m[4+1][2] = {{0,0}, {1,0}, {1,1}, {0,2}};
int d[4+1];
int gd=0;
int gg=0;
for (int i = 0; i < 4; i++) {
int d1 = m[i+1][0] - m[i][0];
int d2 = m[i+1][1] - m[i][1];

## int v = d[i] = d1*d1 + d2*d2;

int l=0,r=0;
for (int i = 0; i < v; i++) {
if (v == i*i) {
v=0;l=r=i;
gd+=i;
gg+=i;
} else if (v == (i+1)*(i+1)) {
v=0;l=r=i+1;
gd+=i+1;
gg+=i+1;
} else if ((i+1)*(i+1) > v && (i*i < v)) {
v=0;l=i;r=i+1;
gd+=i;
gg+=i+1;
}
}

printf("(%d,%d)", l,r);
}
printf("=>(%d,%d)",gd,gg);
}
5)
#include <stdio.h>
#include <stdlib.h>

int main()
{
int hp[20][20][20][20] = {};
int ax = 2;
int ay = 3;
int az = 5;
int aw = 7;
int s = 0;
int c = 0;
int gx = 1;
int gy = 1;
int gz = 1;
int gw = 0;

## for (int x = -gx; x <= gx; x++)

for (int y = -gy; y <= gy; y++)
for (int z = -gz; z <= gz; z++)
for (int w = -gw; w <= gw; w++)
{
s++;
int d = hp[x+gx][y+gy][z+gz][w+gw] = (ax*x + ay*y+ az*z + aw*w);
if (d==0) {
c++;
printf("(%d,%d,%d,%d)", x,y,z,w);
}
}

printf(",s:%d,c:%d", s, c);
}
6)
#include <stdio.h>
#include <stdlib.h>

struct c {
int re;
int im;
};

int main()
{
struct c m1[3][3] = {{{1,0}, {0,0}, {0,0}}, {{0,0}, {-1,0}, {0,0}}, {{ 0,0}, {0,0}, {2,0}}};
struct c m2[3][3] = {{{2,5}, {5,1}, {3,0}}, {{8,0}, { 1,5}, {3,4}}, {{-4,0}, {7,1}, {0,0}}};
struct c m3[3][3] = {};
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
struct c l = m1[i][k];
struct c r = m2[k][j];
struct c p = {(l.re * r.re - l.im * r.im), (l.re*r.im + l.im *r.re)};
m3[i][j].re = m3[i][j].re + p.re;
m3[i][j].im = m3[i][j].im + p.im;
}
}
}
int r=3;
int k=3;
struct c m[r*k];
struct c s = {0,0};;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
struct c p = {m3[j][i].re + m3[i][j].re, m3[j][i].im + m3[i][j].im};
m[i*r+j]=p;
s.re += m[i*r+j].re;
s.im += m[i*r+j].im;
}
}
printf("(%d,%d)", s.re,s.im);

## for (int i = 0; i < r*k; i++) {

for (int j = 0; j < r*k; j++) {
if (m[i].re*m[i].re + m[i].im*m[i].im < m[j].re*m[j].re+m[j].im+m[j].im) {
int t1 = m[i].re;
int t2 = m[i].im;
struct c p = {t1, t2};
m[i] = m[j];
m[j] = p;
}
}
}

## printf("%d%d%d", m[r*k-1].im, m[r*k-2].im, m[r*k-3].im);

}
7)

#include <stdio.h>
#include <stdlib.h>

int main()
{
int n = 64, c=0;
int niz[n], niz2[n];
niz[0] = 9;
int pow = 5, base = 2;
int m = 1;
for (int i = 0; i < pow; i++, m=m*base);
for (int i = 1; i < n; i++)
niz[i] = ((niz[i-1]*3)%m);
for (int i=0; i<n; i++) {
if (niz[i] < m) {
int p = 1;
for (int j = 0; j < c; j++) {
if (niz2[j] == niz[i])
p = 0;
}
if (p==1)
niz2[c++] = niz[i];
}
}
for (int i = 0; i<c;i++)
for (int j=0; j<c; j++)
if (niz2[i]>niz2[j]) {
int t=niz2[i];
niz2[i]=niz2[j];
niz2[j]=t;
}

## for (int i=0; i<c; i++)

printf("%d", niz2[i]);
}
8)

#include <stdio.h>
#include <stdlib.h>

int main()
{
int n = 4;
int niz[16][10] = {0, 4, 5, 1,
0, 4, 5, 1,
0, 4, 5, 1,
0, 4, 5, 1};
for (int i = n - 1; i > 0; i--) {
for (int j = i; j < n; j++) {
if (printf("%d", niz[i][j]) != 0 ?
niz[i][j] : printf("%d", niz[10][j]));
}
}
return 0;
}
9)

#include <stdio.h>
#include <stdlib.h>

int main()
{
int i,j, niz[] = { 2, -4, 99,
7, -8, 101,
-56, 3, -7};
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++) {
if (niz[i,j] > 0)
{
int t = niz[i*3+j];
niz[j*3+i] = niz[i*3+j];
niz[i*3+j] = t;
printf("%d", t > niz[i,j,(i,j)>0]);
}
else if (niz[i,j] < 0)
{
int t = niz[j*3+i];
niz[i*3+j] = niz[j*3+i];
niz[j*3+i] = t;
printf("%d", t < niz[i,j,(j,i)<0]);
}
else
printf("%d", niz[i,j,i,j==0]);
}
}
10)

#include <stdio.h>
#include <stdlib.h>

int main()
{
int a = 4;
int b = a;
int n = a*b + 4 + 2*a + 2*b;
int m[n];

m[i] = 0;

## for (int i = 1; i < 2+a-1; i++)

{
for (int j = 1; j-1< b; j++) {
int a1 = (j%2?1:-1);
int a2 = m[i*(b+2) + j - 1];
m[i*(b+2) + j] = m[(i-1)*(b+2) + j] + a1 + a2;
}
}

## for (int i=1;i<a+1;i++)

{
if ((i%2)) printf("%d", m[i*(2+b) + i]);
if (!(i%2)) printf("%d", m[i*(2+b) + (a+2)-i-1]);
}
}
Rješenja

1) 512344123312211

2) 40020AB

3) 5171421-210-79

4) (1,1)(1,1)(1,2)(2,2)=>(5,6)

5) (-1,-1,1,0)(0,0,0,0)(1,1,-1,0),s:27,c:3

6) (8,-2)-2-210

7) 2725191711931

8) 000104

9) 001101110

10) 1374

## Meniu subsol

### Obține aplicațiile noastre gratuite

Drepturi de autor © 2022 Scribd Inc.
Drepturi de autor © 2022 Scribd Inc.

## Meniu subsol

### Obține aplicațiile noastre gratuite

Drepturi de autor © 2022 Scribd Inc.
Drepturi de autor © 2022 Scribd Inc.