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

Rezolvare 1

The document contains 7 code snippets written in C++ that perform various operations on integers such as calculating the sum and product of digits, reversing numbers, checking if a number is a palindrome, extracting maximum and minimum digits. The code snippets accept a number as input and perform the corresponding operation and output the results.

Uploaded by

Flavius Mocan
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 views3 pages

Rezolvare 1

The document contains 7 code snippets written in C++ that perform various operations on integers such as calculating the sum and product of digits, reversing numbers, checking if a number is a palindrome, extracting maximum and minimum digits. The code snippets accept a number as input and perform the corresponding operation and output the results.

Uploaded by

Flavius Mocan
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/ 3

1.

#include <iostream>
using namespace std;
int main()
{
int x,s=0,a,p=1,b,nr=0;
cin>>x;
a=x;
while(a!=0)
{
s=s+a%10;
a=a/10;
}
b=x;
while(b!=0)
{
p=p*(b%10);
b=b/10;
}
while(x!=0)
{
nr++;
x=x/10;
}
cout<<s<<" "<<p<<" "<<nr;
return 0;
}
2.
#include <iostream>
using namespace std;
int main()
{
int x,ogl=0;
cin>>x;
while(x!=0)
{
ogl=ogl*10+x%10;
x=x/10;
}
cout<<ogl;
return 0;
}
3.
#include <iostream>
using namespace std;
int main()
{
int x,ogl=0,a;
cin>>x;
a=x;
while(a!=0)
{
ogl=ogl*10+a%10;
a=a/10;
}
if(x==ogl)
cout<<"Numarul este polindrom";
else
cout<<"Numarul nu este polindrom";
return 0;
}
4.
#include <iostream>
using namespace std;
int main()
{
int x,a,u,z,p,n23,n12,b,ogl=0,n=0;
cin>>x;
u=x%10;
z=x/10%10;
a=x;
while(a!=0)
{
p=a%10;
a=a/10;
}
n23=z*10+u;
b=x;
while(b!=0)
{
ogl=ogl*10+b%10;
b=b/10;
}
n12=ogl%10*10+ogl/10%10;
while(x!=0)
{
n=n*10+x%10;
x=x/100;
}
cout<<u<<" "<<z<<" "<<p<<endl;
cout<<n23<<" "<<n12<<endl;
cout<<n;
return 0;
}
5.
#include <iostream>
using namespace std;
int main()
{
int x,cm=0,nr=0;
cin>>x;
int a=x;
while(a!=0)
{
if(cm<a%10)
cm=a%10;
a=a/10;
}
while(x!=0)
{
if(x%10==cm)
nr++;
x=x/10;
}
cout<<cm<<" "<<nr;
return 0;
}
6.
#include <iostream>
using namespace std;
int main()
{
int x,ok;
cin>>x;
int a=x%10;
while(x!=0)
{
if(x%10!=a)
{
ok=1;
break;
}
x=x/10;
}
if(ok==1)
cout<<"Nu";
else
cout<<"Da";
return 0;
}
7.
#include <iostream>
using namespace std;
int main()
{
int x,a,ok;
cin>>x;
a=x;
while(x!=0)
{
if(a%10<x/10%10)
{
ok=1;
break;
}
x=x/10;
a=a/10;
}
if(ok==1)
cout<<"Nu";
else
cout<<"Da";
return 0;
}

You might also like