Jump to content

Problema c++


undercover44
 Share

Recommended Posts

Salut, ma poate ajuta si pe mine cu o sursa .cpp pentru in program care sa contina functia interval?

 

Mai exact trebuie sa aleg doua capete de interval A si B (ex: 10 si 20) si sa imi afiseze numerele care sunt intre capetele respective

Link to comment
Share on other sites

@@undercover44

#include <iostream>
using namespace std;
void interval (int a, int b)
{	if (a>b) ///verific daca am citit capetele intervalului corespunzator (tratez cazul in care limita din stanga este mai mare decat cea din dreapta
             ///exemplu: daca citesc a=10 si b=2, imi creez intervalul [2,10].
	{int aux;
	aux=a;
	a=b;
	b=aux;
	}
	int i;
	for (i=a;i<=b;i++) ///afisez fiecare numar dintre a si b folosind o structura repetitiva
		cout<<i<<" ";
}
int main()
{int a,b;
cout<<"Dati a:";
cin>>a;
cout<<"Dati b:";
cin>>b;
interval(a,b); ///apelul functiei
return 0;
}

Edited by CR3ATIVe
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • 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.