Created
December 4, 2015 17:35
-
-
Save iamandrewluca/d45054e0462bbb91df55 to your computer and use it in GitHub Desktop.
Suma radacinilor patrate a elementelor impare
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
int main() { | |
int dimensiuneMasiv; | |
int *masiv; | |
int suma = 0; | |
std::cout << "Dati numarul de elemente in masiv: "; | |
std::cin >> dimensiuneMasiv; | |
std::cout << "Dati elementele masivului:" << std::endl; | |
masiv = new int[dimensiuneMasiv]; | |
for (int i = 0; i < dimensiuneMasiv; ++i) { | |
std::cin >> masiv[i]; | |
} | |
for (int j = 0; j < dimensiuneMasiv; ++j) { | |
// daca numarul curent e par atunci facem pas acestui ciclu | |
// avem nevoie de numere impare doar | |
if (masiv[j] % 2 == 0) continue; | |
// radical din N = N la puterea 1/2 | |
float radacinaPatrata = powf(masiv[j], 1.0/2.0); | |
suma += radacinaPatrata; | |
} | |
std::cout << "Suma radacinilor patrate a elementelor impare este " << suma; | |
delete[] masiv; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment