PDA

View Full Version : Help on C programming


nodeffect
09-14-2003, 04:38 PM
Hi I need help here.....

does anyone knows how to make a program that ask you to enter a number......

if the use enter 5 it should print

*****
*****
*****
*****
*****

if enter 4

than it will be

****
****
****
****

anyone can help me out ??? Using C

if possible, can I make a hole in the center ??? please help, thanks ;)

Arbitus
09-14-2003, 05:09 PM
well I dont know much c, but there similar so try this,


int number;
std::cout << "Enter number: ";
std::cin >> number;
if (number==5)
{
std::cout << "*****
*****
*****
*****
*****";
if (number==4)
{
std::cout << "****
****
****
****";
}


thats just the body. try it tho.

nodeffect
09-14-2003, 06:27 PM
I mean, for all numbers between 1 to 20 not only number 5 and 4........and I think it should use a while loop.......but I can;t get it........please help......

thanks anyway ;)

Josh Campbell
09-15-2003, 02:39 AM
just use two for loops like

for(y = 0; y < num; y++)
{
for(x = 0; x < num; x++)
printf("*");
printf("\n");
}

pretty simple.

Jason
09-15-2003, 08:52 PM
don't forget to declare x, y before you use the for loops or declare them inside the loops....eg: int x = 0 ....


Jason

nodeffect
09-18-2003, 08:23 AM
Thanks for the help guys.....;)

nodeffect
09-18-2003, 11:44 AM
sorry guys, now I have another question about C.

How do I make a program that can convert from decimal to binary, octal and hex numbers ??? please help....;)

Josh Campbell
09-18-2003, 03:46 PM
You can use the %x and %o format specifiers in printf to display a number as a hexadecimal or octal. There is no format specifier for binary, and i dont remember how to do it.

Jason
09-18-2003, 07:55 PM
probably you would want to do it with an array. And since binary starts on the right and counts left you might set a counter to the array.length. So everytime you add one, set array.length to 1 and if its 1 already set it to 0 and decriment the counter and add 1 to that position. You would want that in a loop to go through all possibilities...just an idea.


Jason

Mhtml
09-20-2003, 07:00 AM
Originally posted by Jason
don't forget to declare x, y before you use the for loops or declare them inside the loops....eg: int x = 0 ....


Jason

Why not just go for(int x = 0; and for(int y = 0 ?? Saves heaps of time and space if you write a lot of loops using different variables. But if you were using the same variable again and again you should do it normally.

krycek
09-21-2003, 05:01 AM
Originally posted by Mhtml
Why not just go for(int x = 0; and for(int y = 0 ?? Saves heaps of time and space if you write a lot of loops using different variables. But if you were using the same variable again and again you should do it normally.

isn't that what he said? :confused:

Originally posted by Jason
....or declare them inside the loops....eg: int x = 0 ....

::] krycek [::

Mhtml
09-21-2003, 08:32 AM
Originally posted by krycek
isn't that what he said? :confused:



::] krycek [::

:| I didn't even see that there before. :confused:

Jason
09-22-2003, 06:51 PM
its my super secret language and hidden writting :thumbsup:


Jason

Mhtml
09-22-2003, 07:01 PM
Originally posted by Jason
its my super secret language and hidden writting :thumbsup:


Jason
lol :thumbsup:

nodeffect
09-27-2003, 04:24 AM
Guys, I have another problem....

Can you explain to me what is hypotenuse ???

They ask me to write a function hypotenuse that calculates the length of the hypotenuse of a right triangle when the other two sides are given.

krycek
09-27-2003, 02:50 PM
Originally posted by Mhtml
:| I didn't even see that there before. :confused:

...you quoted it though!!! :p

::] krycek [::

krycek
09-27-2003, 02:54 PM
Originally posted by nodeffect
Guys, I have another problem....

Can you explain to me what is hypotenuse ???

They ask me to write a function hypotenuse that calculates the length of the hypotenuse of a right triangle when the other two sides are given.

Part of the rules of these forums is that we do not help people with homework.

Anyway, what you are asking is very basic geometry, which you should surely know by now.

Even so, I'll give you a pointer.

Pythagorus' Theorum is used to calculate the hypotenuse.

a^2 + b^2 = c^2

^2 means "raise to power of 2", or "square". Usually the 2 will be superscripted and not feature the ^

That's as much help as I will give, although you should know that already!

::] krycek [::

Josh Campbell
09-27-2003, 06:13 PM
Could've searched it yourself (third result on google for 'hypotenuse') instead of wasting time asking on a forum?

Mhtml
09-30-2003, 09:11 AM
Looks like someone listens in school ;) .. .

Could say the same for you Krycek :p " Pythagorus' " hehe, pythagoras' :)

Should you decide to come back and ask for more help, I thought I'd tell you how to raise a number to a power in C without your own function or using lots of * .

long result = pow(long num, long exp)

where num is the number (suprise :p) and exp is, you guessed it, (ok maybe you didn't) the exponential (or power for the less educated, or little number at the top for the even lesser educated).

nodeffect
10-02-2003, 05:37 PM
hey guys, really thanks man.........;) you all helped me a lot