Varianta 22 bacalaureat informatica 2007

Cerinte si rezolvari

{pdf=pdf/bacalaureat2007/varianta_022.pdf|600|600}

1)

#include<iostream.h>
#include<math.h>
int n,i,j,x,a[10];
void nr()
{
while(n)
{
i++;
a[i]=n%10;
n=n/10;
}
}
void f()
{
for(j=1;j<=i;j++)
{
for(x=i;x>j;x--)
cout<<a[x];
for(x=j-1;x>=1;x--)
cout<<a[x];
cout<<" ";
}
}
void main()
{
cout<<"dati n:";cin>>n;
nr();
f();
}
2)
#include<iostream.h>
int n;
int F(int x)
{
int a,b,c,d,nr;
a=1;
b=2;
c=3;
nr=3;
if(x<=3)
return x;
else
{
while(nr<x)
{
nr++;
d=(c*b+a+b)%nr;
a=b;
b=c;
c=d;
}
return d;
}
}



void main()
{
cin>>n;
cout<<F(n);
}
3)
#include<fstream.h>
ifstream f("bac.txt");
int n,i,j,a[10][10],l,c,s;
void citire()
{
f>>n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
f>>a[i][j];
}

void matrice()
{
int l2=l,c2=c;
while(l2<=n)
{
s=s+a[l2][c2];

l2++;
c2--;
}
while(c<=n)
{
l--;
c++;
s=s+a[l][c];
}
}
void main()
{
citire();
cin>>l>>c;
matrice();
cout<<s;
}