Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ursy.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include "pch.h"
- #include <iostream>
- #include <cmath>
- #include <string>
- using namespace std;
- int main()
- {
- string mpolje;
- cout << "Vnesi stevila" << endl;
- getline(cin, mpolje);
- float E = 0;
- float Ck = 0;
- for (int k = 1; k <= (mpolje.length() - 1); k++) {
- Ck = 0;
- for (int i = 0; i <= mpolje.length() - k - 1; i++) {
- int Si;
- int Sik;
- if (mpolje[i] == '0') {
- Si = -1;
- }
- else { Si = 1; }
- if (mpolje[i + k] == '0') {
- Sik = -1;
- }
- else { Sik = 1; }
- Ck = Ck + (Si*Sik);
- }E += pow(Ck, 2);
- }cout << "Je rezultat " << E << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement