Home Forums C Programming Welcome C++ Reply To: Welcome C++

#3204
S.Thananchayan
Participant

Thats awsome I was thinking about this one.
This is the way I was going-
 

#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;
}
  • This reply was modified 7 years, 6 months ago by M. Saqib.
  • This reply was modified 2 years, 9 months ago by M. Saqib.
  • This reply was modified 2 years, 9 months ago by M. Saqib.