Advertisement
Guest User

Untitled

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