Thread: Please help me with this simple code. newbie here.

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    56

    Please help me with this simple code. newbie here.

    Yes this is hw and i have done 47 out of 50 of the problems. I have just gotten stuck on these last 3. if anyone is in the mood to help. please do. I am willing to take pointers as well to help me get along thx.

    1. Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a while loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j.
    i have no idea where to begin

    2. Given int variables k and total that have already been declared, use a while loop to compute the sum of the squares of the first 50 whole numbers, and store this value in total. Thus your code should put 1*1 + 2*2 + 3*3 +... + 49*49 + 50*50 into total. Use no variables other than k and total.

    i tried this but didnt work?

    .
    Code:
    while(k<=50){
    total=total+k^2;
    k=k+1;

    and 3. Given an int variable k that has already been declared, use a do...while loop to print a single line consisting of 97 asterisks. Use no variables other than k.

    i tried

    Code:
    do {
       printf("*");
    } while (k<98);

    thanks so much you guys are great.
    Last edited by stehigs321; 09-29-2003 at 07:50 PM.

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    115
    lol

    what were your previous 47 questions? Learning how to write helloworld in 47 different languages?

    If you have done those 47 then this should be a catwalk.
    Code:
    1. if n =1, j=5;
    
    while(n<j)
    printf('*');
    
    2. you cant do k^2
    total=0;
    k=1;
    while(k<=50){
    total=total+k*k;
    k++;
    }
    there are only 10 people in the world, those who know binary and those who dont

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    56

    the first one doesnt work?

    The first answer u gave me was wrong.
    it has to print as many stars as the number the user enters.

    And i still need help with the 3rd one

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    61
    >And i still need help with the 3rd one
    Code:
    k=0;
    do {
      printf("*");
      k++;
    } while(k<97);
    $ENV: FreeBSD, gcc, emacs

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird error in this simple code! C2248!
    By gross100 in forum C++ Programming
    Replies: 2
    Last Post: 12-10-2005, 01:31 AM
  2. Replies: 14
    Last Post: 11-23-2005, 08:53 AM
  3. Replies: 18
    Last Post: 11-04-2005, 02:41 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM