1) Se citeste un nr mare. sa se afiseze nr max format din cifrele lui
#include<iostream>
using namespace std;
int main()
{int n,i,a[100],aux,ordonat=0,p;
cout<<"n=";cin>>n;
for(i=0;i<n;i++)
{cout<<"p=";cin>>p;a[i]=p;}
do{ordonat=1;
for(i=0;i<n-1;i++)
if(a[i]<a[i+1]){aux=a[i];
a[i]=a[i+1];
a[i+1]=aux;
ordonat=0;}}
while(ordonat==0);
cout<<endl;
for(i=0;i<n;i++)cout<<a[i];
}
2) Cel mai mic nr care se poate forma
#include<iostream>
using namespace std;
int main()
{int ok,k,n,i,a[100],aux,ordonat=0,p;
cout<<"n=";cin>>n;
for(i=0;i<n;i++)
{cout<<"a["<<i<<"]=";cin>>a[i];}
do{ordonat=1;
for(i=0;i<n-1;i++)
if(a[i]>a[i+1]){aux=a[i];
a[i]=a[i+1];
a[i+1]=aux;
ordonat=0;}}
while(ordonat==0);
if(a[0]==0)ok=1;
if(ok)
for(i=0;i<n;i++)
if(a[i]!=0){k=i;break;}
aux=a[k];a[k]=a[0];a[0]=aux;
for(i=0;i<n;i++)
cout<<a[i];
}
Orar semigroup #2
16 aprilie - probleme
vineri, 9 iulie 2010
by DlMuresan
Categories:
info,
ordonare,
vectori
|
Leave a comment