Name: Anonymous 2011-12-20 13:26
i want to write a program in C++ that shows which digit has the figure we want in a given number.
for example: user enters 456813 and wants to know where 6 is. program prints "6 is in the third digit." or something like that it doesn't matter. my not-good-looking was:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int x;
cout << "enter 5 digit number : " ;
cin >> x;
int a;
cout<<"enter the figure you want to search: ";
cin>>a;
int y = x;
for(int i = 1;i < 6;i++)
{
for (int j = 1; j < 6;j++)
{
x= x / 10;
if(x % 10 == a)
cout <<"(from end) " << j+1 << " . digit has" <<a<< endl;
}
}
if(y % 10 == a)
cout <<"(from end).digit has" <<a<< endl;
return 0;
}
for example: user enters 456813 and wants to know where 6 is. program prints "6 is in the third digit." or something like that it doesn't matter. my not-good-looking was:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int x;
cout << "enter 5 digit number : " ;
cin >> x;
int a;
cout<<"enter the figure you want to search: ";
cin>>a;
int y = x;
for(int i = 1;i < 6;i++)
{
for (int j = 1; j < 6;j++)
{
x= x / 10;
if(x % 10 == a)
cout <<"(from end) " << j+1 << " . digit has" <<a<< endl;
}
}
if(y % 10 == a)
cout <<"(from end).digit has" <<a<< endl;
return 0;
}