please check out the attachment,
I've written an program for finding two variables but it doesn't works
Also I've inserted an picture of the terminal showing the output for this program.
Friends.. I'm waiting for your replies ....
please check out the attachment,
I've written an program for finding two variables but it doesn't works
Also I've inserted an picture of the terminal showing the output for this program.
Friends.. I'm waiting for your replies ....
I think you should start a and b with 1, because anything multiplying with 0 returns 0. So the condition is getting true each time.
BTW remember initializing those variables with 1 will never make your condition true, so you won't get any output.
As I understand you want to find a,b for:
(a+b)^2 = a^2 + b^2
This is only possible if a=0 ( any value of b) or b=0 ( any value of a )
Am I missing anything?
If its worth fighting for its worth dying for!!!
http://shankhs4u.blogspot.com
Registered Ubuntu User #2611
Registered Linux User #484419
Actually, a*a + 2*a*b + b*b = (a+b) * (a+b)
in ur case, the condition is satified only when b == 0 . hence the output.
change the formula and things will be fine.
Darshan
Never upgrade your working system to the newest release without thorough testing on the actual hardware you will be running it on.
Never perform a system update in a live session
Installed Ubuntu Touch 1.0 on my Nexus 7. And loving it!
@krishnandu.sarkar you are true,
but Friends, somebody told me that, there are really two numbers, and those are non-zero.
so i thought, to make a program to search it.
look at the output carefully, you will get noticed that, only one variable is getting incremented while both should get incremented..
like..
for a=0, b should increment from 0 to 999,
again, for a=1, b from 0-999, and so on upto a becomes 999.
please help.
(a+b)^2 = a^2+b^2
=>a^2+b^2+2ab=a^2+b^2
=>2ab=0
So either a=0 or b=0
If its worth fighting for its worth dying for!!!
http://shankhs4u.blogspot.com
Registered Ubuntu User #2611
Registered Linux User #484419
@ shankhs,
(a+b)^2 = a^2+b^2
is not possible,
actually, the correct formula is :
(a+b)^2 = a^2+b^2 + 2*a*b
Do you want this thing??
#include<stdio.h>
main()
{
// A PROGRAM TO FIND a AND b IF (a*a)+(2*a*b)+(b*b) = (a*a)+(b*b)
int i;
int a=0, b=0;
int x, y;
for(i=0;i<1000;i++)
{
x=(a*a)+(2*a*b)+(b*b);
y=(a*a)+(b*b);
if(x==y)
{
printf("\na=%d\tb=%d",a,b);
a++;
b++;
}
}
if(a==999 && b==999)
printf("\nElements not found!");
}
Bookmarks