Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7168293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:45:04+00:00 2026-05-28T14:45:04+00:00

For a given integer, n , I need to print all the lists of

  • 0

For a given integer, n, I need to print all the lists of length 3 which sum to n. The members of the list must be non-negative integers. After printing all these lists, it must then print the number of lists that were found.

For example, if n=2:

  • 1+0+1 = 2
  • 1+1+0 = 2
  • 0+1+1 = 2
  • 2+0+0 = 2
  • 0+0+2 = 2
  • 0+2+0 = 2

Here is the program I did for lists of length 2 rather than lists of length 3:

#include <stdio.h>
int main (void)
{
    int total;
    int c1=0;
    int c2=0;
    int c3=0;
    int count;

    printf("Welcome friends and mainly enemies to the thingy. Only postive intergers!!!\n That's right just enter a number here:");
    scanf ("%d",&total);
    printf ("\n\n\nWhy pick %d? Here is the list if combinations anyway,",total);

    for (count=0;count<=total;count++)
    {
        printf ("\n");
        for (c1=count;c1==count;c1--)
        {
            printf("%d ",c1);

        }
        for (c2=total-count;c2<=total-count;c2++)
        {
            printf("%d",c2);

        }

    }
    printf ("\n\nThere are %d number combinations that total %d",count,total);

}

The goal is to extend this from lists of length two to lists of length 3.

Additional Info:
I can only use one other variable c3.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:45:05+00:00Added an answer on May 28, 2026 at 2:45 pm

    Hope this helps:

    int c3 = 0;
    for (int c1 = 0; c1 <= total; c1++) {       
        for (int c2 = total - c1; c2 >= 0; c2--){
            printf("%d %d %d \n", c1, c2, total - c1 - c2);
            c3++;
        }
    
    }
    
    printf("there are %d ways to sum to %d", c3, total);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to pad the output of an integer to a given length. For
Given an integer array, i need to find which number occurred most number of
I've got a System.Generic.Collections.List(Of MyCustomClass) type object. Given integer varaibles pagesize and pagenumber, how
You are given a 32-bit unsigned integer array with length up to 2 32
Given an undirected graph, I want to generate all subgraphs which are trees of
Given an arbitrary input string I'm meant to find the sum of all numbers
Given an integer typedef: typedef unsigned int TYPE; or typedef unsigned long TYPE; I
Given an unsorted integer array, and without making any assumptions on the numbers in
Given a distance (50km) as integer: 50 And a time as string in the
Given a potentially huge integer value (in C# string format), I want to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.