Question:

Program in "C" plz help!!?

by  |  earlier

0 LIKES UnLike

can anyone tell me the program in C for performing set operation like union and intersection or suggest any good wedsite for finding source code of programs in c or any other programing language

 Tags:

   Report

4 ANSWERS


  1. Honestly speaking, for your requirement it does not depend upon the language these days and heavily dependent upon the way you approach a problem. In programming there could be many ways to approach and solve a particular problem.

    In my opinion you can use arrays for storing each element of a set and then you can write separate functions for performing operations on them like union,intersection,etc.  

    Following is a attempted example to create a set of 5 integers.

    #include <iostream.h>

    #include <conio.h>

    int validate(int);

    int a[5];

    main()

    {  

        

          cout<<"SET A";

          for(int i=0;i<=4;i++)

          {        

          cout<<"\nEnter value "<<(i+1)<<":";

          cin>>a[i];

          }

          

          if (validate(5))

          {

             cout<<"\nSET IS NOT VALID!";                

          }

          else

          {

             cout<<"This is a valid set!";

             cout<<"{";

             for (int i=0;i<=4;i++)

             {

             if (i<4)    

               cout<<a[i]<<",";

             else

               cout<<a[i]<<"}";      

             }        

                

          }

          

          

    getch();    

    }

    int validate(int n)

    {

        int common=0;

        for (int i=0;i<=(n-1);i++)

          {

              for(int j=0;j<=(n-1);j++)

              {

                  if (i==j)

                  {

                  continue;

                  }

                  else if (a[i]==a[j])

                  {

                  cout<<"There is a common element";

                  common=1;

                  break;

                  }            

              }

              if (common)

              break;    

          }

        return common;

    }

    This is just an attempt. You can use structures(struct in C++) and classes for creating sets and their respective operations.

    That would be the most appropriate way in my opinion.


  2. i persionally advice u that you should join tution for C.I am sure that you are master in C after join tution.and read the book ANSCI C it"s outher is balagurusame

  3. There are no intrinsic set operations in the C language. There are probably public domain and shareware libraries you could get source to. Try http://www.planet-source-code.com/ and go to the C/C++ section and then to Data Structures.

    Visual Basic, C#, and Java all have this built-in to their extensive libraries.

  4. Cprogramming.com is a web site designed to help you learn the C or C++ programming languages, and provide you with C and C++ programming language resources. The Getting Started with the C++ language  section gives advice about learning C or C++. Learn from C and C++ language tutorials, or test your programming knowledge with our programming quizzes  including the C++ MegaQuiz. If you need help getting set up, check out compilers  page.

Question Stats

Latest activity: earlier.
This question has 4 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions