evgeni_tsn

Untitled

Dec 4th, 2015
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int numberOfDigits;
  9.     cout<<"Izberete duljina na masiva: ";
  10.     cin>>numberOfDigits;
  11.    
  12.     int array[100];
  13.    
  14.     int chetniChisla = 0;
  15.     int sbor = 0;
  16.     int broiNulevi = 0;
  17.    
  18.    
  19.     for(int i = 0; i < numberOfDigits; i++)
  20.     {
  21.         int k;
  22.         cin>>k;
  23.         while(k>=30)
  24.         {
  25.             cout<<"Chisloto trqbva da e < 30"<<endl;
  26.             cin>>k;
  27.         }
  28.         if(k==0) broiNulevi ++;
  29.         else sbor += k;
  30.         array[i] = k;
  31.     }
  32.    
  33.     int newArray[100];
  34.     int sumNaPolojitelni = 0;
  35.     int broqch = 0;
  36.     for(int i = 0; i < numberOfDigits; i++)
  37.     {
  38.         if(array[i]!=0)
  39.         {
  40.             newArray[broqch] = array[i];
  41.             sumNaPolojitelni += array[i];
  42.             broqch++;
  43.         }
  44.     }
  45.    
  46.     cout<<"originalen masiv ";
  47.     for(int i = 0; i < numberOfDigits; i++)
  48.     {
  49.         cout<<array[i]<<" ";
  50.     }
  51.     cout<<endl;
  52.     int max;
  53.     int maxIndex;
  54.     for(int i = 0; i < numberOfDigits; i++)
  55.     {
  56.         if(array[i]%2==0){
  57.             max = array[0];
  58.             if(array[i]>max){
  59.                 max = array[i];
  60.                 maxIndex = i;
  61.             }
  62.         }
  63.         else{
  64.             max = 0;
  65.         }
  66.         cout<<array[i]<<" ";
  67.     }
  68.  
  69.     cout<<endl;
  70.     cout<<"Sumata na chislata razlichni ot 0 e: "<<sbor;
  71.     cout<<endl;
  72.     cout<<"broq na nulevite elementi e: "<<broiNulevi<<endl;
  73.     cout<<endl;
  74.     cout<<"Maksimalnoto polojitelno chislo "<<max<<" na index "<<maxIndex<<endl;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment