C Program to find the two sets Intersection and Union

Write a C Program to find the two sets Intersection and Union
A Set is a collection of well defined and distinct objects.
Intersection of two sets A and B is defined as, all the elements of set A, which are also elements of set B.Union of two sets A and B is defined as, all the elements of A and B, but not belonged to both.
Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<stdio.h>
#include<conio.h>
void Union(int set1[10],int set2[10],int m,int n);
void Intersection(int set1[10],int set2[10],int m,int n);
void main()
{
int a[10],b[10],m,n,i,j;
int ch;
clrscr();
printf("nEnter the number of elements in first set:n");
scanf("%d",&m);
printf("nEnter the elements:n");
for(i=0;i<m;i++)
{
scanf("%d",&a[i]);
}
printf("nElement of First set:nn");
for(i=0;i<m;i++)
{
printf("%dt",a[i]);
}
printf("nEnter the number of elements in second set:n");
scanf("%d",&n);
printf("nEnter the elements:n");
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
}
printf("nElement of second setn");
for(i=0;i<n;i++)
{
printf("%dt",b[i]);
}
for(;;)
{
printf("nnMenunn1.Unionn2.Intersection");
printf("n3.exit");
printf("nEnter your choice:n");
scanf("%d",&ch);
switch(ch) {
case 1:
Union(a,b,m,n);
break;
case 2:
Intersection(a,b,m,n);
break;
case 3:
exit(0);
}
getch();
}
}

void Union(int a[10],int b[10],int m,int n)
{
int c[20],i,j,k=0,flag=0;
for(i=0;i<m;i++)
{
c[k]=a[i];
k++;
}
for(i=0;i<n;i++)
{
flag=0;
for(j=0;j<m;j++)
{
if(b[i]==c[j])
{
flag=1;
break;
}
}
if(flag==0)
{
c[k]=b[i];
k++;
}
}
printf("nElement of resultant setnn");
for(i=0;i<k;i++)
{
printf("t%d",c[i]);
}
}
void Intersection(int a[10],int b[10],int m,int n)
{
int c[20],i,j,k=0,flag=0;
for(i=0;i<m;i++)
{
flag=0;
for(j=0;j<n;j++)
{
if(a[i]==b[j])
{
flag=1;
break;
}
}
if(flag==1)
{
c[k]=a[i];
k++;
}
}
if(k==0)
{
printf("nnResultant set is null set!n");
}else{
printf("nElement of resultant setn");
for(i=0;i<k;i++)
{
printf("t%d",c[i]);
}
}
}


Read more Similar C Programs
Learn C Programming

Number System

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C Program to add one to digits of a number

Write C Program to add one to digits of a number.
C Program that adds the 1 to each single digit of a number, i.e for Example 12345’s output is 23456.
If the digit is 9 it adds 1 and follows the carry system, 9 becomes 0 and 9’s left digit adds one more 1. I.e., 3491’s output is 4602. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                      Happy Coding
***********************************************************/

#include<stdio.h>
#include<conio.h>
int main()
{
 int num, sum = 0;
 int rem, check = 0;
 clrscr( );
 printf("Enter the required number:");
 scanf("%d",&num);
 printf("nGiven Number: %d",num);
 while(num>0) 
 {
  rem = num % 10;
  if(rem != 9)
  {
   if(check == 0) 
    sum = (10 * sum) + (rem + 1);
   else{
    sum = (10*sum) + (rem + 2);
    check = 0;
   }
  } 
  else{
   sum = (10 * sum) + 0;
   check = 1;
  }
  num = num/10;
 } 

 num = sum; sum=0;
 while(num > 0)
 {
  rem = num % 10;
  sum = (10*sum) + rem;
  num = num / 10;
 }
 printf("nAfter Adding one: %d",sum);
 getch( );
 return 0;
}
Read more Similar C Programs
Learn C Programming
Number System

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now, our page!

Share this program with your Facebook friends now! by liking it

Like to get updates right inside your feed reader? Grab our feed!
(c) www.c-program-example.com

C program to implement bit flipping.

Write a C program to implement bit flipping.
C Program to setbits(x,p,n,y) that returns x with the n bits that begin at position p set to the rightmost n bits of y, leaving the other bits unchanged in the least number of lines.
Bit flipping or flip bit is the complement(~) of bits. i.e., 0 to 1 and vise versa. bit flipping is the bits manipulation or processing individual bits within a byte. Bit flipping is used in the very low-level programming and is often used in graphics and systems programming.Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include <stdio.h>
#include <math.h>
#include <limits.h>

unsigned setbits(unsigned x, unsigned p, unsigned n, unsigned y) {
x |= (y & ~(~0 << n)) << p;
size_t s = (int)(log(INT_MAX)/log(2)) + 1;
printf("nnnSuccess! Number after bit flipping: n", s);
int mask = pow(2.0, (int)s);
do {
((x & mask) == 0) ? printf("0") : printf("1");
((s%4)==0) ? printf(" ") : printf("");
x <<= 1;
} while (s--);
printf("n");
}


void main( ) {
unsigned retrn=1, begin=0, nbits=0, num=0;

printf("Enter the number to bit flip!n");
scanf("%d",&num);
printf("Enter the number of bits to be flip!n");
scanf("%d",&nbits);
printf("Enter the position to begin bit flip!n");
scanf("%d",&begin);
unsigned x = setbits(retrn, begin, nbits, num);

}
Read more Similar C Programs
C Basic
C Search Algorithms
K and R C Programs Exercise

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C Program to print factors of the number.

Write a C Program to print factors of a number. Factors of a whole number are the whole numbers which are exactly divides the number. i.e reminder is equal to zero.
Example: Factors of 8 are: 1, 2, 4, and 8.
Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<stdio.h>
#include<conio.h>
{
void main( )
{
int num,x;
clrscr( );
printf("Enter the required number:");
scanf("%d",&num);
printf("nThe factors are:");
for(x=1; x<=num; x++)
{
if(num%x==0)
printf("n%d",x);
}
getch( );
}
Read more Similar C Programs
C Basic
C Search Algorithms
K and R C Programs Exercise

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C program to print Fibonacci numbers using Recursion

C Program to print Fibonacci numbers. In this program we used the Recursion method. Recursion is the programming technique that a process invoking itself again and again. Fibonacci numbers are sequence of numbers starts from 0 and 1 , continue by adding previous number. 0,1,1,2,3,5,8,13,…….. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<stdio.h>
#include<conio.h>
int fib(int);
int f=1,fib1=0,fib2=0,i=0,j;
void main()
{
int num;
clrscr();
printf(" How many Fibonacci numbers do you want?n");
scanf("%d",&num);
printf("nFibonacci Numbers are:n");
f=0;
printf("n%dn",f);
f=1;
printf("n%dn",f);
for(j=0;j<num-2;j++)
{
f=fib(num);
printf("n%dn",f);
}
getch();
}
int fib(int n)
{

while(i<n)
{
if(i<=n)
{
i++;
fib1=fib2;
fib2=f;
f=fib2+fib1;
fib(1);
return f;
}
}

}


Read more Similar C Programs
Learn C Programming
Recursion
Number System

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to demonstrate the ‘fgets’ function.

Program to demonstrate the ‘fgets’ function. The program will count the number of lines in a file. This is a function of the UNIX command ‘wc’. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/



#include <stdio.h>

#define LINE_LENGTH 80

main()
{
FILE* fp;
char line[LINE_LENGTH];
int count=0;

fp=fopen("/home/DOC/C/c.html","r");
/* Count up the lines here. */
while ( fgets(line, LINE_LENGTH, fp) != NULL) count++;

printf("File contains %d lines.n", count);

fclose(fp);
}
Read more Similar C Programs
C Strings

Simple C Programs

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to demonstrate extern variable.

C Program to demonstrate extern variable. Extern variables are very useful in c,when the source code is in the two or more files, you can refer the variables from one file to another using extern variables. Extern variables are also global variable,but in explicit manner. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<stdio.h>
void write_extern(void);

extern int count;

void write_extern(void)
{
printf("count is %in", count);
}

int count = 5;

main()
{
write_extern();
}

Read more Similar C Programs
C Strings

Simple C Programs

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to demonstrate the ‘atof’ and ‘gets’ functions.

C Program to demonstrate the ‘atof’ and ‘gets’ functions. atof function converts the intial nptr string to the double. atof means ASCII to float. gets function reads string from the input stream. puts function prints string to the output stream This program will multiply to floating point numbers. The program will accept invalid data, and give you crap results as a result. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/



#include <stdio.h>
#include <stdlib.h>

main()
{
char str1[80], str2[80]; /* define a couple o' strings. */
double result; /* Result of multiplication. */

puts ("This program will multiply to floating point numbers.");
puts ("The program will accept invalid data, and give you");
puts ("crap results as a result.n");
puts ("Please enter the first number.");
gets(str1);

puts ("And the second.");
gets(str2);

result = atof(str1) * atof(str2);
printf("Answer is %8.2fn", result);
}


Read more Similar C Programs
C Strings

Simple C Programs

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to implement the Lagrange interpolation

C Program to implement the Lagrange interpolation. Lagrange interpolation is the polynomial interpolation. It is the process of passing a polynomial of degree n-1 through n points. In this program we used the arrays in c. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/
#include<stdio.h>
#include<conio.h>
#define MaxN 90

void main()
{
float arr_x[MaxN+1], arr_y[MaxN+1], numerator, denominator, x, y=0;
int i, j, n;
clrscr();
printf("Enter the value of n: n");
scanf("%d", &n);
printf("Enter the values of x and y: n");
for(i=0; i<=n; i++)
scanf("%f%f", &arr_x[i], &arr_y[i]);
printf("Enter the value of x at which value of y is to be calculated: ");
scanf("%f", &x);
for (i=0; i<=n; i++)
{
numerator=1;
denominator=1;
for (j=0; j<=n; j++)
if(j!=i)
{
numerator *= x-arr_x[j];
denominator *= arr_x[i]-arr_x[j];
}
y+=(numerator/denominator)*arr_y[i];
}
printf("When x=%4.1f y=%7.1fn",x,y);
getch();
}



Read more Similar C Programs
Learn C Programming

Simple C Programs

You can easily select the code by double clicking on the code area above. To get regular updates on new C programs, you can Follow @c_program You can discuss these programs on our Facebook Page. Start a discussion right now,

our page! Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button) Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to show Sleep() function example.

C Program to show Sleep() function example.
sleep() function stops the execution of the program, wherever its invoked or called. It takes the arguments in microseconds. In Windows we use Sleep() function i,e ‘S’, and for other systems it is sleep() function.
/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/

#include <time.h>
#include <stdio.h>
#include <windows.h> 
#include <conio.h>

int main()
{
 printf("This is the message before sleep() function");
 Sleep(1000); //1000 microsecond= 1 second will sleep...
 printf("This is the message after 1 second");
 getch();
 return 0;
}

However, I have to remind you that the program may change a bit based on
what Operating system and compiler you are using.

Read more Similar C Programs
Learn C Programming
Number System

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!


List of C Programs
(c) www.c-program-example.com