0% found this document useful (0 votes)
68 views28 pages

Variante Bac Si Atestat

The document contains solutions to programming problems from an exam. It includes code for: 1) A program that reads two numbers n and k and prints their product n*k repeatedly. 2) A program that reads an array of numbers, sorts it in ascending order, and prints the sorted array. 3) A program that reads two files containing numbers, merges the numbers from both files together in ascending order, and prints the merged list.
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)
68 views28 pages

Variante Bac Si Atestat

The document contains solutions to programming problems from an exam. It includes code for: 1) A program that reads two numbers n and k and prints their product n*k repeatedly. 2) A program that reads an array of numbers, sorts it in ascending order, and prints the sorted array. 3) A program that reads two files containing numbers, merges the numbers from both files together in ascending order, and prints the merged list.
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/ 28

Varianta 10

Subiectul I
1-a)
2-a) 24
-b) n=233456 k=3
n=2332456 k=4
-c) --citeste n,k
| nr <-0
| p<-1
| exectuta
| -- daca n%2 ≠0 atunci
| | nr<-nr+[n/10]%10*p
| | p=p*10
| | altfel
| | k<-k-1
| |-----⌂
| n<-[n/10]
|cat timp n≠0 si k ≠0
|---⌂
-d)
cin>>n>>k;
nr=0;
p=1;
while(n!=0 && k!=0)
{
If(n%2!=0)
{
nr=nr+n/10%10*p;
p=p*10;
}else k=k-1;
n=n/10;
}
cout<<nr;
Subiectul II

1-a)
3- 3081
4- abacde
5- #include <iostream>
#include <string.h>

using namespace std;

int main()
{
int n,p,i,j,nr=0,x[100][100];
cin>>n>>p;
for(i=1;i<=n;i++)
{
for(j=1;j<=p;j++)
{
x[i][j]=nr*nr;
nr=nr+2;
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=p;j++)
{
cout<<x[i][j]<<" ";
}
cout<<endl;
}

}
Subiectul III

1-a)
2- 56789
3-
int sub(int n, int &a, int &b)
{
int i,j,ok,k=0;
for(i=n-1;i>=2;i--)
{
ok=0;
for(j=2;j<=i/2;j++)
if(i%j==0)
{
ok=1;
break;
}
if(ok==0 && k==0)
{
a=i;
k=1;
}else if(ok==0)
{
b=i;
return 0;
}

}
}
4-
#include <iostream>
#include <fstream>
#include <assert.h>

using namespace std;


ifstream fin("PRODUSE.TXT");
int suma[10000];
int main()
{
int n,i=1,tip[9999],a,b,k;
fin>>i>>a>>b;
while(!fin.eof())
{

suma[i]=suma[i]+(a*b);
fin>>i>>a>>b;

}
i=1;
while(suma[i]!=0)
{
cout<<i<<" "<<suma[i]<<endl;
i++;
}

Varianta 11
Subiectul I
1- a)
2 -a) 15
-b)98888
-c)
cin>>n>>k;
p=1;
while(n>0 && k>0)
{ c=n%10;
If(c%2==1)
P=p*c;
n=n/10;
k=k-1;
}
cout<<p;
-d)
citeste n,k
p<-1
pentru n si k, n>0 && k>0,k-1 executa
| c<-n%10;
| daca c%2=1 atunci
| | p<-p*c
| |----------⌂
| n<-[m/10]
|-------- ⌂
scrie p
Subiectul II

1-d)
2-c)
3- 11 brcdbr
5)
#include <iostream>
#include <string.h>

using namespace std;

int main()
{
int x[10][10],i,j,n,m,k,minn;
cin>>m>>n;
cin>>x[1][1];
minn=x[1][1];
for(j=2;j<=m;j++)
{
cin>>x[1][j];
if(x[1][j]<minn)
minn=x[1][j];

for(i=2;i<=n;i++)
{
cin>>x[i][1];
k=x[i][1];
for(j=2;j<=m;j++)
{
cin>>x[i][j];
if(x[i][j]<k)
k=x[i][j];

}
if(k>minn)
minn=k;
}
cout<<minn;
}

Subiectul III
1-a)
2-f(5)->5
f(23159)->1
3-#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("numere.txt");
int main()
{
int n,i,maxx,x;
fin>>n;
fin>>x;
maxx=x;
cout<<maxx<<" ";
for(i=2;i<=n;i++)
{
fin>>x;
if(x>maxx)
{
maxx=x;
cout<<maxx<<" ";
}else cout<<maxx<<" ";
}
}
4-#include <iostream>

using namespace std;


int n, v[25],nr=0;

int sum(int x,int i)


{
if(i<x)
{
if(x%i==0)
return i+sum(x,i+1);
else sum(x,i+1);

}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>v[i];
if(sum(v[i],1)==v[i]+1)
nr++;
}
cout<<nr;

}
Varianta 12
Subiectul I
1-d)
2-a) 17396
-b) 3,2,1,0
-c) cin>>x;
y=0;
while(x!=0)
{
While(x>9)
X=x/10;
y=y*10+x;
cin>>x;
}cout<<y;
-d)
citeste x
y<-0
executa
| executa
| | x<-[x/10]
| | cat timp x>9
| |-----⌂
| y<-y*10+x
| citeste x
| cat timp x≠0
|-------⌂

Subiectul II
1-b)
3- grad minim:1
grad maxim:n-1
4- 11 *nf*nm*t*c*
5-#include <iostream>

using namespace std;


int main()
{
int i,j,n,x[25][25];
cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
x[i][j]=i*j%10;
cout<<x[i][j]<<" ";
}
cout<<endl;
}
}

Subiectul III
1-c)
2- 2+2+2+3
2+2+5
2+7
3-#include <iostream>
#include <fstream>
#include <assert.h>
using namespace std;
ifstream fin1("NR1.TXT");
ifstream fin2("NR2.TXT");

int main()
{
int x[100],v[100],n=0,m=0,i,j;
fin1>>i;
while(!fin1.eof())
{

if(i%5==0)
{
n++;
x[n]=i;

}
fin1>>i;
}
fin2>>j;
while(!fin2.eof())
{

if(j%5==0)
{
m++;
v[m]=j;

}
fin2>>j;

}
i=1;
j=1;
while(j<=m && i<=n)
{
while(x[i]<v[j])
{
cout<<x[i]<<" ";
i++;
}
if(v[j]==x[i])
{
i++;
j++;
}
while(v[j]<x[i])
{
cout<<v[j]<<" ";
j++;
}
}

if(j<=m)
{
for(j=j;j<=m;j++)
cout<<v[j]<<" ";

}
if(i<=n)
{
for(i=i;i<=n;i++)
cout<<x[i]<<" ";
}

}
4-#include <iostream>

using namespace std;


int v[100];
int main()
{
int n,x[100],i,k,ok,j;
cin>>n;
for(i=1;i<=n;i++)
{
ok=0;
cin>>x[i];
k=x[i]%10;
x[i]=x[i]/10;
while(x[i])
{
if(k!=x[i]%10)
{
ok=1;
break;
}
x[i]=x[i]/10;
}
if(ok==0)
v[k]++;

}
for(i=1;i<=9;i++)
{
while(v[i]>0)
{
for(j=1;j<=5;j++)
cout<<i;
cout<<" ";
v[i]--;
}
}

}
Atestat
Subiectul nr 7
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("ATESTAT7.IN");
ofstream fout("ATESTAT7.OUT");

int main()
{
int n,k;
fin>>n>>k;
while(n)
{
fout<<n*k<<" ";
n--;
}
}
Subiectul 8
#include <iostream>
#include <fstream>

using namespace std;


ifstream fin("ATESTAT8.IN");
ofstream fout("ATESTAT8.OUT");
int main()
{
int x[50],i,n,f,aux,k;
fin>>n;
for(i=1;i<=n;i++)
fin>>x[i];
k=n;
do{
f=0;
for(i=1;i<=n;i++)
{
if(x[i]>x[i+1])
{
aux=x[i];
x[i]=x[i+1];
x[i+1]=aux;
f++;
}

}
}while(f);
for(i=1;i<=n;i++)
fout<<x[i]<<" ";
}

You might also like