To solve the following problem on numbers we use the C code
Problem:
A 3-digit number such that the sum of three digits is equal to the cube of middle digit. find that number?
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,f,g;
clrscr();
//let us consider a for loop from 100 to 1000 because its a 3-digit number
for(a=100;a<1000;a++)
{
b=a%10;//last digit will comes i.e.,, if xyz is 3-digit number then z will comes
c=a/10;;//first 2 digits will comes i.e.,, if xyz is 3-digit number then xy will comes
d=c%10;//by doing this we get middle digit ie,, y
e=a/100;//we get first digit i.e,, x
//caluclate sum
f=b+d+e;
//caluclate cube of middle digit
g=d*d*d;
if(f==g)
{
printf("The answer for the problem is=%d",a);
}
}
}
Problem:
A 3-digit number such that the sum of three digits is equal to the cube of middle digit. find that number?
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,f,g;
clrscr();
//let us consider a for loop from 100 to 1000 because its a 3-digit number
for(a=100;a<1000;a++)
{
b=a%10;//last digit will comes i.e.,, if xyz is 3-digit number then z will comes
c=a/10;;//first 2 digits will comes i.e.,, if xyz is 3-digit number then xy will comes
d=c%10;//by doing this we get middle digit ie,, y
e=a/100;//we get first digit i.e,, x
//caluclate sum
f=b+d+e;
//caluclate cube of middle digit
g=d*d*d;
if(f==g)
{
printf("The answer for the problem is=%d",a);
}
}
}
No comments:
Post a Comment