Thats wonderful!! See how pleasurable it is to find out a solution on your own!! :D
Ok , now for another self discovery. Check the difference between long int and long double.
ok... I know long double but what is long int?? :?:
Thats wonderful!! See how pleasurable it is to find out a solution on your own!! :D
Ok , now for another self discovery. Check the difference between long int and long double.
ok... I know long double but what is long int?? :?:
YES!!! ThankS guys I got it.... Took me 1 day to figure it out now here it goes in the using while loop i need 2 variables... Like you said...
{
long double i,product=1;
cout<<"Enter a Number:"<<endl;
cin>>i;
while(i>=1)
{
product=product*i;
i--;
}
cout<<"The Factor is:"<<product;
getch();
return 0;
}
Now that i got it... Another thing i should ask.... How can i change the output to a whole number instead of giving an exponent?
Ex.
Output:
4.7x10e8....
Ok lets do a dry run to see where you went wrong in the program.
Say num = 5
while num >= 1 ( 5 >=1 , hence true )
num = num * num , num becmes 25.
num = num -1 , num becomes 24again while num > = 1 ( 24 > =1 , hence true )
num = num * num , num becmes 24 squared = 576
num = num - 1 , num = 575 nowand so now , so basically your variable num keeps increasing and the condition while num >= 1 is always true , and thus ur program takes num to infinity or maximum 16bit integer value.
I guess u are looking for something like 5! = 120 right ?
thats 5 x 4 x 3 x 2 x 1 . Hint : thats 5 multiplication , with each number 1 less. try some more, then we are here.
Thanks for teaching me why i got always an infinity as an output.... Let me see... all i have to do is just subtract one from the number you inputed.... and not the solution.... but what id i swap the num-- to --num what will that do??
Hi Demonisya,
The problem I guess is here in while loop.
What exactly do you want your program to do? to find the factors of the entered number or the Factorial of the number??
well the output woud be like this for example....
output
Enter a Number: 3
6....
3*2*1 it multiplies each number that it subtracts from the number you gave....
Hello guys i need help on my program factoring.... i have the progam here but the bad news is it is been giving me -3242 or infinite number as an output... I already been so busy changing any thing but i cant make the output correct the way it should be... please help me where have i gone wrong :?:? Thank you very much....
#include<iostream.h>
#include<conio.h>
main()
{
int num;
cout<<"Enter a Number:"<<endl;
cin>>num;
while (num>=1)
{
num*=num;
num--;
}
cout<<"The Factor is:"<<num<<endl;
getch();
return 0;
}
I have read the bubble sort but may I ask you what does beside of n ( := ) do?? I got this example in wikipedia....
n := length( A )
do
swapped := false
n := n - 1
for each i in 0 to n - 1 inclusive do:
if A[ i ] > A[ i + 1 ] then
swap( A[ i ], A[ i + 1 ] )
swapped := true
end if
end for
while swapped
end procedure
Yeah...it really takes a long time to finish it.... I barely got the half of it.... anyways I got a fair grade of trying.... but sir still didn't gave us the answer... but I will try your advice on swapping the arrays.... but before I ask for your code I'll have to try my best on this one...... you can give me your code and I'll try to study It on my own..... I really appreciate your help.... ^^
What do i have to use in order to obtain the acsending order????
Hello Once Again..... I need you to help me with this program im working. My teacher asked me to create a program that could arrange the random numbers from lowest to highest.... but I can't follow up what's next in my program:
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b[10];
for(a=1,a<=10,a++)
{
printf("Enter Number %d",a);
scanf("%d",&b[a]);
}
for(b=0,b<=a,b--)
{
printf("The Numbers in Descending order:%d\n",b[a])
}
return 0;
Is The 2nd loop correct????
ok thanks i'll rearrange and print it thanks for the advices.... plus my teacher just give us something that we could do without the help of c in the lab... since usually when someone is done they would just open the file and copy it.... Even so when my teacher said delete before he checked it there is still a way for them to cheat so he gave us this.... And it usually is fair to me... then when were done with the paper work he'd let us write our work in c and try to defend it in our own words.... Thanks again... ^^
Problem 2: Write a progam that accepts an integer input representing the total number of seconds and outputs the equivalent time in hours and minutes.
Example Output:
Enter total number of seconds:5400
Equivalent in hours:1.5hr
Equivalent in minutes:90min
Here is my program:
#include<stdio.h>
main()
{
int a;
float b=60.0,c=60.0,d,e;
printf("Enter total number of seconds:");
scanf("%d",&a);
d=a/b; // In Minutes
e=d/c; // In Hours
printf("Equivalent in hours:%f",e);
printf("Equivalent in minutes:%f",d);
}
Is This correct???
O.k My teacher game me a take home exam which will be submitted on monday..... and also I have to defend what I composed so I will ask you many questions so that I will understand this program..... my teacher said Never use C... do it in your own ideas....
Problem 1: Write a program to read in a distance expressed in kilometers and output the distance expressed in miles. One kilometer is equal to 0.62137 miles.
Example Ouput:
Enter Value in Kilometers:4
Value in Mile: 2.48548
Here is my program:
#include<stdio.h>
main()
{
int a;
float b=0.62137,c;
printf("Enter Value in Kilometers:");
scanf("%d",&a);
c=a*b;
printf("Value in miles:%f",c);
getch();
return 0;
}
Is this right???
Try creating your program on your own first as Narue said, post it and we'll help you with the problems later on ok???.....
Sorry it took me a long time to reply because I have other business to attend to and it really got me famished.... By the way thanks a lot I got the problem solved and thanks for the advice and teachings.... I will write another problem next time...
Ok... I've checked my test paper and got the question here it is: Create a program that could give an output of a chrismas tree starting from the first * to the 4th line of *
I counted it....to every line it adds 2 to every next line it goes... I asked my teacher how may loops do I have to make and he gave us a hint 3.... but the problem is when I get to the 2nd and 3rd loop I can't really figure it out.... and that was a written exam so I have to make it without the help of a computer but this was my answer in my test paper....
while(a<16)
{
a=a+2
a++
}
Hello..... I want to ask you something..... My teacher gave us our final exam last October 16 & 17.... I want to ask you about this question: Create a program that could show this output
*
***
****
******
using while or for..... what I put in my answer sheet has only 1 while.... but my teacher told me there would be 3 while's in total how can that be???? Thanks for the help in advance.....:)
Thank you for you wonderfull advises...but i only need a simple program so scientific calculator will have to do and we only have 1 week to finish it so we have to better hurry thank you so much for your kind help....
Hello....everyone I want to ask you for your advice on what problem I'm gonna do.... So my teacher grouped us and make a program that we ourselves would make.... we can do that but what kind of program do we have to make, any suggestions???? My teacher said that the program we will make is interesting to everyone... Just give me the problem and I will talk to my groupmates about the program... Thank you :)
O.K. I got it and does my coding look correct to you???? Narue Sorry..... I'll Try to code these this before I put them in my threads..... and thank you very much twomers I appreaciate your help.....
#include<stdio.h>
#include<conio.h>
main()
{
clrscr ();
int a,c=2;
printf("Write the Number:");
scanf("%d",&a);
//Subtract 2 from any number
while(a>0)
{
a-=c;
printf("\n\n\n %d",a);
}
return 0;
getch;
}
So my answer should be in this form??? Heheheh Sorry if I did it wrong cause I'm still a beginner and I want to learn and willing to hear from you Thanks....
#include<stdio.h>
main()
{
int a;
int c=2;
int d;
printf("Write the Number:");
scanf("%d",&d);
//Subtract d to c
while(a>0)
{
c-=2;
printf("\n %d ",c);
}
printf ( "The Answer is %d\n", a);
return 0;
Hey....Help me in this one please... I have to encode something that the output will come out as example....10, 8, 6, 4, 2, 0..... please help me what I did wrong....Thanks ...and I like to thank Narue too...for helping me in my last problem....I have to do this without using my c said sir :'(
#include<stdio.h>
main()
{
int a[100];
int b=0;
int c=2;
int d;
printf("Write the Number:");
scanf("%d",&d);
//Subtract d to c
while(a>=0)
{
a[b]=d-c;
}
printf ( "The Answer is %d\n", a[b]);
return 0;
}
Thanks! I appreciate your helpful advises.... I'll try it later in my lab class and sure Narue I'll slap my sir for you heheheh......Thanks....^^
Hi!!! This is my first time to post here and I have a problem and I want your help.....
This is the case my teacher gave me a question to add 1 to 100 using while loop and its really confusing me... but here is my idea and I jsut want you to help me What I am missing.... Thanks
#include <stdio.h>
#include<conio.h>
#define p printf
main()
{clrscr();
int a,b,c;
while(a>=1)
{
b=a+c
a=b+c
c++;
}
p("\n The Answer is:")
for(a>=0)
p("%d",a);
getch();
return 0;
}