0% found this document useful (0 votes)
7 views2 pages

Structuri Repetitive în C++

The document contains 3 coding problems involving repetitive structures in C++. The first problem asks the user to input two numbers and an operator, and performs the corresponding operation on the numbers. The second problem calculates the sum of two numbers if the first is less than the second, and the difference if the first is greater. The third problem determines the largest of three numbers input by the user.

Uploaded by

Raluca Voina
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Structuri Repetitive în C++

The document contains 3 coding problems involving repetitive structures in C++. The first problem asks the user to input two numbers and an operator, and performs the corresponding operation on the numbers. The second problem calculates the sum of two numbers if the first is less than the second, and the difference if the first is greater. The third problem determines the largest of three numbers input by the user.

Uploaded by

Raluca Voina
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Voina Raluca

Clasa a 7-a A

STRUCTURI REPETITIVE

PROBLEMA 1

Se dau doua numere naturale a si b. Sa se introduca unul dintre caracterele: +, -, *, iar, in fuctie de
caracterul introdus, sa se efectueze operatia corespunzatoare. In cazul in care caracterul introdus nu este unul
din cele trei mentionate, sa se afiseze mesajul "Operatie necunoscuta".

#include <iostream>
using namespace std;
int main()
{
int a,b;
char c;
cout<<"Introduceti primul numar: a=";
cin>>a;
cout<<"Introduceti al doilea numar: b=";
cin>>b;
cout<<"Introduceti caracterul: c=";
cin>>c;
switch (c)
{
case '+': cout<<a+b;break;
case '-': cout<<a-b;break;
case '*': cout<<a*b;break;
default: cout<<"Operatie necunoscuta";
}
}

PROBLEMA 2

Se dau 2 numere naturale a si b. Sa se calculeze suma dintre a si b daca a<b si diferenta dintre a si b
daca a>b.

#include <iostream>
using namespace std;
int main()
{
int a,b,s,d;
cout<<"Introduceti primul numar: a=";
cin>>a;
cout<<"Introduceti al doilea numar: b=";
cin>>b;
if (a<b)
{
s=a+b;
Voina Raluca
Clasa a 7-a A
cout<<"s="<<s;
}
else
{
d=a-b;
cout<<"d="<<d;
}
return 0;
}

PROBLEMA 3

Sa se determine cel mai mare numar natural dintre 3 numere citite de la tastatura.

#include <iostream>
using namespace std;
int main()
{
int a,b,c,maxim;
cout<<"Introduceti primul numar: a=";
cin>>a;
cout<<"Introduceti al doilea numar: b=";
cin>>b;
cout<<"Introduceti al treilea numar: c=";
cin>>c;
if (a>=b && a>=c)
maxim=a;
if (b>=a && b>=c)
maxim=b;
if (c>=b && c>=a)
maxim=c;
cout<<"Cel mai mare numar este: "<<maxim;
return 0;
}

You might also like