0% found this document useful (0 votes)
27 views5 pages

Info 5

The document contains C++ code for several problems involving functions that take integers as parameters and return integers or void. The functions perform operations like summing digits in odd positions, checking if a number has identical adjacent digits, finding the number of pairs that are products of consecutive integers, finding the greatest common divisor of two numbers, sorting arrays, and calculating sums of the first elements.

Uploaded by

Luminita Stefan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views5 pages

Info 5

The document contains C++ code for several problems involving functions that take integers as parameters and return integers or void. The functions perform operations like summing digits in odd positions, checking if a number has identical adjacent digits, finding the number of pairs that are products of consecutive integers, finding the greatest common divisor of two numbers, sorting arrays, and calculating sums of the first elements.

Uploaded by

Luminita Stefan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include <iostream>

using namespace std;/** ex 30 **/


int CifreImpare(int n)
{ int a=0,p=1,b=n;
while(n!=0)
{
if(n%2==0)
{
a+=n%10*p;
p=p*10;
}
n=n/10;
}
if(a==b || a==0)
return -1;
return a;

int main()
{
int x;
cin>>x;
cout<<CifreImpare(x);
return 0;
}

#include <iostream>

using namespace std;/**ex 40**/


int cifid(int n)
{

while(n>=10)

if(n%10!=(n/10)%10)
return 0;
n=n/10;
return 1;

}
void Identice(int a,int b)
{
int i,ok=0;
for(int i=a;i<=b;i++)
{ if(cifid(i)==1)
{
cout<<i<<' ';
ok=1;
}

}
if(!ok)
cout<<"Nu exista ";
}
int main()
{int x,y;
cin>>x>>y;
Identice(x,y);

return 0;
}

include <iostream>
#include <cmath>
using namespace std;/** ex 44**/
int prodcons(int n)
{ int p=sqrt(n);
if(p*(p+1)==n)
return 1;
else
return 0;

}
int nrdiv(int a,int b)
{ int i,nr=0;
for(int i=a;i<=b;i++)
if(prodcons(i)==1)
nr++;
return nr;

}
int main()
{ int x,y;
cin>>x>>y;
cout<<nrdiv(x,y);

return 0;
}
#include <iostream>

using namespace std; /**ex 45**/


int cmmdc(int a,int b)
{ while(a!=b)
if(a>b)
a=a-b;
else
b=b-a;
return a;

}
int divimpar (int a, int b)
{ int n=cmmdc(a,b);
if(n%2==0)
n--;
for(;n;n-=2)
if(a%n==0 && b%n==0)
return n;

}
int main()
{
int x,y;
cin>>x>>y;
cout<<divimpar (x,y);
return 0;
}

#include <iostream>

using namespace std; /** ex 53**/


void Aranjare (int v[10000], int n)
{
int j=0;
for(int i=1;i<n;i++)
if(v[i]%2!=0)
swap(v[i--],v[j++]);

for(int i=0;i<n;i++)
cout<<v[i]<<' ';

}
int main()
{
int a[100],n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
Aranjare(a,n);
return 0;
}
#include <iostream>

using namespace std;/** ex 47 **/


int sdivp (int a)
{
int d,s=0;
for(d=2;d<=a/2;d++)
if(a%d==0)
s=s+d;

return s;
}
int este_spar(int x)
{ if(x%2==0 && sdivp(x)%2==0)
return 1;
return 0;

}
void spar (int n)
{
while(!este_spar(n))
n++;
cout<<n;

}
int main()
{ int b;
cin>>b;
spar (b);

return 0;
}

#include <iostream>

using namespace std;/** ex 56 **/


void Pminim (int n,int x[1000], int &minv,int &maxv,int &sum)
{ int i;
minv=maxv=sum=x[0];
for(i=1;i<n;i++)
{
if(x[i]<minv)
minv=x[i];
if(x[i]>maxv)
maxv=x[i];
sum+=x[i];
}

int main()
{
int v[100],n,a,b,c;
cin>>n;
for(int i=0;i<n;i++)
cin>>v[i];
Pminim(n,v,a,b,c);
cout<<a<<" "<<b<<" "<<c;

return 0;
}

#include <iostream>

using namespace std;/** ex 58 **/


int suma( int n, int x[100], int m)
{ for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
if(x[i]>x[j])
swap(x[i],x[j]);
int s=0;
for(int i=0;i<m;i++)
s+=x[i];
return s;

int main()
{
int m, v[100], n;
cin>>n;
cin>>m;
for(int i=0;i<n;i++)
cin>>v[i];
cout<< suma( n,v,m);

return 0;
}

You might also like