Skip to content

Instantly share code, notes, and snippets.

@samir96
Created Apr 24, 2015
Embed
What would you like to do?
#include <iostream>
#include <vector>
using namespace std;
int findThrees(vector<int>list){
int modulo;
int suma=0;
int num=0;
do{
modulo=list[num]%3;
if(modulo==0){
suma=list[num]+suma;
}
num++;
} while(num< list.size());
return suma;
}
int main() {
vector<int>list;
int tam;
int num;
cout<<"Dame una lista de numeros y solo sumare los numeros que sean divisibles entre 3."<<endl;
cout<<"Dame la cantidad de datos que tendra tu lista: ";
cin>>tam;
for (int n=0; n<tam; n++){
cout<<"Dame un numero: ";
cin>>num;
list.push_back(num);
}
cout<<"La suma es: "<<findThrees(list)<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment