Bac.2009-Varianta 53
Rezolvare Bac. 2009 -Varianta 53
Subiectul I
1. c
2. a) 13
b) 2000
c) citeste x
(numar natural nenul)
z<-0
p<-1
-cat timp x<>0 executa
| c<-x%10
| -daca c%2<>0 atunci
| | z<-z+c*p
| | p<-p*10
| |_
|
| x<-[x/10]
|_
scrie z
d)
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
int x,c,p,z;
cout<<"x=";cin>>x;
z=0;
p=1;
do
{
c=x%10;
if(c%2!=0)
{
z=z+c*p;
p=p*10;
}
x=x/10;
}while(x!=0);
cout<<z;
return 0;
}
Subiectul II
1. c
2. a
3. 12
4. vectorul de tati: (3, 4, 4, 0, 2, 3, 6, 6)
descendentii nodului 3: 1, 5, 6, 7 ,8
5.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
int m,n,x,y,i,j,aux;
cout<<"m=";cin>>m;
cout<<"n=";cin>>n;
cout<<"x=";cin>>x;
cout<<"y=";cin>>y;
int a[m][n];
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
cin>>a[i][j];
for(j=1;j<=n;j++)
{
aux=a[x][j];
a[x][j]=a[y][j];
a[y][j]=aux;
}
for(i=1;i<=m;i++)
{for(j=1;j<=n;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
return 0;
}
Subiectul III
1. a
2. f(2138) are valoarea 10
f(513) are valoarea 0
3.
a) long cmmdc(long a, long b)
b)
#include <iostream>
#include <fstream>
using namespace std;
long cmmdc(long a, long b)
{
while(a!=b)
if(a>b)
a=a-b;
else
b=b-a;
return a;
}
int main()
{
cout << "Hello world!" << endl;
ifstream f("date.in");
int n,i,s=0;
long x,nr;
f>>n;
f>>x;
for(i=1;i<n;i++)
{
f>>nr;
if(cmmdc(x,nr)==1)
s++;
x=nr;
}
cout<<s;
f.close();
return 0;
}
4.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
int i,j,n,aux;
cout<<"n=";cin>>n;
int a[n];
for(i=1;i<=n;i++)
cin>>a[i];
cout<<endl;
for(i=n;i>=1;i--)
{
for(j=1;j<=n;j++)
cout<<a[j]<<" ";
cout<<endl;
aux=a[1];
for(j=1;j<i;j++)
a[j]=a[j+1];
a[i]=aux;
aux=a[i];
for(j=i;j<=n;j++)
a[j]=a[j+1];
a[n]=aux;
}
return 0;
}