0% found this document useful (0 votes)
79 views16 pages

Exercitii Pascal Ooooooooooooooo

The document contains C++ code examples demonstrating various programming concepts like loops, conditionals, functions, arrays, and mathematical operations. Example 1 defines functions that check conditions on parameters and output values. Example 2 defines functions that perform maximum, minimum, summation and other operations on integer parameters. Example 3 reverses a number using loops. The remaining examples contain loops, conditionals and other programming elements to solve problems.

Uploaded by

David Detishin
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)
79 views16 pages

Exercitii Pascal Ooooooooooooooo

The document contains C++ code examples demonstrating various programming concepts like loops, conditionals, functions, arrays, and mathematical operations. Example 1 defines functions that check conditions on parameters and output values. Example 2 defines functions that perform maximum, minimum, summation and other operations on integer parameters. Example 3 reverses a number using loops. The remaining examples contain loops, conditionals and other programming elements to solve problems.

Uploaded by

David Detishin
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
You are on page 1/ 16

EX 2

#include <iostream>

using namespace std;

#define parametri int x, int y, int a

void ok1(parametri) {
if ((pow(x, 2) > a) && (pow(y,2) == 4)) { a = 1; }

cout << a << "\n";


}

int sqr(int x) {

return x * x;

void ok2(parametri) {

if ((sqrt(x) > a) || (sqr(y) == 4)) { a = 1; }

cout << a << "\n";

void ok3(parametri) {

if (a == true) { a = 0; }
cout << a << "\n";

void ok4(parametri) {

if (a != true) {
a = 1;
}
else { a = 0; }

cout << a << "\n";

void ok5(parametri) {
if (5 == (5 / 5 + 4)) { a = a; }

cout << a << "\n";

}
int main() {

ok1(9, 4, 2);
ok2(9, 4, 2);
ok3(9, 4, 2);
ok4(9, 4, 2);
ok5(9, 4, 2);

system("pause");
return 0;

}
EX 5
#include <iostream>

using namespace std;

#define parametri int x, int y, int a

int a_max(int a, int b ) {


int x;

if (a > b) { x = a; }
else { x = b; };

cout << x << "\n";


return x;
}

int b_min(int a, int b) {


int x;
if (a > b) { x = b; }
else {x = a;}

cout << x << "\n";


return x;
}

int c_sum() {

int c;

c = a_max(1,3) + b_min(1,3);
cout <<"suma"<< c <<"\n" ;
return c;
}

void d_max(int a, int b) {


int x;
if ((a-b) > b) { x = a; }
else { x = b; };

cout << x << "\n";


}

void e_min(int a, int b) {


int x;
if (a+b > b) { x = b; }
else { x = a; }

cout << x << "\n";

}
void f_max(int a, int b) {
int x;
if (pow(a,2)>pow(b,3)) { x = a; }
else { x = b; };

cout << x << "\n";


}

int main() {

a_max(1, 3);
b_min(1, 3);
c_sum();
d_max(1, 3);
e_min(1, 3);
f_max(1, 3);

system("pause");
return 0;

EX 29
#include <stdio.h>
#include <iostream>
using namespace std;
int main() {
int n, rev = 0, ramas;
printf("Numarul = ");
cin >> n;
while (n != 0) {
ramas = n % 10;
rev = rev * 10 + ramas;
n /= 10;
}
printf("Numarul reversat = %d", rev);
return 0;
}

EX 22
e)
#include <iostream>

#include<math.h>
using namespace std;

int main() {

float suma = 0;

for (float k = 1; k <= 20; k++) {

for (float m = k; m <= 20; m++) {


suma += (8 + k) / m;

cout << suma;

b)

float suma=0;

for(int i=1;i<=30;i++)

for(int j=1;j<=10;j++){

suma+=sin(i*i+j*j*j*j);

cout<<"Exercitiul a) ="<<suma;
}

g)
#include <iostream>

#include<math.h>
using namespace std;

int main() {
float suma = 0;
float x;
cin >> x;
float fact = 1;
float k = 1;
for (int i = 1; i <= 30; i++) {

for (i = 1; i <= k; i++) {


fact = fact * i;
}
k++;

suma += fact / pow(x, i);

cout << suma;


return 0;
}

1 pag 52
#include <iostream>

using namespace std;

int main() {

//1 pag 52

int a[] = { 1,2,3,4,5,6,7,8,9,10 };

cout << a[3]<<"\n" << a[4] << "\n" << a[9];

cout << "\n" << a[3] + a[2] + a[8];

cout << "\n" << a[1] + 5 << "\n" << a[9]+5;

cout << "\n" << a[5] - 10 << "\n" << a[6] - 10;

return 0;
}
3 pag 52
#include <iostream>

#include <iostream>

using namespace std;

int main() {

int numere_negative = 0;
int nr_pare = 0;
int nr_nenule = 0;
int i = 0;
int nr_divizibile=0;
int nr_celputin=0;

/// ////////////////////////
/// int a[10];

int a[10];

for ( i = 0; i < 10; i++) {

cin >> a[i];

}
i = 0;
int n = 10;
for ( i ; i <n-1; i++) {

if (a[i] < 0) { numere_negative++; }

}
cout << numere_negative;
i = 0;
//----------------------------------------
for ( i; i <n; i++)

if (a[i] % 2 == 0) { nr_pare++; }

}
cout << "\n" << nr_pare;
i = 0;
//---------------------------------------------
for (i; i < n; i++) {

if (a[i] != 0) { nr_nenule++; }
}
cout<<"\n"<<nr_nenule;
i = 0;
//----------------------------------
for (i; i < n; i++) {

if (a[i] % 3 == 0 || a[i] % 5 == 0) { nr_divizibile++; }

}
i = 0;
cout << "\n" << nr_divizibile;
//------------------------------------------------
for (i; i < n; i++) {

if (a[i] %7 == 0 || a[i] % 9 == 0 || a[i] % 11 == 0) { nr_celputin++; }

}
i = 0;
cout << "\n" << nr_celputin;

return 0;
}
24 pag 24
#include <stdio.h>
#include <iostream>

using namespace std;


int main() {

int n;
int suma = 1;
cin >> n;
int n1 = n;
for (int i = 1; i <= n; i++) {

suma = suma * n1;


n1--;

cout << suma;

return 0;
}
23 pag 24
#include <stdio.h>
#include <iostream>

using namespace std;


int main() {
char c;
int lowercase_vocala, uppercase_vocala;
printf("Enter an alphabet: ");
cin >> c;

lowercase_vocala = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');

uppercase_vocala = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');

if (lowercase_vocala || uppercase_vocala)
cout << c << " = " << "Este vocala";
else
cout << c << " = " << "Este consoana";
return 0;
}

2 pag 52

#include <stdio.h>
#include <iostream>

using namespace std;


int main() {
int a[]={1,2,3,4,5};
int suma;
int suma1=1;

for(int i=0;i<a[i];i++){
suma=suma+a[i];
suma1=suma1*a[i];
}

cout<<"\n"<<suma;
cout<<"\n"<<suma1;
return 0;
}

9 pag 22
#include <iostream>

using namespace std;

int main(){

int m ,n;

cin>>m>>n;

if((m-n)<0){cout<<"consecutive";}

else{cout<<"nu sunt consecutive";}

return 0;

}
22 unknown page
#include <iostream>

#include<math.h>
using namespace std;

int main() {
float suma = 0;
float x;
cin >> x;
float fact = 1;
float k = 1;
int j;
for (int i = 1; i <= 30; i++) {

for (j = 1; j <= k; j++) {


fact = fact * j;
}
k++;

suma += fact / pow(x, i);

cout << suma;


return 0;
}

4 pag 32
#include <iostream>
using namespace std;
int main() {
int n, i;
unsigned long long fact = 1;
cin >> n;

if (n < 0)
cout << "Numarul este negativ";
else {
for (i = 1; i <= n; ++i) {
fact *= i;
}
cout << "Factorialul numarului dat = " << fact;
}

return 0;
}

Numar perfect uknown page exercise


#include <iostream>

#include <stdio.h>

using namespace std;

int main()

int n;

cin >> n;

int suma = 0;

for (int i = 1; i <= n / 2; i++)

if (n % i == 0)

suma += i;

if (suma == n)
cout << "N este perfect";

return 0;

You might also like