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

Lucrare de Laborator NR 1 Grupa: I-1324 Student: Balagura Vlad Nota: Profesor: Natalia Gainurova

The document contains code for several C++ programs that analyze arrays and matrices. The programs count the number of elements greater than the average, print letters in even positions of a string, print odd numbers less than or equal to a given number using different loops, count the number of occurrences of the maximum element, count elements with an absolute value greater than 3, and count the number of occurrences of the maximum element in a matrix.

Uploaded by

Vlad ....
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Lucrare de Laborator NR 1 Grupa: I-1324 Student: Balagura Vlad Nota: Profesor: Natalia Gainurova

The document contains code for several C++ programs that analyze arrays and matrices. The programs count the number of elements greater than the average, print letters in even positions of a string, print odd numbers less than or equal to a given number using different loops, count the number of occurrences of the maximum element, count elements with an absolute value greater than 3, and count the number of occurrences of the maximum element in a matrix.

Uploaded by

Vlad ....
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Lucrare de laborator nr 1

Grupa: I-1324
Student:
Balagura Vlad
Nota:
Profesor: Natalia Gainurova

//Numarul elementelor mai mari ca media aritmetica//


#include <iostream>
#include <conio>
#include <math.h>
int a[10][10],n,i,j,s,m;
int main()
{
cout<<"n="; cin>>n;
cout<<"m="; cin>>m;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{cout<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j]; s+=a[i][j];}
int k=0;
float b=s/(m*n);
for(i=0;i<n;i++)
for(j=0;j<m;j++)
if(a[i][j]>b) k++;
cout<<k;
getch();
return 0;
}
Afisare:
n=2
m=2
a[0][0]=1
a[0][1]=50
a[1][0]=1
a[1][1]=60
2

//sa se afiseze literele de pe pozitiile pare//


#include<iostream.h>
#include<conio.h>
int main()
{
int i,n;
char v[20];
cin>>v;
for(i=0;i<strlen(v);i++)
if((i%2==0))
cout<<v[i]<<" ";
getch();
return 0;
}
Afisare:
mama
mm

//numerele naturale impare mai mici sau egale cu n//

while
#include<iostream.h>
#include<conio.h>
int main()
{
int i,n,k;
cout<<"n="; cin>>n;
i=0;
while(i<=n)
{ i++ ;
if(i%2==1)
cout<<i<<endl;
}
getch();
return 0;
}

do while
#include<iostream.h>
#include<conio.h>
int main()
{
int i,n,k;
cout<<"n="; cin>>n;
i=0;
do
{ i++ ;
if(i%2==1)
cout<<i<<endl;
}

while(i<=n);
getch();
return 0;
}

for
#include<iostream.h>
#include<conio.h>
int main()
{
int i,n;
cout<<"n="; cin>>n;
for (i=0; i<=n; i++)
{ if(i%2==1)
cout<<i<<endl;
}
getch();
return 0;
}
Afisare:
n=8
1
3
5
7

//de cite ori figureaza elementul cu valoarea maxima//

#include <iostream>
#include <conio.h>
int main()
{
float a[100], k=0, max;
int i,n;
cout << "n="; cin >> n;
for (i = 0; i<n; i++)
{cout << "a[" << i << "]="; cin >> a[i];}
max=a[1];
for (i = 0; i<n; i++)
if (max<a[i]) max=a[i];
for(i=0;i<n;i++)
if (max==a[i])k++;
cout<<max<<" "<<k;
getch();
return 0;
}
Afisare:
n=5
a[0]=1
a[1]=2
a[2]=6
a[3]=4
a[4]=6
6 2

//nr componentelor cu modulul mai mare ca 3//


#include<iostream.h>
#include<conio.h>
#include<math.h>

int main()
{
int a[100],n,i,k=0;
cout<<"n="; cin>>n;
for(i=0;i<n;i++)
{cout<<"a["<<i<<"]="; cin>>a[i];}
for(i=0; i<n; i++)
if (abs (a[i])>3) k++;
cout<<k;
getch();
return 0;
}
Afisare:
n=5
a[0]=1
a[1]=-7
a[2]=5
a[3]=-6
a[4]=2
3

#include <iostream>
#include <conio>
int main()
{
int n,m,min,i,j,max,a[30][30],k=0;
cout<<"Dati dimensiunile matricii"<<endl;
cout<<"Dati numarul de linii : ";cin>>n;
cout<<"Dati numarul de coloane : ";cin>>m;

for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
cout<<"a["<<i<<","<<j<<"]= ";
cin>>a[i][j];
}
max=a[0][0];
k++;
for(i=1;i<n;i++)
for(j=0;j<m;j++)
{
if(a[i][j] == max)//daca maxim-ul mai este prin matrice atunci incrementam
k++;
else
if(a[i][j]>max)
{
max=a[i][j];//s-a gasit alt maxim
k = 1;//resetam la 1, pentru ca el deja este
}
}
cout<< max<<endl<<k;
getch();
return 0;
}
Afisare:
Dati dimensiunile matricii
Dati numarul de linii : 3
Dati numarul de coloane : 3
a[0,0]= 1
a[0,1]= 2
a[0,2]= 3
a[1,0]= 4
a[1,1]= 3
a[1,2]= 5
a[2,0]= 5
a[2,1]= 1
a[2,2]= 0
5
2

You might also like