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

#3203
[email protected]
Participant

How to count all the three digit number tht lie between 100 to 300 and whose 1st & last digit is 2?
Ans:

#include <iostream>
using namespace std;
void display()
{
 int count = 0;
 for(int i = 100;i<300;i++)
 {
  int value = i;
  if(((value%10)== 2) &&(value/100)==2)
  {
   cout<<value<<endl;
   count++;
  }
 }
 cout<<"Total Number "<<count<<endl;
}
void main()
{
 display();
}

output:
202
212
222
232
242
252
262
272
282
292
Total Number 10
  • 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.
  • This reply was modified 2 years, 9 months ago by M. Saqib.