Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main()
- {
- cout<<"1 : read and print array a[10]\n";
- int a[10],i;
- for(i=0;i<=9;i++)
- {
- cout<<"["<<i<<"]";
- cin>>a[i];
- }
- for(i=0;i<=9;i++)
- {
- cout<<a[i]<<"\t";
- }
- cout<<"\n---------------------------------------\n";
- cout<<"2 : Ask user to give number now tell user whether that number is present in array or not\n";
- int x,k=0;
- cout<<"\nGive a number : ";cin>>x;
- for(i=0;i<=9;i++)
- {
- if(x==a[i])
- {
- cout<<"The number is in array Ok\n";
- k++;
- }
- }
- if(k==0)
- cout<<"Not found \n";
- cout<<"\n---------------------------------------\n";
- cout<<"3 : read 20 int inputs from user \n";
- int b[20];
- for(i=0;i<=19;i++)
- {
- cout<<"["<<i<<"]";
- cin>>b[i];
- }
- int p=0,n=0,o=0,e=0,r=0;
- for(i=0;i<20;i++)
- {
- if(b[i]>0)
- {p++;
- }
- if(b[i]<0)
- {n++;
- }
- if(b[i]%2==1)
- {o++;
- }
- if(b[i]%2==0)
- {e++;
- }
- if(b[i]==0)
- {r++;
- }
- }
- cout<<"The positive number : "<<p<<endl;
- cout<<"The negative number : "<<n<<endl;
- cout<<"The odd number : "<<o<<endl;
- cout<<"The even number : "<<e<<endl;
- cout<<"The 0 number : "<<r<<endl;
- cout<<"\n---------------------------------------\n";
- cout<<"4 : Read array and copy all the elements in another array but in reverse order \n";
- int s[10],y[10];
- for(i=0;i<10;i++)
- {
- cout<<"["<<i<<"]";
- cin>>s[i];
- }
- for(i=0;i<10;i++)
- {
- y[i]=s[i];
- }
- for(i=9;i>=0;i--)
- {
- cout<<y[i]<<"\t";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment