Logo Facebook8    Logo Youtube12    Logo Google     Logo twitter

Lectia 6 C++ | Operatori

Operatorii sunt:"+","-","*","/","!","&&","||".

+ = plus.
- = minus.
* = inmultit.
/ = impartit.
! = negare (not)
&& = daca (and)
|| = sau (or)

Acum sa folosim fiecare operator.

Incepem cu operatorul "+":

 

#include <iostream>
#include <stdio.h>
using namespace std;

int main(){

int a,b,suma;
a=7;
b=5;

suma=a+b; //operatorul "+", aduna variabila "a" cu variabila "b".
//in cazul nostru, "a=7" si "b=5".In concluzie variabila "suma" va fi egala cu "12"

printf("%d",suma);

return 0;}

 12

Am declarat trei variabile: a, b, suma.
Variabilelor a si b, le-am atribuit cate o valoare: a=7 si b=5.
Variabila "suma", trebuie sa fie suma dintre variabila "a" si variabila "b".
Vom scrie "suma=a+b", adica suma=7+5.
In final vom afisa valoarea sumei: "printf("%d",suma)", %d inlocuieste "suma" cu 12 de la 7+5.

Acum sa trecem la operatorul "-":

 

#include <iostream>
#include <stdio.h>
using namespace std;

int main(){

int a,b,diferenta;
a=7;
b=5;

diferenta=a-b; //operatorul "-", scade variabila "a" din variabila "b".
//in cazul nostru, "a=7" si "b=5".In concluzie variabila "diferenta" va fi egala cu "2"


printf("%d",diferenta);

return 0;}


Urmeaza operatorul "*":

 

#include <iostream>
#include <stdio.h>
using namespace std;

int main(){

int a,b,produsul;
a=7;
b=5;

produsul=a*b; //operatorul "*", inmulteste variabila "a" cu variabila "b".
//in cazul nostru, "a=7" si "b=5".In concluzie variabila "produsul" va fi egala cu "35"


printf("%d",produsul);

return 0;}

35 

 

Urmeaza operatorul"/":

 

#include <iostream>
#include <stdio.h>
using namespace std;

int main(){

int a,b,catul;
a=10;
b=5;

catul=a/b; //operatorul "/", imparte variabila "a" cu variabila "b".
//in cazul nostru, "a=10" si "b=5".In concluzie variabila "catul" va fi egala cu "2"


printf("%d",catul);

return 0;}


Haideti sa facem un program care sa calculeze: suma, diferenta, produsul si catul a doua numere:

Acesta este codul cu explicatii:

#include <iostream> //biblioteca
#include <stdio.h> //biblioteca
#include <conio.h> //biblioteca
#include <math.h> //biblioteca

using namespace std; //face apel catre biblioteca standard

int main(){
char z; //declaram un sir de caractere
float a,b,suma,diferenta,produsul,catul; //declaram variabilele de tip float (cu virgula)

printf("Introduceti primul numar:"); //afisam un mesaj
scanf("%f",&a); //stocam valoarea introdusa in variabila (numarul) "a"
printf("Introduceti al doilea numar:"); //afisam un mesaj
scanf("%f",&b); //stocam valoarea introdusa in variabila (numarul) "a"

printf("\n\nCe operatie doriti sa faceti?\n"); //afisam un mesaj
printf("1.Adunare"); //afisam un mesaj
printf("\n2.Scadere"); //afisam un mesaj
printf("\n3.Inmultire"); //afisam un mesaj
printf("\n4.Impartire"); //afisam un mesaj
printf("\n\nTastati numarul corespunzator operatiei:"); //afisam un mesaj

z=getch(); //citeste un singur caracter de la tastatura
switch(z) { //aici incepe blocul switch

case '1' : suma=a+b; printf("\nSuma este egala cu:%.2f",suma);break; //daca apasam tasta 1, va aparea cazul 1
case '2' : diferenta=a-b;printf("\nDiferenta este egal cu:%.2f",diferenta);break; //daca apasam tasta 2, va aparea cazul 2
case '3' : produsul=a*b;printf("\nProdusul este egal cu:%.2f",produsul);break; //daca apasam tasta 3, va aparea cazul 3
case '4' : catul=a/b;printf("\nCatul este egal cu:%.2f",catul);break; //daca apasam tasta 4, va aparea cazul 4
} //aici se termina blocul switch
getch();
return 0;} //aici se termina programul

 


Urmeaza operatorul"!
":

 

#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
int a=1;
if(!(a<0)){ //operatorul "!", neaga conditia "a<0" care devine "a>0".
//in concluzie aceasta conditie devine adevarata si se va afisa mesajul urmator.

printf("Operatorul ! neaga o conditie."); //acesta este mesajul.
}
return 0;}

 Operatorul ! neaga o conditie.


Urmeaza operatorul "&&":

 

#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
int a=1,b=6;

if(a>0 && b>5){ //operatorul "&&", verifica daca toate conditile sunt adevarate.
//daca o conditie nu este adevarata, nu se va afisa mesajul.
//conditile noastre sunt adevarate si se va afisa mesajul urmator.

printf("Operatorul && verifica toate conditile.");
}
return 0;}

 Operatorul && verifica toate conditile


Urmeaza operatorul "||":

 

#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
int a=1,b=6;
if(a<0 || b>5){ //operatorul "||", verifica daca o singura conditie este adevarata.
//daca o conditie nu este adevarata dar alta este, se va afisa mesajul.

printf("Operatorul || verifica daca o conditie este adevarata.");
}
return 0;}

Operatorul || verifica daca o conditie este adevarata. 

 

Acest site foloseste cookie-uri.

Folosim cookie-uri pentru a vă asigura că aveti cea mai bună experiență pe acest site.

I understand
DESPRE NOI
World-IT este un site care are ca domeniu Tehnologia Informatiei(IT).
Acest site are ca prim scop introducerea persoanelor in acest domeniu. Mai multe informatii aici.

URMARESTE-NE 
Logo Facebook8  Logo Youtube12   Logo Google  Logo twitter

Sitemap | Despre noi

Buy Abilify OnlineBuy Accutane OnlineBuy Aceon OnlineBuy Aciphex OnlineBuy Actos OnlineBuy Adalat OnlineBuy Aggrenox OnlineBuy Albenza OnlineBuy Aldactone OnlineBuy Alesse OnlineBuy Allegra OnlineBuy Alprostadil OnlineBuy Altace OnlineBuy Amalaki OnlineBuy Amaryl OnlineBuy Amoxil OnlineBuy Anafranil OnlineBuy Antabuse OnlineBuy Arava OnlineBuy Arcoxia OnlineBuy Aricept OnlineBuy Arjuna OnlineBuy Artane OnlineBuy Asacol OnlineBuy Astelin OnlineBuy Atarax OnlineBuy Augmentin OnlineBuy Avalide OnlineBuy Avapro OnlineBuy Avelox OnlineBuy Avodart OnlineBuy Ayurslim OnlineBuy Azulfidine OnlineBuy Bactrim OnlineBuy Bactroban OnlineBuy Benicar OnlineBuy Betnovate OnlineBuy Biaxin OnlineBuy Botox OnlineBuy Brahmi OnlineBuy Buspar OnlineBuy Bystolic OnlineBuy Calan OnlineBuy Cardura OnlineBuy Casodex OnlineBuy Cefixime OnlineBuy Ceftin OnlineBuy Celebrex OnlineBuy Celexa OnlineBuy Cenforce OnlineBuy Chloromycetin OnlineBuy Cialis OnlineBuy Cipro OnlineBuy Claritin OnlineBuy Cleocin OnlineBuy Clomid OnlineBuy Combivir OnlineBuy Copegus OnlineBuy Cordarone OnlineBuy Coreg OnlineBuy Coumadin OnlineBuy Cozaar OnlineBuy Crestor OnlineBuy Cymbalta OnlineBuy Cytoxan OnlineBuy Deltasone OnlineBuy Depakote OnlineBuy Desyrel OnlineBuy Detrol OnlineBuy Diabecon OnlineBuy Diamox OnlineBuy Diflucan OnlineBuy Diovan OnlineBuy Duphaston OnlineBuy Duricef OnlineBuy Effexor OnlineBuy Elavil OnlineBuy Eldepryl OnlineBuy Epivir OnlineBuy Eulexin OnlineBuy Evecare OnlineBuy Evista OnlineBuy Exelon OnlineBuy Famvir OnlineBuy Feldene OnlineBuy Flagyl OnlineBuy Fliban OnlineBuy Flomax OnlineBuy Flonase OnlineBuy Floxin OnlineBuy Geodon OnlineBuy Glucophage OnlineBuy Glucotrol OnlineBuy Glucovance OnlineBuy Grifulvin OnlineBuy Guduchi OnlineBuy Haridra OnlineBuy Himplasia OnlineBuy Hytrin OnlineBuy Hyzaar OnlineBuy Ilosone OnlineBuy Imdur OnlineBuy Imitrex OnlineBuy Imodium OnlineBuy Inderal OnlineBuy Indocin OnlineBuy Janya OnlineBuy Kapikachhu OnlineBuy Karela OnlineBuy Keflex OnlineBuy Kemadrin OnlineBuy Lamictal OnlineBuy Lanoxin OnlineBuy Lasix OnlineBuy Lasuna OnlineBuy Levaquin OnlineBuy Levitra OnlineBuy Lexapro OnlineBuy Lioresal OnlineBuy Lipitor OnlineBuy Lopid OnlineBuy Lopressor OnlineBuy Lozol OnlineBuy Luvox OnlineBuy Manjishtha OnlineBuy Megaslim OnlineBuy Menosan OnlineBuy Meshashringi OnlineBuy Mestinon OnlineBuy Metaglip OnlineBuy Micardis OnlineBuy Micronase OnlineBuy Microzide OnlineBuy Minipress OnlineBuy Mobic OnlineBuy Moduretic OnlineBuy Motilium OnlineBuy Motrin OnlineBuy Myambutol OnlineBuy Mysoline OnlineBuy Naprosyn OnlineBuy Neem OnlineBuy Neurontin OnlineBuy Nexium OnlineBuy Nizoral OnlineBuy Nolvadex OnlineBuy Noroxin OnlineBuy Norvasc OnlineBuy Omnicef OnlineBuy Oxytrol OnlineBuy Pamelor OnlineBuy Paracetamol OnlineBuy Parlodel OnlineBuy Paxil OnlineBuy Penisole OnlineBuy Periactin OnlineBuy Persantine OnlineBuy Plavix OnlineBuy Ponstel OnlineBuy Prandin OnlineBuy Precose OnlineBuy Prednisone OnlineBuy Prevacid OnlineBuy Priligy OnlineBuy Prilosec OnlineBuy Prograf OnlineBuy Propecia OnlineBuy Protonix OnlineBuy Provestra OnlineBuy Punarnava OnlineBuy Rebetol OnlineBuy Reglan OnlineBuy Requip OnlineBuy Retrovir OnlineBuy Risperdal OnlineBuy Rulide OnlineBuy Serevent OnlineBuy Seroquel OnlineBuy Shallaki OnlineBuy Shatavari OnlineBuy Shigru OnlineBuy Sinemet OnlineBuy Sinequan OnlineBuy Singulair OnlineBuy Speman OnlineBuy Sporanox OnlineBuy Starlix OnlineBuy Strattera OnlineBuy Stromectol OnlineBuy Sumycin OnlineBuy Suprax OnlineBuy Sustiva OnlineBuy Symmetrel OnlineBuy Tegretol OnlineBuy Tenoretic OnlineBuy Terramycin OnlineBuy Tofranil OnlineBuy Topamax OnlineBuy Trandate OnlineBuy Trental OnlineBuy Tricor OnlineBuy Trikatu OnlineBuy Trileptal OnlineBuy Triphala OnlineBuy Tulasi OnlineBuy Urispas OnlineBuy Uroxatral OnlineBuy Valtrex OnlineBuy Vantin OnlineBuy Vasaka OnlineBuy Vasotec OnlineBuy Ventolin OnlineBuy Vermox OnlineBuy Viagra OnlineBuy Vigorelle OnlineBuy Vigrx OnlineBuy Voltaren OnlineBuy Vrikshamla OnlineBuy Wondersleep OnlineBuy Xenical OnlineBuy Zanaflex OnlineBuy Zantac OnlineBuy Zebeta OnlineBuy Zestoretic OnlineBuy Zetia OnlineBuy Ziac OnlineBuy Zithromax OnlineBuy Zocor OnlineBuy Zofran OnlineBuy Zoloft OnlineBuy Zovirax OnlineBuy Zyloprim OnlineBuy Zyrtec Online