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

The Archive Base Latest Questions

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

I have to write a C program (for my Discrete Mathematics assignment) that finds

  • 0

I have to write a C program (for my Discrete Mathematics assignment) that finds the number of onto functions from set A (|A| = m) to set B (|B|=n) and to display all those functions. Number of onto functions I calculated using the code:

for(k=0; k<n; k++)
    x = x + pow( -1, k) * combination( n, n - k ) * pow( ( n - k ), m);

Where combination is a function that finds the Number of possible combinations.

For example if A = {1,2,3}, B={a,b,c} then the number of onto functions evaluated from the formula is
3^3 – 3(2^3) + 3 = 6.
One possible solution is f = {(1,a),(2,b),(3,c)} [I know this is a solution].

But my problem is: How to display each and every solution!?
This is just a trivial example. But if m and n values are increased (provided m>=n) then the number of possible onto functions increases exponentially!!
For example if m=7 and n=4 there are 8400 functions!

I can’t think of any method to display each and every function that exists between A and B.

  • 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-15T05:16:44+00:00Added an answer on June 15, 2026 at 5:16 am

    I answered a similar problem sometime ago but m and n were equal m = n.(You must think recursively to solve this), by your comment I think the possible answers are: {(1,a)(2,b)(3,c)}, {(2,a)(3,b)(1,c)}, {(3,a)(1,b)(2,c)}, {(3,a)(2,b)(1,c)}, {(2,a)(1,b)(3,c)} and {(1,a)(3,b)(2,c)} then this is my recipe:

    1. Set 2 arrays with their initial value let’s call them letters and numbers.

      *---*---*---*                          *---*---*---*
      | a | b | c | <---letters.             | 1 | 2 | 3 | <---numbers.
      *---*---*---*                          *---*---*---*
      
    2. Choose one of the arrays to be your pivot, I chose the letters, it will be statical.

      *---*---*---*                          *---*---*---*
      | a | b | c | <---STATIC.              | 1 | 2 | 3 | <---DYNAMIC.
      *---*---*---*                          *---*---*---*
      
    3. Rotate the dynamic array counter-clockwise or clockwise as you wish, you must print the i element of numbers with the i element of letters.

      *---*---*---*               *---*---*---*                 *---*---*---* 
      | 1 | 2 | 3 |   -(Print)->  | 2 | 3 | 1 |    -(Print)->   | 3 | 1 | 2 |
      *---*---*---*               *---*---*---*                 *---*---*---*
      

    So you get at this point: {(1,a)(2,b)(3,c)}, {(2,a)(3,b)(1,c)}, {(3,a)(1,b)(2,c)}, 3 are missing.

    1. Swap the i element with the n element of the dynamic array.

      *---*---*---*                                     *---*---*---*
      | 1 | 2 | 3 |   ---------( Swap (0<->2) )-------> | 3 | 2 | 1 | 
      *---*---*---*                                     *---*---*---*
      
    2. Repeat the step 3.

      *---*---*---*               *---*---*---*                 *---*---*---* 
      | 3 | 2 | 1 |   -(Print)->  | 2 | 1 | 3 |    -(Print)->   | 1 | 3 | 2 |
      *---*---*---*               *---*---*---*                 *---*---*---*
      

    So you get the missed subsets:{(3,a)(2,b)(1,c)}, {(2,a)(1,b)(3,c)} and {(1,a)(3,b)(2,c)}.

    If you have more than 3 example 4. Easy: 1234 (rotate N times where N is the number of variables and print with each movement), swap 1 and 4 -> 4231 (Rotate and Print), swap 2 and 3 -> 4321 (Rotate and Print), swap 4 and 1 –> 1324 (Rotate and Print).

    I hope this helped.

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

Sidebar

Related Questions

I have to write program that gets a number n from the user, and
I have to write a program that finds all of the index values for
I have to write a program to find a rational number that has a
I have a class assignment where I have to write a program that will
This is a homework assignment, I have to write a program that reads a
I have to write a program that finds square root of an integer that
I have to write a program that read from a file that contains the
I have to write a program in which main calls other functions that test
for an assignment I have to write a program that will take in an
I have to write a program using the IAS instruction set that will loop

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.