Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * Solution to homework assignment S
- * Introduction to programming course
- * Faculty of Mathematics and Informatics of Sofia University
- * Winter semester 2021/2022
- *
- * @author Anelia Keranova
- * @idnumber 7MI0600055
- * @task 3
- * @compiler VC
- *
- **/
- #include <iostream>
- using namespace std;
- bool space(char ch) {
- if (ch == ' ' || ch == '\t' || ch == '\0')
- return true;
- return false;
- }
- int strlen(char* str) {
- int counter = 0;
- while (str[counter] != '\0') {
- ++counter;
- }
- return counter;
- }
- int evenWords(char* str) {
- int result = 0;
- int len = strlen(str);
- int counter = 0;
- for (int i = 0; i < len; i++) {
- if (!space(str[i])){
- ++counter;
- }
- else {
- if (counter % 2 == 0) {
- ++result;
- }
- counter = 0;
- }
- }
- return result;
- }
- int main() {
- char arr[] = "this is a string ";
- cout << evenWords(arr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement