@ quzah: I see u are equally dumb as me....U always temme clicking arround google and wiki but u urself refrain to click a link beside "2". Did u realise i'm not behind "Magic Square"....click the link find out...!!!
@ all others: It WAS NOT my homework....i "REALLY" wanted different approaches solving those problems!!!
I said, "If at all it’s my homework even then how does it bother you anyway if you do it on my behalf and help an ignorant kid to save his ass rather than "mis"-interpreting and translating my statements???"
I meant, is not it waste of time to dissect whether it was someone's homework or something rather than posting some codes. quzah was so very sure that it was my homework so i said, thinking it to be my homework only, let him post his logic!!!
CommonTater:
Because you won't learn a darned thing from the "gifted code", but you'll pass your course and then one of us will get stuck with you asking us to cover your butt in the workplace later on... And I for one would absolutly not want you in my workgroup.
Don't you think C has become outdated for real-world development in the current scenario?? I will not say there are none but hardly there are organisations who develop using C. Everyone is running behind .NET and Java these days. And about my programming skills, I know what I can do and I know I will be hired without anyone covering my butt!!
So, to all u nerds....here is my logic..........
Code:
//krishnamurthy
#include <stdio.h>
int fact(int);
int main()
{
int u,l,t,s,i;
printf("Enter lower limit : ");
scanf("%d",&l);
printf("Enter upper limit : ");
scanf("%d",&u);
for(i=l;i<=u;i++)
{
t=i;
s=0;
while(t!=0)
{
s=s+fact(t%10);
t=t/10;
}
if(s==i)
printf("%d ",i);
}
}
int fact(int n)
{
return n==0?1:n*fact(n-1);
}
Code:
//Armstrong
#include <stdio.h>
#include <math.h>
int main(void)
{
int l,u,i,t,d,s;
printf("Enter lower limit : ");
scanf("%d",&l);
printf("Enter upper limit : ");
scanf("%d",&u);
for(i=l;i<=u;i++)
{
t=i;
d=0;
while(t!=0)
{
d++;
t/=10;
}
t=i;
s=0;
while(t!=0)
{
s+=(int)pow(t%10,d);
t/=10;
}
if(i==s)
printf("%d ",i);
}
}
I'm still working on the "Magic No." algorithm....its taking hell lot of time and its buggy too......look forward to post it soon.
From you nerds, I would like some better and optimized logic than those I posted