dau si coroana. vreau cat mai multe din problemele din poza rezolvate. pt c++.
daca nu stiti nu raspundeti la intrebare.
merci
Răspunsuri la întrebare
Răspuns:
ex 3 si 4:
#include <iostream>
using namespace std;
int main(){
int i,n,v[100];
cout << "Dati lungimea vectorului:";
cin >> n ;
for (i=1;i<=n;i++){
cout << "V[" << i << "]=";
cin >> v[i];
}
cout << "Vectorul introdus:";
for (i=1;i<=n;i++){
cout << v[i] << " ";
}
cout << endl;
int suma = 0 ;
for (i=1;i<=n;i++){
if (v[i] % 2 == 0){
suma = suma + v[i];
}
}
int suma_imp = 0 ;
for (i=1;i<=n;i++){
if (v[i] % 2 == 1){
suma_imp = suma_imp + v[i];
}
}
cout << "Suma elementelor pare este: " << suma <<endl;
cout << "Suma elementelor impare este: " << suma_imp;
}
ex 6 :
#include <iostream>
using namespace std;
int main(){
int i,n,v[100];
cout << "Dati lungimea vectorului:";
cin >> n ;
for (i=1;i<=n;i++){
cout << "V[" << i << "]=";
cin >> v[i];
}
cout << "Vectorul introdus:";
for (i=1;i<=n;i++){
cout << v[i] << " ";
}
cout << endl;
int suma=0;
for (i=1;i<=n;i++){
if (i % 2 == 0 ){
suma = suma + i;
cout << v[i] << " ";
}
}
cout <<endl;
cout << "Suma elementelor pe pozitii pare este : " << suma ;
}
ex7 :
#include <iostream>
using namespace std;
int main(){
int i,n,v[100];
cout << "Dati lungimea vectorului:";
cin >> n ;
for (i=1;i<=n;i++){
cout << "V[" << i << "]=";
cin >> v[i];
}
cout << "Vectorul introdus:";
for (i=1;i<=n;i++){
cout << v[i] << " ";
}
cout << endl;
int suma=0;
for (i=1;i<=n;i++){
if (v[i] % 3 == 0){
suma = suma + v[i];
cout << v[i] << " ";
}
}
cout << endl;
cout << "Suma numerelor divizible cu 3 : " << suma;
}
ex8 :
#include <iostream>
#include <math.h>
using namespace std;
int main(){
int i,n,v[100];
cout << "Dati lungimea vectorului:";
cin >> n ;
for (i=1;i<=n;i++){
cout << "V[" << i << "]=";
cin >> v[i];
}
cout << "Vectorul introdus:";
for (i=1;i<=n;i++){
cout << v[i] << " ";
}
cout << endl;
int suma=0;
for (i=1;i<=n;i++){
suma = suma + pow(v[i],2);
}
cout << endl;
cout << "Suma patratelor : " << suma;
}
- din poza de jos doar atat am reusit
ex 1 si ex 2#include <iostream>
using namespace std;
int main(){
int i,n,v[100];
cout << "Dati lungimea vectorului:";
cin >> n ;
for (i=1;i<=n;i++){
cout << "V[" << i << "]=";
cin >> v[i];
}
cout << "Vectorul introdus:";
for (i=1;i<=n;i++){
cout << v[i] << " ";
}
cout << endl;
int produs=1;
for (i=1;i<=n;i++){
if (v[i] > 0){
produs = produs * v[i];
}
}
int produs_neg=1;
for (i=1;i<=n;i++){
if (v[i] < 0){
produs_neg = produs_neg * v[i];
}
}
cout << "Produsul elementelor din vector care sunt pozitive: " << produs << endl;
cout << "Produsul elementelor din vector care sunt negative: " << produs_neg;
}
si ex 4:
#include <iostream>
using namespace std;
int main(){
int i,n,v[100];
cout << "Dati lungimea vectorului:";
cin >> n ;
for (i=1;i<=n;i++){
cout << "V[" << i << "]=";
cin >> v[i];
}
cout << "Vectorul introdus:";
for (i=1;i<=n;i++){
cout << v[i] << " ";
}
int produs=1;
for (i=1;i<=n;i++){
if (v[i] % 2 == 1){
produs = produs * v[i];
}
}
cout << endl;
cout << "Produsul elementelor din vector care sunt impare: " << produs;
}
Explicație: