Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- int numberOfDigits;
- cout<<"Izberete duljina na masiva: ";
- cin>>numberOfDigits;
- int array[100];
- int chetniChisla = 0;
- int sbor = 0;
- int broiNulevi = 0;
- for(int i = 0; i < numberOfDigits; i++)
- {
- int k;
- cin>>k;
- while(k>=30)
- {
- cout<<"Chisloto trqbva da e < 30"<<endl;
- cin>>k;
- }
- if(k==0) broiNulevi ++;
- else sbor += k;
- array[i] = k;
- }
- int newArray[100];
- int sumNaPolojitelni = 0;
- int broqch = 0;
- for(int i = 0; i < numberOfDigits; i++)
- {
- if(array[i]!=0)
- {
- newArray[broqch] = array[i];
- sumNaPolojitelni += array[i];
- broqch++;
- }
- }
- cout<<"originalen masiv ";
- for(int i = 0; i < numberOfDigits; i++)
- {
- cout<<array[i]<<" ";
- }
- cout<<endl;
- int max;
- int maxIndex;
- for(int i = 0; i < numberOfDigits; i++)
- {
- if(array[i]%2==0){
- max = array[0];
- if(array[i]>max){
- max = array[i];
- maxIndex = i;
- }
- }
- else{
- max = 0;
- }
- cout<<array[i]<<" ";
- }
- cout<<endl;
- cout<<"Sumata na chislata razlichni ot 0 e: "<<sbor;
- cout<<endl;
- cout<<"broq na nulevite elementi e: "<<broiNulevi<<endl;
- cout<<endl;
- cout<<"Maksimalnoto polojitelno chislo "<<max<<" na index "<<maxIndex<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment