Info C++
Info C++
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;
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;
}
}