Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 14
- #include <iostream>
- #include <limits.h>
- ///14. Adott egy egész számokat tartalmazó sorozat. Szúrjuk be a sorozat
- ///legkisebb eleme elé a pozitív számok összegét.
- using namespace std;
- int main()
- {
- int a[50],n,k,min=INT_MAX,o=0;
- cout<<"N ";cin>>n;
- for(int i=1;i<=n;i++)cin>>a[i];
- for(int i=1;i<=n;i++){
- if(a[i]%2==0)o=o+a[i];
- if(a[i]<min) min=a[i];}
- for(int i=1;i<=n;i++)
- if(a[i]==min) k=i;
- for(int i=n;i>=k;i--) a[i+1]=a[i];
- a[k]=o;
- n++;
- for(int i=1;i<=n;i++) cout<<a[i]<<" ";
- return 0;
- }
- +++++++++++++++++++++++++++++
- 5
- //Szúrjuk be egy n elemű egész sorozat minden páratlan értékű eleme után az illető szám ellentettjét.
- #include <iostream>
- using namespace std;
- int main()
- {
- int n,a[50];
- cout << "n=" << endl;
- cin>>n;
- for(int i=1; i<=n; i++)
- cin>>a[i];
- int i=1;
- while(i<=n)
- {
- if(a[i]%2!=0)
- {
- ///beszuras i+1 poz
- for(int j=n;j>=i+1;j--)
- a[j+1]=a[j];
- a[i+1]=-a[i];
- n++;
- i=i+2;
- }
- else i++;
- }
- for(int i=1;i<=n;i++)
- cout<<a[i]<<" " ;
- return 0;
- }
- +++++++++++
Advertisement
Add Comment
Please, Sign In to add comment