Jump to content

Recommended Posts

Posted

-functii fara parametri

100-ariile unor figuri geometrice

-functii cu parametri transmisi prin valoare

101-calculeaza media aritmetica a doua nr reale

102-interschimbarea a doua linii intr-o matrice

104-nr +, nr-, nr0 intr un vector

103-calculeaza sumele elementelor de pe liniile matricii, memorandu-le intr un

vector S

-functii care returneaza o valoare

105-max dintre mediile aritmetice a doua perechi de nr

106-suma cifrelor unui numar

107-verifica cate cifre pare are un nr dat

100.

#include<iostream.h>

float pi=3.14159;

void aria_patrat()

{

int L;

cout<<"Latura: "; cin>>L;

if(L>0)

 cout<<endl<<"Aria este: "<<L*L;

else

 cout<<endl<<"date incorecte!!!";

}

void aria_cerc()

{

int R;

cout<<"Raza: "; cin>>R;

if(R>0)

 cout<<endl<<"Aria este: "<<pi*R*R;

else

 cout<<endl<<"date incorecte!!!";

 }

 void aria_triunghi()

 {

 int B, H;

 cout<<"Baza B si inaltimea H: "; cin>>B>>H;

 if((B>0) && (H>0))

	cout<<endl<<"Aria este: "<<(B*H)/2;

 else

	cout<<endl<<"date incorecte!!!";

 }

 void main()

 {

 int opt;

 cout<<"optiunea dvs. = 1. Patrat  2. Cerc  3. Triunghi: \n"; cin>>opt;

 switch(opt)

 {

 case 1:

	aria_patrat();

	break;

 case 2:

	aria_cerc();

	break;

 case 3:

	aria_triunghi();

	break;

	default:

	cout<<endl<<"date incorecte!!";

	}

}
101.
#include<iostream.h>

#include<conio.h>

void calcul_media(float x, float y)

{

float M;

M=(x+y)/2;

cout<<"Media este= "<<M;

}

void main()

{

float a, b;

cout<<"dati nr: "; cin>>a>>b;

calcul_media(a, b);

getch();

}
102.

#include<iostream.h>

int a[20][20], i, j, m, n, L1, L2, temp;

void citire_matrice()

{

cout<<"Dati nr de linii si de coloane: "; cin>>m>>n;

for(i=0; i<=m-1; i++)

 for(j=0; j<=n-1; j++)

 {

 cout<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j];

 }

}

void interschimbare(int i1, int i2)

{

 for(j=1; j<=n; j++)

 {

 temp=a[i1][j];

 a[i1][j]=a[i2][j];

 a[i2][j]=temp;

 }

}

void afisare_matrice(int a[20][20], int m, int n)

{

cout<<endl<<"matricea este: ";

for(i=0; i<=m-1; i++)

{

 for(j=0; j<=n-1; j++)

	cout<<a[i][j]<<" ";

	cout<<endl;

	}

 }

void main()

{

 citire_matrice();

 afisare_matrice(a, m, n);

 do{

 cout<<endl<<"dati liniile care se vor interschimba: "; cin>>L1>>L2;

 }

 while(L1<1 || L1>m || L2<1 || L2>m);

 interschimbare(L1, L2);

 afisare_matrice(a, m, n);

 }
103.

#include<iostream.h>

int a[20][20], m, n, i, j, k, s[80];

void citire_matrice()

{

 cout<<"dati nr de linii si de coloane: "; cin>>m>>n;

 for(i=0; i<=m-1; i++)

	for(j=0; j<=n-1; j++)

	{

	 cout<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j];

	 }

	}

 void formeaza_vector()

 {

 k=0;

 for(i=0; i<=m-1; i++)

 {

 for(j=0; j<=n-1; j++)

	s[k]+=a[i][j];

	k++;

	}

 }

void afisare_vector(int s[80], int k)

{

for(k=0; k<=m-1; k++)

cout<<s[k]<<" ";

}

void main()

{

 citire_matrice();

 formeaza_vector();

 afisare_vector(s, k);

 }

104.
#include<iostream.h>

int v[20], n, i, np, nn, nl;

void citire_vector()

{

cout<<"n="; cin>>n;

for(i=0; i<=n-1; i++)

{

cout<<endl<<"v["<<i<<"]="; cin>>v[i];

}

}

void calculvsafisare(int v[20], int n)

{

np=nn=nl=0;

for(i=0; i<=n-1; i++)

{

 if(v[i]>0)

 np++;

 if(v[i]<0)

 nn++;

 if(nl==0)

 nl++;

 }

cout<<endl<<"nr elem. pozitive: "<<np;

cout<<endl<<"nr elem. neg. : "<<nn;

cout<<endl<<"nr elem. nule: "<<nl;

}

void main()

{

citire_vector();

calculvsafisare(v, n);

}
105.
#include<iostream.h>

#include<conio.h>

float m1, m2, a1, a2, b1, b2;

float calcul_media(float x, float y)

{

return (x+y)/2;

}

void main()

{

cout<<"a1, b1= \n"; cin>>a1>>b1;

m1=calcul_media(a1, b1);

cout<<"a2, b2= \n"; cin>>a2>>b2;

m2=calcul_media(a2, b2);

if(m1>=m1)

 cout<<endl<<"max="<<m1;

 else

	cout<<endl<<"max="<<m2;

	getch();

	}
106.
#include<iostream.h>

long x;

int suma_cifre(long x)

{

int d, s;

d=x; s=0;

do{

 s+=d%10;

 cout<<endl<<s; d/=10;

 }

	while(d!=0);

	return s;

	}

void main()

 {

	cout<<endl<<"dati nr: "; cin>>x;

	cout<<endl<<"suma cifrelor lui: "<<x<<" este "<<suma_cifre(x);

  }
107.
#include<iostream.h>

long x;

int nr_cifre(long x)

{

int d, i, nr=0;

d=x;

do{

 i=d%10;

 if(i%2==0)

	nr++;

 d/=10;


 }

	while(d!=0);

	return nr;

	}

void main()

 {

	cout<<endl<<"dati nr: "; cin>>x;

	cout<<endl<<"nr de cifre pare: este "<<nr_cifre(x);

  }

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.