Advertisement
ItsMeLucifer

Funkcja zad3 c++

May 14th, 2019
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8. void ciag(int *w, int elementy) {
  9.     int ciag=0,ile=0;
  10.     for (int i = 0; i < elementy - 1; i++) {
  11.         if (w[i] - w[i + 1] < 0) {
  12.             ciag -= 1;
  13.         }else if (w[i] - w[i + 1] > 0) {
  14.             ciag += 1;
  15.         }
  16.         if (i == 0 && w[i] % 2 == 0 && w[i] > 10 && w[i] % 3 == 0) {
  17.             ile++;
  18.         }
  19.         if (i>0 && w[i + 1] % 2 == 0 && w[i + 1] > 10 && w[i + 1] % 3 == 0) {
  20.             ile++;
  21.         }
  22.     }
  23.     if (abs(ciag) == elementy-1 && ciag<0) {
  24.         printf("Ciag jest: rosnacy\n");
  25.     }
  26.     else if (abs(ciag) == elementy-1 && ciag > 0) {
  27.         printf("Ciag jest: malejacy\n");
  28.     }
  29.     else {
  30.         printf("Ciag nie jest ani rosnący ani malejacy\n");
  31.     }
  32.     cout << "Suma pierwszego i ostatniego elementu: " << w[0] + w[elementy - 1] << "\n";
  33.     cout<<"Liczba elementow parzystych, dwucyfrowych i podzielnych przez 3: "<<ile<<endl;
  34. }
  35. int main() {
  36.     int ile=10;
  37.     int tablica[] = {2,5,7,19,27,40,42,53,60,64};
  38.     int *wskaznik = tablica;
  39.     ciag(wskaznik,ile);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement