Haval1

Homework 3

May 13th, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     cout<<"1 : read and print array a[10]\n";
  6.     int a[10],i;
  7.     for(i=0;i<=9;i++)
  8.     {
  9.         cout<<"["<<i<<"]";
  10.         cin>>a[i];
  11.     }
  12.     for(i=0;i<=9;i++)
  13.     {
  14.         cout<<a[i]<<"\t";
  15.     }
  16.     cout<<"\n---------------------------------------\n";
  17.     cout<<"2 : Ask user to give number now tell user whether that number is present in array or not\n";
  18.     int x,k=0;
  19.     cout<<"\nGive a number : ";cin>>x;
  20.     for(i=0;i<=9;i++)
  21.     {
  22.         if(x==a[i])
  23.         {
  24.             cout<<"The number is in array Ok\n";
  25.             k++;
  26.         }
  27.     }
  28.     if(k==0)
  29.     cout<<"Not found \n";
  30.     cout<<"\n---------------------------------------\n";
  31.     cout<<"3 : read 20 int inputs from user \n";
  32.     int b[20];
  33.     for(i=0;i<=19;i++)
  34.     {
  35.         cout<<"["<<i<<"]";
  36.         cin>>b[i];
  37.     }
  38.     int p=0,n=0,o=0,e=0,r=0;
  39.     for(i=0;i<20;i++)
  40.     {
  41.         if(b[i]>0)
  42.         {p++;
  43.         }
  44.         if(b[i]<0)
  45.         {n++;
  46.         }  
  47.         if(b[i]%2==1)
  48.         {o++;
  49.         }
  50.         if(b[i]%2==0)
  51.         {e++;
  52.         }  
  53.         if(b[i]==0)
  54.         {r++;
  55.         }  
  56.     }
  57.     cout<<"The positive number : "<<p<<endl;
  58.     cout<<"The negative number : "<<n<<endl;
  59.     cout<<"The odd number : "<<o<<endl;
  60.     cout<<"The even number : "<<e<<endl;
  61.     cout<<"The 0 number : "<<r<<endl;
  62.     cout<<"\n---------------------------------------\n";
  63.     cout<<"4 : Read array and copy all the elements in another array but in reverse order \n";
  64.     int s[10],y[10];
  65.     for(i=0;i<10;i++)
  66.     {
  67.         cout<<"["<<i<<"]";
  68.         cin>>s[i];
  69.     }
  70.     for(i=0;i<10;i++)
  71.     {
  72.         y[i]=s[i];
  73.     }
  74.     for(i=9;i>=0;i--)
  75.     {
  76.         cout<<y[i]<<"\t";
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment