1 Replies - 16461 Views - Last Post: 07 November 2008 - 11:20 PM Rate Topic: -----

#1 ayesha1989  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 07-November 08

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

Post icon  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.

double powerTo (double x,int y)
{
   if(y<= 0.0)
return 0;
else
return (x^y);
}

can you tell me the error in this one?

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.

void dashedLine (int)
{
int x;
if (x==0 || x<0)
return 0;
else 
printf("\n");
return;
}

can you tell me the error in this one?

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.

Is This A Good Question/Topic? 0
  • +

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

#2 kummu4help  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 245
  • Joined: 05-August 08

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

Posted 07 November 2008 - 11:20 PM

hi,
i am trying to help without a compiler at present. so pls don't mine if any syntactical errors that may occur :rolleyes:
the 1st one should look like this.
for(int count=1;count<=40;count++)
{
	printf("\n%d",count );
}


*edit*
the 2nd one should some thing look like this
for(int i=1;i<=n;i++)
		{
				for(int j=0;j<i;j++)
				{
						printf("*");
				}
				printf("\n");//print a new line character
			 
		}



the 3rd may look like this
result=0;
for(i=lo;i<=hi;i++)
{
	 result=result+i;
}
printf("%d",result);



the 6th one may look like this
int total=0;
int amount=0;
int count=0;
while(count<3)
{
   printf("enter value for amount variable:\n");
   scanf("%d",&amount);
   total=total+amount;
}
printf("\ntotal amount is : %d",total);




hope it helps to you
*edit*

This post has been edited by kummu4help: 07 November 2008 - 11:36 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1