Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <iomanip>
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.     int max =10;int num[max] = {10,9,8,7,6,5,4,3,2,1};
  7.     int odd[5];int even[5];
  8.     int mult=0,add=0,sub=0;int evenCtr=-1,oddCtr=-1;
  9.     long double divide=0;
  10.     for(int x = 0; x<max; x++){
  11.         if(num[x]%2>0){
  12.             oddCtr+=1;
  13.             odd[oddCtr]=num[x];
  14.         }
  15.         else{
  16.             evenCtr+=1;
  17.             even[evenCtr]=num[x];
  18.         }
  19.         add+=num[x];
  20.         sub-=num[x];
  21.         if(x==0){
  22.             divide=num[x];
  23.             mult=num[x];
  24.         }
  25.         else{
  26.             divide/=num[x];
  27.             mult*=num[x];
  28.         }        
  29.     }
  30.     cout<<"Even Numbers: ";
  31.     for(int z = 0; z<=evenCtr;z++){
  32.             cout<<even[z];
  33.             if(z!=evenCtr){
  34.                 cout<<",";
  35.             }
  36.     }
  37.     cout<<"\n";cout<<"Odd Numbers: ";
  38.     for(int y = 0; y<=oddCtr;y++){
  39.             cout<<odd[y];
  40.             if(y!=oddCtr){
  41.                 cout<<",";
  42.             }
  43.     }
  44.     cout<<"\n"<<"Array computation";
  45.     cout<<"\n"<<"Multiplication: "<<mult;
  46.     cout<<"\n"<<"Division: "<<setprecision(30)<<fixed<<divide;
  47.     cout<<"\n"<<"Subtraction: "<<add;
  48.     cout<<"\n"<<"Addition: "<<sub;
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement