Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define n 10
- using namespace std;
- int main()
- {
- float a[n], b[n], c[n], sum=0, min=32767.0, tymczasowy, *pa, *pb, *pc;
- int i, j, n1, n2, k=0;
- pa = &a[0];
- pb = &b[0];
- pc = &c[0];
- cout << "Введіть розмірність масиву від 0" << endl;
- cin >> n1;
- for (i=0; i<=n1; i++)
- {
- cout << "Введіть "<<i<<" елемент масиву" << endl;
- cin >> *(pa+i);
- }
- //пошук кількости від'ємних значень
- for (i=0; i<=n1; i++)
- {
- if (*(pa+i)<0)
- k++;
- }
- cout <<"Кількість від'ємних елементів у масиві "<< k << endl;
- //розрахунок абсолютної величини
- for (i=0; i<=n1; i++)
- {
- if (*(pa+i)<0)
- *(pb+i)=*(pa+i)*-1;
- else
- *(pb+i)=*(pa+i);
- }
- //пошук мінімальної абсолютної величини
- for (i=0; i<=n1; i++)
- {
- if (*(pb+i)<min)
- {
- min=*(pb+i);
- n2=i+1;
- }
- }
- //сума після мінімальної абсолютної величини
- for (i=n2; i<=n1; i++)
- {
- sum = sum+*(pb+i);
- }
- cout <<"Сума абсолютних величин після мінімального абсолютної величини "<< sum << endl;
- //підготовка до третього завдання
- for (i=0; i<=n1; i++)
- {
- if (*(pa+i)<0)
- *(pc+i)=*(pb+i)**(pb+i);
- else
- *(pc+i)=*(pb+i);
- }
- //сортування бульбашкою
- for (j=0; j<=n1-1; j++)
- {
- for (i=0; i<=n1-1; i++)
- {
- if (*(pc+i)>*(pc+i+1))
- {
- tymczasowy=*(pc+i);
- *(pc+i)=*(pc+i+1);
- *(pc+i+1)=tymczasowy;
- }
- }
- }
- //вивід масиву
- for (i=0; i<=n1; i++)
- {
- cout << "Елемент масиву "<<i<<" = "<<*(pc+i)<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement