Help solving a question

This is a discussion on Help solving a question within the C Programming forums, part of the General Programming Boards category; Hi all, my professor gave me some questions to solve and i cant even understand what the questions wants although ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    90

    Help solving a question

    Hi all,
    my professor gave me some questions to solve and i cant even understand what the questions wants although it looks very simple, if anyone can help me i will be grateful,

    here are the questions:

    1-Write a program that estimates the of integer numbers 1 to N,your program should read the integer number N and be sure N>5.

    2-Write a program to read number n using keyboard where n must be >2.Then program display the multiplication table n rows, n columns and table's entity is i x j.where i=1,2,...n,
    j=1,2,...n.
    Display each table in a new horizontal line.


    thanks.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What are you stuck on? For the second, you'll need a pair of loops. For the first, you don't really need to estimate, because there's a formula to calculate that.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    90
    can u tell me what the loops are ?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    A loop is a method of repeating a block of code for a controlled number of times. There are three easy ways to do this:
    Code:
    for( initializer; condition; increment )
    {
        ...stuff to do...
    }
    Example:
    Code:
    int x;
    for( x = 0; x < 5; x++ )
    {
        ...stuff to do...
    }
    This says, start x at zero, and while x is less than five, increment x once at the end of each loop pass. There is also:
    Code:
    while( condition )
    {
        ...do stuff...
    }
    And:
    Code:
    do
    {
        ...do stuff...
    } while( condition );
    The difference here is that the condition may evaluate false, on the first one, at the first check, and the loop may not execute, whereas with a do-while, the loop is guaranteed to execute at least once before it checks the condition.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by everyone0 View Post
    Hi all,
    my professor gave me some questions to solve and i cant even understand what the questions wants although it looks very simple, if anyone can help me i will be grateful,

    here are the questions:

    1-Write a program that estimates the of integer numbers 1 to N,your program should read the integer number N and be sure N>5.

    2-Write a program to read number n using keyboard where n must be >2.Then program display the multiplication table n rows, n columns and table's entity is i x j.where i=1,2,...n,
    j=1,2,...n.
    Display each table in a new horizontal line.


    thanks.

    Don't worry, I don't understand the question either. That's because it makes no sense at all.

    Did your professor give it to you like this? If so, he should be banned from every teaching again. Did you translate it? Then do a better job translating it. Did you write it in your own words? Then, damn, you have no idea what you're typing .

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    My guess is that "estimates" is really "sums". As for the second one, that's pretty clear.


    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    435
    Code:
    /* ESTIMATES the sum of integer 1 through n :) */
    int SumOneTo(int n)
    {
    	return n/2 + n/2 * n+2;
    }
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  8. #8
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by NeonBlack View Post
    Code:
    /* ESTIMATES the sum of integer 1 through n :) */
    int SumOneTo(int n)
    {
    	return n/2 + n/2 * n+2;
    }
    Isn't it actually (n*(n+1))/2 ?
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    That's why it's an estimate.

  10. #10
    Registered User
    Join Date
    Apr 2010
    Posts
    90
    thanks guys appreciate ur help and no i didnt translate it , the professor gave it to me like this lol

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question about a question
    By hausburn in forum C++ Programming
    Replies: 3
    Last Post: 04-25-2010, 05:24 AM
  2. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  3. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21