Home › Forums › C Programming › Welcome C++ › Reply To: Welcome C++
July 31, 2007 at 10:33 am
#3204
S.Thananchayan
Participant
Thats awsome I was thinking about this one.
This is the way I was going-
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <iostream> #include <algorithm> #include <vector> bool IsThis (int x) { return (x=1); } bool IsAnswer (int i) { return (((i%10)==2)&(i/100)==2); } int main () { int mynumbers; int mycount; std::vector<int> myscope; for (int x =100; x<300; x++) myscope.push_back(x); std::vector<int> myvector; for (int i=100; i<300; i++) myvector.push_back(i); mynumbers = (int) count_if (myscope.begin(), myscope.end(), IsThis); std::cout << "myvector contains " << mynumbers << " numbers between 100 and 300.n"; mycount = (int) count_if (myvector.begin(), myvector.end(), IsAnswer); std::cout << "myvector contains " << mycount << " numbers that begin and end with 2.n"; return 0; } |