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

Threaded View

Previous Post Previous Post   Next Post Next Post
  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.

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