Hii I have developed a code in which i have two check those 2 digit numbers whose 3 times sum is equal to the number
eg:-27=3(2+7)

#include<conio.h>
#include<stdio.h>
int main()
{
clrscr();
int a,b,n;
long sum=0;
loop:for(n=24;n<=28;n++)
{
 a=n/10;
 b=n%10;
 sum=sum+(a+b);

 }
 if(n==(3*sum))
 {
 printf("%d \n",n);
 }
 else
    {
    goto loop;

 }

    getch();
    return 0;
    }

However i am only getting a blank screen with a cursor
can anyone explain

You've got the logic wrong.

In your code, your for loop does not do any checking of the numbers. It just creates a big value for sum. Then your if statement checks that one big sum value against 28, and then goes back to loop: because whatever that big sum value is, it is not 3*(2+8)

Your if statement should be inside the for loop so that you check each value of n. Also, you need to reset the value of sum to zero every time you go round that for loop.

And you don't need the goto loop. Always try to avoid using goto. You can use do- while in you code, but i think you don't need it anyway.

You've got the logic wrong.

In your code, your for loop does not do any checking of the numbers. It just creates a big value for sum. Then your if statement checks that one big sum value against 28, and then goes back to loop: because whatever that big sum value is, it is not 3*(2+8)

Your if statement should be inside the for loop so that you check each value of n. Also, you need to reset the value of sum to zero every time you go round that for loop.

Thank you it worked ...Ya i should place the if code inside the for loop....

#include<stdio.h>

void main(){

int num, sum, temp1, temp2, i;

for(num=10;num<100;num++)
{

temp1 = num/10;
temp2 = num%10;


if( num == 3 * (temp1 + temp2))
{

printf("hurry !!! found it %d \n", num);
}
}

return 0;
}

try this mate :P

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.