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 9228237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:16:24+00:00 2026-06-18T05:16:24+00:00

I have this program that is trying to determine how many unique items are

  • 0

I have this program that is trying to determine how many unique items are within some intersecting sets. The amount of input entirely depends on the the first value n, and then the amount of sets entered afterward. For example, if I start with entering n = 2, I am expected to enter 2 integers. The program then determines how many intersections there are between n items (this is like choosing 2 items from n items). This goes on as k increments. But that’s kind of beyond the point. Just some background info.

My program adapts correctly and accepts the proper amount of input, but it stops working properly before the first for loop that is outside of the while loop. What I have tried to do is make a vector of integer vectors and then add every other row (when index starts at 0 AND index starts at 1). But I am guessing I have constructed my vectors incorrectly. Does anybody see an error in my vector logic?

#include <iostream>
#include <vector>

using namespace std;

int fact (int m) {
        if (m <= 1)
        return 1;
    return m * fact(m - 1);
}

int comb (int n, int k) {
    return fact(n)/(fact(n-k)*fact(k));
}

int main() {
    int n = 0;
    int k = 2;
    int sum = 0;
    int diff = 0;
    int final = 0;

    vector <vector <int> > arr;
    cin >> n;
    while (n > 0) {
        vector <int> row;
        int u;
        for (int i = 0; i < n ; ++i) {
            cin >> u;
            row.push_back(u);
        }
        arr.push_back(row);
        n = comb(row.size(), k);
        k++;
    }
    for (int i = 0; i < arr.size(); i+2)
        for (int j = 0; j < arr[i].size(); ++j)
            sum += arr[i][j];

    for (int i = 1; i < arr.size(); i+2)
        for (int j = 0; j < arr[i].size(); ++j)
            diff += arr[i][j];

    final = sum - diff;
    cout << final;
    return 0;
}
  • 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-06-18T05:16:25+00:00Added an answer on June 18, 2026 at 5:16 am
    for (int i = 0; i < arr.size(); i+=2)
                                      ^
    

    You want to do i+=2 or i=i+2, else the value of i is never changed, leading to an infinite loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this program that should execute a piece of code base on the
I have this program that I am working on for class, I think the
I have this simple program that computes salaries for four different worker types. It's
I have a C/ncurses program that I'm debugging/maintaining. This program does ripoffline twice: first,
I have made a program that scans rss feeds. This same program creates feeds
I have a program that looks something like this: public partial class It {
I have a program that looks like this. I need to consistently write something
I have a real world program that is similar to this one, which I'll
I have a program that simulates mouse click. Code is something like this: [DllImport(user32.dll,
I have a program that generates a .shp file, and exports this as a

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.