some problems relating loops and functions

please please help me i am a beginner to C am having a lot of problems

Posted 07 November 2008 - 10:40 PM

Q1:Write a for loop that prints the integers 1 through 40, separated by spaces or new lines. You may use only one variable, count which has already been declared as an integer.

for(count=1;count<=40;count++)printf("1",40 );

the error is where i have written 1 and 40 in the printf parenthesis what should come there instead??i am confused,please help me.

Q2:Assume that the int variables i and j have been declared, and that n has been declared and initialized.

Write code that causes a "triangle" of asterisks of size n to be output to the screen. Specifically, n lines should be printed out, the first consisting of a single asterisk, the second consisting of two asterisks, the third consistings of three, etc. The last line should consist of n asterisks. Thus, for example, if n has value 3, the output of your code should be
*
**
***
You should not output any space characters.

for(int i=1;i<=n;i++)
{
for(int j=0;j<i;j++)
{
printf("*");
}
}

can you tell me the error in this?please.

Q3:Assume the int variables i , lo , hi , and result have been declared and that lo and hi have been initialized.

Write a for loop that adds the integers between lo and hi (inclusive), and stores the result in result .

Your code should not change the values of lo and hi . Also, do not declare any additional variables -- use only i , lo , hi , and result .

result=0;for(i=0){result=lo+hi}

caan you tell me the error in this one??

Q4: Write the definition of a function powerTo , which receives two parameters. The first is a double and the second is an int . The function returns a double .

If the second parameter is negative, the function returns 0. Otherwise it returns the value of the first parameter raised to the power of the second.

Q5:Write the definition of a function dashedLine , with one parameter, an int .

If the parameter is negative or zero, the function does nothing. Otherwise it prints a complete line terminated by a new line character to standard output consisting of dashes (hyphens) with the parameter's value determining the number of dashes. The function returns nothing.

Q6:Given that two int variables, total and amount , have been declared, write a sequence of statements that:
initializes total to 0
reads three values into amount , one at a time.

After each value is read in to amount , it is added to the value in total (that is, total is incremented by the value in amount ).

total = 0;
amount=intx;int y;int z;
total=total + amount;

can you tell me the error in this one???

please i am realy trying my best and i have done all of my questions besides these,these are really creating trouble i have tried my best and i have pasted my codes here,please kindly give me suggestions on how to fix them.thank you so much.