Advertisement
rozman50

Untitled

Dec 3rd, 2018
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. // ursy.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include "pch.h"
  5. #include <iostream>
  6. #include <cmath>
  7. #include <string>
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. string mpolje;
  13. cout << "Vnesi stevila" << endl;
  14. getline(cin, mpolje);
  15. float E = 0;
  16. float Ck = 0;
  17. for (int k = 1; k <= (mpolje.length() - 1); k++) {
  18. Ck = 0;
  19. for (int i = 0; i <= mpolje.length() - k - 1; i++) {
  20. int Si;
  21. int Sik;
  22. if (mpolje[i] == '0') {
  23. Si = -1;
  24. }
  25. else { Si = 1; }
  26.  
  27. if (mpolje[i + k] == '0') {
  28. Sik = -1;
  29. }
  30. else { Sik = 1; }
  31.  
  32.  
  33. Ck = Ck + (Si*Sik);
  34. }E += pow(Ck, 2);
  35. }cout << "Je rezultat " << E << endl;
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement