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

Info DDD

The document contains code snippets for solving 6 problems: 1) Finding the greatest common divisor (GCD) of two numbers using the Euclidean algorithm 2) Displaying a decimal number with a specified number of decimal places 3) Modifying elements of an array by incrementing odd indices and decrementing even indices 4) Sorting an array of point structures based on x- and y-coordinates 5) Defining a student structure with name, surname, and grade attributes 6) Sorting an array of student structures by grade in descending order

Uploaded by

valicuinfo
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)
20 views3 pages

Info DDD

The document contains code snippets for solving 6 problems: 1) Finding the greatest common divisor (GCD) of two numbers using the Euclidean algorithm 2) Displaying a decimal number with a specified number of decimal places 3) Modifying elements of an array by incrementing odd indices and decrementing even indices 4) Sorting an array of point structures based on x- and y-coordinates 5) Defining a student structure with name, surname, and grade attributes 6) Sorting an array of student structures by grade in descending order

Uploaded by

valicuinfo
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

INFO

Problema 1
CMMDC
void euclid(int a, int b, int *c)
{
if (b == 0) {
*d = a;
} else
euclid(b, a % b, d);
}
void main()
{
int x,y,z,rez;
cout<<"x="; cin>>x;
cout<<y=;cin>>y;
rez = euclid(x,y,z);
cout << rez;s
}
problema 3
afisare zecimale
void afisare_zecimale(int m, int n, int z)
{
double rez;
rez=m/n;
cout<<setprecision(z+1)<<rez;
}
void main()
{
int x,y,z;
cout<<"m="; cin>>x;
cout<<n=;cin>>y;
cout<<nr de zecimale=;cin<<z;
afisare_zecimale(x,y,z);
}
problema 4
modificare vector
void modificare_vector (int x[], int n)
{
int i;
for (i=1;i<=n;i++)
if(i%2!=0)
x[i]=x[i]+1;
else x[i]=x[i]-2;
}
void main()
{

int x[100],n,i;
cout<<n=;cin>>n;
for (i=1;i<=n;i++)
cin<x[i]<<endl;
modificare_vector(x[],n);
for (i=1;i<=n;i++)
cout<<x[i]<< ;
}
problema 5
puncte in plan
typedef struct{
int x,y;
}PUNCT
void main(){
int n,i;
PUNCT aux,x[100];
cout<< n=;cin>>n;
for (i=0;i<n;i++){
cout<<punctul[<<i<<].x=;<<cin x[i].x;
cout<<punctul[<<i<<].y=;<<cin x[i].y;
}
for (i=0;i<n-1;i++){
if ((x[i].x>x[i+1]) && (x[i].y>x[i+1].y)){
aux=x[i];
x[i]=x[i+1];
x[i+1]=aux;
}
}
for (i=0;i<n;i++)
cout<<punctul[<<i<<]=(;<< x[i].x<<,<<x[i].y<<) ;
}
problema 6
student
typedef struct{
char nume[20],prenume[20];
float media;
}STUDENT
void main(){
int n,i;
STUDENT x[100],c[100];
int b[100];
cout<< n=;cin>>n;
for (i=0;i<n;i++){
cout<<student[<<i<<].nume=;<<cin x[i].nume;
cout<<student[<<i<<].prenume=;<<cin x[i].prenume;
cout<<student[<<i<<].media=;<<cin x[i].media;
}

for(i=0;i<n;i++){
b[i]=0;
for(j=1;j<=n;j++)
if(x[j].media<x[i].media)
b[i]++;
}
for(i=1;i<=n;i++)
c[b[i]+1]=c[i];
for(i=1;i<=n;i++)
cout<<c[i].nume<< <<c[i].prenume<< <<c[i].media;
}

You might also like