Thread: problemwith loop

  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,336
    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, 04:28 AM
  2. need help with a loop
    By Darkw1sh in forum C Programming
    Replies: 19
    Last Post: 09-13-2009, 09:46 PM
  3. funny-looking while loop
    By Aisthesis in forum C++ Programming
    Replies: 3
    Last Post: 08-30-2009, 11:54 PM
  4. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 10:21 PM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 09:14 AM