Jump to content

Recommended Posts

Posted

113-max dintre mediile aritmetice a doua perechi de nr

114-ordonarea a trei numere

115-(bacalaureat aug.2000, varianta2)

116-(bacalaureat iulie, varianta2)

119-platouri de lungime maxima

113.

#include<iostream.h>

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

void calcul_media(float x, float y, float &m)

{

m=(x+y)/2;

cout<<"media este: "<< m;

}

void main()

{

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

calcul_media(a1, b1, m1);

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

calcul_media(a2, b2, m2);

if(m1>=m2)

cout<<endl<<m1;

else cout<<endl<<m2;

}
114.
#include<iostream.h>

int a, b, c;

void interschimbare(int &x, int &y)

{

int interm;

interm=x;

x=y;

y=interm;

}

void main()

{

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

if(a>b)

interschimbare(a, b);

if(a>c)

interschimbare(a, c);

if(b>c)

interschimbare(b, c);

cout<<endl<<"nr dupa re_aranjare: "<<a<<" "<<b<<" "<<c;

}
115.
#include<iostream.h>

#include<stdio.h>

int  n, v[40];

FILE *f, *g;

void interschimbare(int &x, int &y)

{

int interm;

interm=x;

x=y;

y=interm;

}

void citire()

{

int i;

f=fopen("ceva.txt", "r");

while(!feof(f))

{

fscanf(f, "%d ", &v[i]);

i++;

n=i;

fclose(f);

}

}

void main()

{

int i, j;

citire();

g=fopen("altceva.txt", "w");

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

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

	if(v[i]>v[j])

	interschimbare(v[i], v[j]);

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

 fprintf(g, "%d \n", v[i]);

 fclose(g);

 }
116.
#include<iostream.h>

#include<values.h>

int a[20], b[20], i, nr, M;

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

{

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

{

cout<<"elem de pe pozitia" <<i<<"="; cin>>v[i];

}

}

int de_minim(int v[20], int n)

{

int min=MAXINT;

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

 if(v[i]<min)

 min=v[i];

return min;

}

void main()

{

cout<<"citim vectorul a: \n"; citire(a, 10);

cout<<"citim vectorul a: \n"; citire(b, 8);

M=de_minim(b, 8);

for(nr=0, i=1; i<=10; i++)

 if(a[i]<M)

 nr++;

 cout<<endl<<"nr="<<nr;

 }

119.
#include<iostream.h>

#include<values.h>

int v[25], i, n, L_max;

void citire_vector()

{

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

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

{

 cout<<"elem de pe pozitia"<<i<<"= "; cin>>v[i];

 }

 }

int det_lungime_maxima()

{

int lung, lung_max, p, q;

lung_max=0;

i=1;

while(i<=n)

{p=i;

while(i<=n && v[i+1]==v[i])

 i++;

 q=i;

 lung=q-p+1;

 if(lung>lung_max)

	lung_max=lung;

 i++;

 }

return lung_max;

}

void afisare_platouri()

{

L_max=det_lungime_maxima();

cout<<endl<<"Platourile de lungime maxima au lungimea: "<<L_max;

if(L_max==1)

 cout<<endl<<"nu exista platouri!!!";

else

 {

 i=1;

 while(i<=n)

	if(v[i+L_max-1]==v[i])

	 {

	 cout<<endl<<"platou max. intre poz. "<<i<<" "<<i+L_max-1;

	 i+=L_max;

	 }

	else

	i++;

	}

	}

void main()

{

citire_vector();

afisare_platouri();

}

  • Upvote 1

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.