C++ Subprograme fara parametrii

#include<iostream.h>

// Suprograme fara parametrii si care nu returneaza valori

void max2()
{
cout<<“MAXIMUL a 2 nr. intregi”<<endl;
int a,b; // variabilele locale
cout<<“a=”;
cin>>a;
cout<<“b=”;
cin>>b;

if(a>b)
cout<<“Max=”<<a<<endl;
else cout<<“Max=”<<b<<endl;

}
void cmmdc()
{
int a,b; // variabilele locale
cout<<“CMMDC a 2 nr.”<<endl;
cout<<“a=”;
cin>>a;
cout<<“b=”;
cin>>b;

// algoritmul lui Euclid

while(a!=b)
if(a>b)
a=a-b;
else
b=b-a;

cout<<“cmmdc=”<<a<<endl;

}
void citire_v()
{
int n, v[10],i;
cout<<“CITIREA vectorului de la tastatura:”<<endl;
cout<<“Lg. vector=”;
cin>>n;
for(i=1;i<=n;i++)
{
cout<<“v[“<<i<<“]=”;
cin>>v[i];
}

}
void afisare_v()
{
int n, v[10],i;
cout<<“AFISAREA vectorului pe ecran:”<<endl;
for(i=1;i<=n;i++)
cout<<v[i]<<” “;

}

void main()
{
max2(); //apeluri functii
cmmdc();
citire_v();
afisare_v();
}

 

#include<iostream.h>

// Suprograme fara parametrii si care RETURNEAZA valori

int max2()
{
cout<<“MAXIMUL a 2 nr. intregi”<<endl;
int a,b; // variabilele locale
cout<<“a=”; cin>>a;
cout<<“b=”; cin>>b;

if(a>b)
return a;
else return b;
}

int cmmdc()
{
int a,b; // variabilele locale
cout<<“CMMDC a 2 nr.”<<endl;
cout<<“a=”; cin>>a;
cout<<“b=”; cin>>b;

// algoritmul lui Euclid
while(a!=b)
if(a>b)
a=a-b;
else
b=b-a;

return a;
}

int invers()
{
cout<<“Inversul”<<endl;
int n,inv=0;

cout<<“n=”; cin>>n;

while(n!=0)
{
inv=inv*10+n%10;
n=n/10;
}
return inv;
}
// Programul principal
void main()
{
cout<<“Maximul=”<<max2()<<endl; //apeluri functii
cout<<“CMMDC=”<<cmmdc()<<endl;
cout<<“Inversul=”<<invers();
}

Leave a comment

Adresa ta de email nu va fi publicată. Câmpurile obligatorii sunt marcate cu *

Time limit is exhausted. Please reload the CAPTCHA.