Hi ..

        for(int i=1;i<=n;i++) 
        { 
                first=i%10; 
last=i/10;

.......
i want to see how many number that first number equal last number;
like 3003..and 1,2,3... is counted because its a single numbers
but my statmant it is just count the num unti 100 and its not count the single numbers ..
I think the wrong in value of last ..i wamnted count unt the number that user inter
last =??
Thank you :)

you can try: if first = last or if last = 0 then counter ++

its didn't work
i try this :(

int first;
int last;
int counter =0;
for(int i=1;i<=n;i++){
last = i % 10;

for(first = i; first / 10 > 10; first = first / 10);

if (last == first) counter++;
}
for(int i=1;i<=n;i++) 

        { 

                first=i%10;
                if(first==last && last==first) 
                { 
                        counter++;

look just last the error
i try to put
last=0
last++;
but its failled

First of all line 7 first==last and last==first is the same thing you dont need to compare it twice, secondly to calculate last the easier way should be using a for loop
ie

// keep divide the number by 10 until it reaches the right most digit.
//ie 12345 / 10 = 1234, 1234 /10 = 123, 123 /10 = 12, 12/ 10 = 1 and you get last = 1
for (last = i ; last / 10 > 10; last = last/10)

Yes, I understand last
But what value should be - first -

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.