0% found this document useful (0 votes)
16 views3 pages

Info C++

The document contains three programming exercises. The first exercise contains a function to find all the divisors of a number. The second exercise involves reading a 2D array and finding the maximum sum of adjacent elements that is a perfect square. The third exercise reads numbers from a file and finds the three most frequent numbers.

Uploaded by

Ramona Roman
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)
16 views3 pages

Info C++

The document contains three programming exercises. The first exercise contains a function to find all the divisors of a number. The second exercise involves reading a 2D array and finding the maximum sum of adjacent elements that is a perfect square. The third exercise reads numbers from a file and finds the three most frequent numbers.

Uploaded by

Ramona Roman
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/ 3

MODEL 2024 ~SIII~

Ex 1(subprogram) Ex 2
#include <iostream> #include <iostream>
#include <string.h>
using namespace std; using namespace std;
int produs(int a, int b) int main()
{ {
int minim=0,p=1; char sir[101],*p,sir1[101],sir2[101];
if(b<a) int n;
minim=b; cin>>n;
else minim=a; cin.get();
for(int i=1;i<=minim;i++) cin.getline(sir,101);
if(a%i==0&&b%i==0) p=strtok(sir," ,.?!#");
{ strcpy(sir1,"");
p=p*i; strcpy(sir2,"");
} while(p)
return p; {
} if(strlen(p)<n)
int main() {
{ strcat(sir1,p);
int a,b; strcat(sir1," ");
cin>>a; }
cin>>b; else if(strlen(p)>n)
cout<<produs(a,b); {
return 0; strcat(sir2,p);
} strcat(sir2," ");
}
p=strtok(NULL," ,.?!#");
}
if(sir1==NULL||sir2==NULL)
cout<<"nu exista";
else
cout<<sir1<<endl<<sir2;
return 0;
}
Ex 3
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("bac.txt");
int main()
{
int n, n1, n2, n3, v[1001], ok1 = 0, ok2 = 0, ok3 = 0;
for (int i = 10; i <= 1000; i++)
{
v[i] = 0;
}
f >> n1 >> n2 >> n3;
while (f >> n)
{
v[n]++;
}
for (int i = 1000; i >= 10; i--)
{
if (v[i] >= n1 && ok1==0)
{
ok1 = i;
n1 = 0;

}
if (v[i] >= n2 && ok2==0 && i<ok1)
{
ok2 = i;
n2 = 0;
}
if (v[i] >= n3&& ok3==0 && i<ok2)
{
ok3 = i;
n3 = 0;
}

}
if (ok1 != 0 && ok2 != 0 && ok3 != 0)
cout << ok1 << " " << ok2 << " " << ok3;
else cout<<"nu";
return 0;
}
SESIUNEA AUGUST 2023
Ex1
#include <iostream>
using namespace std;

void DNPI(int n)
{
int ok = 0;
cout << 1<<" ";
for (int i = 1; i <= n / 2; i = i + 2) {
ok = 0;
if (n % i == 0) {
for (int j = 2; j <= i / 2; j++) {
if (i % j == 0) {
ok=1;
}
}

if (ok == 1)
cout << i << " ";
}

}
}
Ex2
int main()
{
int m, n, a[20][20];
cin >> n >> m;

for (int i = 1; i <= n; i++)


for (int j = 1; j <= m; j++)
cin >> a[i][j];

int maxs = 0;
for(int i=1; i<n; i++)
for (int j = 1; j < m; j++)
{
int sum = a[i][j] + a[i][j + 1] + m[i + 1][j] + m[i + 1][j + 1];
int rad = sqrt(sum);
if (rad * rad == sum) {
if (maxs < sum)
maxs = sum;
}
}

cout << maxs;


return 0;
}

You might also like