0% found this document useful (0 votes)
312 views

Lucrare de Laborator NR 4 Tema:Prelucrarea Masivelor Bidimensionale

This document is a lab report submitted by a student, Corneliu Corman, for a programming course at the Moldova Technical University. It details 4 exercises working with 2D arrays in C++. The first exercise calculates the sum and count of negative elements below the 4th row of a 2D array. The second exchanges the elements of the 3rd and 4th areas of a 2D array. Code snippets and output are provided. The conclusion states the student reinforced their C++ programming knowledge around 2D arrays.

Uploaded by

Kenneth Edwards
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
312 views

Lucrare de Laborator NR 4 Tema:Prelucrarea Masivelor Bidimensionale

This document is a lab report submitted by a student, Corneliu Corman, for a programming course at the Moldova Technical University. It details 4 exercises working with 2D arrays in C++. The first exercise calculates the sum and count of negative elements below the 4th row of a 2D array. The second exchanges the elements of the 3rd and 4th areas of a 2D array. Code snippets and output are provided. The conclusion states the student reinforced their C++ programming knowledge around 2D arrays.

Uploaded by

Kenneth Edwards
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Ministerul Educatiei al Republicii Moldova

Universitatea Tehnica a Moldovei


Catedra Sisteme si Dispozitive electronice.

La disciplina:Programare

Lucrare de Laborator nr 4
Tema:Prelucrarea masivelor
bidimensionale.
A efectuat st. gr. SOE-121

Corman Corneliu

A verificat I. sup.

Chihai Andrei

Chisinau 2012

1)Varianta 11
2)Sarcini: De aflat suma si cantitatea elementelelor
Negative mai sus de rindul patru.
3)Schema logica.
#include<stdio.h>
#include<conio.h>
#include<math.h>
Void main(){
int x[50][50],i,j,n,m,S=0,k;
printf(Introduceti numarul rindurilor);
scanf(%d,&n);
printf(Introduceti numarul coloanelor);
scanf(%d,&n);
for(i=0;i<n;i++){
for(j=0;j<m;j++){
printf(x[%d][%d]=,i,j);
scanf(%d,&x[i][j]);}}
prinf(Masivul initial);
for(i=0;i<n;i++){
for(j=0;j<m;j++){
printf(%3d,x[i][j]);}
printf(\n);}
k=0;
for(i=3;i<n;i++){
for(j=0;j<m;j++){
if(x[i][j]<0){
s+=x[i][j];k++;}}}
printf(S=%d,k=%d,S,k);
getch();}

4)Schema bloc:
Start

&n

I=0;i<n;i++

j=0;j<m;j++

X[%d][%d]

X[i][j]

i=0;i<n;i++

j=0;j<m;j++

%3d

/n

1
I=4;i<n;i++

j=0;j<m;j++

(Ifx[i][j]<0)
_

S+=x[i][j]

Getch();}

5)Descrierea si analiza rezultatelor:


S=0,k=0 introduceti nr rindurilor 5
Introducetinr coloanelor 3
X[0][0]=1 X[0][1]=2 X[0][2]=3
X[1][0]=4 X[1][1]=5 x[1][2]=6
X[2][0]=7 x[2][1]=8 x[2][2]=1
X[3][0]=2 x[3][1]=-3 x[3][2]=-2
X[4][0]=4 x[4][1]=5 x[4][2]=-8

Masivul initial
1

-3 -2

-8

S=-13 , k=3

b)
1)Sarcina :de schimbat cu locul elementul ariei 3 cu el ariei 4.
2)Schema bloc :
Start

Introd nr n

&n
Alege metod de

If((z
==
automat

manual

&n
i=o;i<n;i++
j=o;j<m;j++

X=[i][j]=random

1
i=o;i<n;i++

j=o;j<m;j++

X=%d[%d]
&x[i]

i=o;i<n;i++
j=o;j<m;j++

%3d

i=n/2;i<n;i++

j=0;j<n/2;j++

Ex.1

Getch()

Ex.1= aux=x[i][j]; x[i][j]=x[i+n/2][j+n/2]; x[i+n/2][j+n/2]=aux;

/n

4)Schema logica:

#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void main(){
int x[50][50],n,i,j,aux;
char z;
clrscr();
printf(" Culegeti marimea masivului\n");
scanf("%d",&n);
label:clrscr();
printf("alege metoda de completare");
printf("\n a-Automat");
printf("\n m-Manual");
z=getch();
if((z=='a')||(z=='A')) goto automat;
else
if((z=='m')||(z=='M')) goto manual;
else goto label;
automat:randomize();
for(i=0;i<n;i++){
for(j=0;j<n;j++){
x[i][j] =random(19)-9;}}
goto masiv;
manual:
for(i=0;i<n;i++){
for(j=0;j<n;j++){

printf("x[%d][%d]=",i,j);
scanf("%d",&x[i][j]);}}
masiv:printf("\n Masivul initial");
for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("%3d",x[i][j]);}
printf("\n");}
for(i=n/2;i<n;i++){
for(j=0;j<n/2;j++){
aux=x[i][j];
x[i][j]=x[i+n/2][j+n/2];
x[i+n/2][j+n/2]=aux;
printf("Elementul ariei 3 a fost schimbat cu elementele ariei 4");
getch();}}}

Afisare program:
Introduceti numarul de rinduri:
4
Introduceti numarul de coloane:
4
X[0][0]=1 X[0][1]=2 X[0][2]=-3 X[0][3]=5
X[1][0]=-4 X[1][1]=2 X[1][2]=3 X[1][3]=6
X[2][0]=5 X[2][1]=6 X[2][2]=-7 X[2][3]=3
X[3][0]=4 X[3][1]=2 X[3][2]=7 X[3][3]=1

Masivul initial:

1 2 -3 5
-4 2 3 6
5 6 -3 3
4 2 7 1

Masivul final:
1 2 5 6
-4 2 4 2
-3 3 5 6
7 1 4 2

Concluzie: In urma efectuarii acestei lucrari de laborator am intarit cunostintele


mele in principalele actiuni ale limbajului de programare C++ ,si am facut
cunostinta cu modul de elaborare a masivului bidimensional si structura lui,am
rezolvat probleme in dependenta de conditie si am vazut cum ele se indeplinesc.

You might also like