problemwith loop

This is a discussion on problemwith loop within the C Programming forums, part of the General Programming Boards category; i have problem with the loop. i want to get the result as: but i cannot find what wrong with ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    42

    problemwith loop

    i have problem with the loop. i want to get the result as: but i cannot find what wrong with the code. please help me.
    exp:
    4+3+2+1=10
    3+2+1=6
    2+1=3
    1=1
    Code:
    #include<stdio.h>
    main()
    {
    	int i,j,count,sum;
    printf("input number \n");
    scanf("%d",&count);
    for(i=count;i>=1;i--)
    {
    sum=i;
    printf("\n%d",i);
    j=1;
    while(i>j)
    {	i--;
    	printf("+%d",i);
    	sum+=i;
    	
    }
    printf("=%d",sum);
    
    }
    
    
    
    
    printf("\n");
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If you stop your loop at 2, how do you expect to print 1?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Poll event loop
    By rogster001 in forum C++ Programming
    Replies: 2
    Last Post: 09-17-2009, 05:28 AM
  2. need help with a loop
    By Darkw1sh in forum C Programming
    Replies: 19
    Last Post: 09-13-2009, 10:46 PM
  3. funny-looking while loop
    By Aisthesis in forum C++ Programming
    Replies: 3
    Last Post: 08-31-2009, 12:54 AM
  4. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 11:21 PM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 09:14 AM

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