ProAnswers.org

C program to find Car number - puzzle.

4 students of mathematics were out for a morning work and they notified a car breaking the traffic rules . Nobody could see properly the number of the car which was a 4 digit number . In a police enquary one recalled that the 1st two digits are same . 2nd recalled that last two digit are alike . The 3rd student recalled that the four digit number is a perfect square . You are required to write a program in c to help locating the car number

(The car number is > 1000)

Hi Alokesh,

check this:

#include
#include
#include
int main()
{
int i,num,d1,d2,count=0,tmp;
for(i=1000;i<=9999;i++)
{
num=sqrt(i);
num=num*num;
if(num==i)
{
count++;

        num=num/100;
        d1=num%10;
        d2=num/10;
        if(d1==d2)
        {
            tmp=i;
            d1=tmp%10;
            tmp=tmp/10;
            d2=tmp%10;
            if(d1==d2)
                printf("%d is a car number.

",i);
}

    }
   
}

}

o/p

7744 is a car number.