This message was edited by chenfeng7 at 2007-2-9 6:50:24
This message was edited by chenfeng7 at 2007-2-9 5:58:47
This message was edited by chenfeng7 at 2007-2-9 5:43:17
This message was edited by chenfeng7 at 2007-2-9 5:36:55
This message was edited by chenfeng7 at 2007-2-9 5:36:9
:
: : #include<stdio.h>
: : #include<conio.h>
: :
: : void main ()
: : {
: : clrscr();
: : float a=1;int p;float b;
: : printf("Enter the value as format(power,base):");
: : scanf("%f,%d",&b,&p);
: : for (;p!=0;p--)
: : a*=b;
: : printf("\nAnswer=%g",a);
: : getch();
: : }
: :
:
If it runs and gives the correct result - then it is fine.
:
**********************************************************************
I think it will not give the correct result (or am I the one who is mistaken?). Based from my understanding, the programmer wants to solve for
base raised to power. The above code, however, computes for
power raised to base.
If I am right, the "red" in the ff code snippet must be changed to "green":
/* solution 1 */
scanf("%f,%d",&b,&p);
scanf("%d,%f",&p,&b);
/* or solution 2 */
printf("Enter the value as format(power,base):");
printf("Enter the value as format(base,power):");
/* Note: Either you do solution 1 or solution 2. Do not do them both. */
Correct me if I am wrong (grammatical errors too) but I think there is a
logic error in this program. One more thing, variable declarations should come before any other statement. In other words, do this:
float a=1; int p; float b;
clrscr();
instead of this one:
clrscr();
float a=1; int p; float b;
Hope that helps.
#7