quiz5

#include <iostream>
using namespace std;
bool palindrome(string word){
int c=1;
string invert=string(word.rbegin(), word.rend());
int z=word.size();
for(int i=0; i<z; i=i+1){
if (word[i]==invert[i]) {
return true; }
else {
return false; }
return 0; } }
int main(){
string word;
cout<<“This program calculate if a single word is a palondrome or not”;
cout<<“Give the word to prove if its a palindrome or not”<<endl;
cin>>word;
if(palindrome(word)==false) {
cout<<word<<” “<<“Its NOT palindrome”<<endl; }
else{
cout<<word<<” “<<“It´s a Palindrome”<<endl; }
return 0;
}

CÓDIGO 2.

#include <iostream>
using namespace std;

int threesAdd(int range[], int numOfNum) {
int total=0;
int divi=0;
int val;
for(int i=0; i<numOfNum; i=i+1){
val=range[i];
if(val%3==0){
cout<<val<<” “<<“Is divisible so it goes to the addition”<<endl;
divi=divi+1;
total=total+val;}
else { } }
cout<<“The total divisble numbers:”<<” “<<divi<<” “;
return total; }

int main() {
int values;
cout<<“This program evaluates a range of numbers and make a total addition”<<endl;
cout<<“But it only add the ones which are divisibles by 3″<<endl;
cout<<“How many values you will type?”<<” “;
cin>>values;
int range[values];
for(int i=0; i<values; i=i+1){
cout<<“Type the”<<” “<<i+1<<” “<<“number”<<endl;
cin>>range[i]; }
cout<<“The total addition of the no.3 divisibles is:”<<” “<<threesAdd(range, values)<<endl;
return 0;
}

CC BY-SA 4.0 quiz5 by codemaster2016 is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.