Posts

Showing posts with the label C Programming

C Program for Binary Search and Merge Search using recursion function | C Programming

C Program for Binary Search and Merge Search using recursion function Before starting with the program to find binary search and linear search using recursion function let us know about recursion function. Recursion Function Recursion is a process by which a function call itself repeatedly until some specified condition has been satisfied.                  The process is used for repetitive computation in which action is stated in terms of previous result.                  In order to solve a problem recursively two condition must be satisfied. The problem must be written in a recursive form. The problem statement must include a problem stopping condition.

C Program To Implement Dijkstra's Algorithm For Finding Shortest Path | C Programming

C Program To Implement Dijkstra's Algorithm For Finding Shortest Path | C Programming #include "stdio.h" #include "conio.h" #define infinity 999 void dij ( int n , int v , int cost [ 10 ][ 10 ], int dist []) {     int i , u , count , w , flag [ 10 ], min ;     for ( i = 1 ; i <= n ; i ++)         flag [ i ] = 0 , dist [ i ] = cost [ v ][ i ];     count = 2 ;     while ( count <= n )     {         min = 99 ;         for ( w = 1 ; w <= n ; w ++)             if ( dist [ w ] < min && ! flag [ w ])                 min = dist [ w ], u = w ;         flag [ u ] = 1 ;         count ++;         for ( w = 1 ; w <= n ; w ++)             if (( dist [ u ] + cost [ u ][ w ] < dist [ w ]) && ! flag [ w ])                 dist [ w ] = dist [ u ] + cost [ u ][ w ];     } } int main () {     int n , v , i , j , cost [ 10 ][ 10 ], dist [ 10 ];     printf ( "Enter the number of nodes:" );     scanf ( "

C Program To Find Minimum Spanning Tree Using Kruskal's Algorithm | C Programming

C Program To Find Minimum Spanning Tree Using Kruskal's Algorithm  #include <stdio.h> #include <conio.h> #include <stdlib.h> int i , j , k , a , b , u , v , n , ne = 1 ; int min , mincost = 0 , cost [ 9 ][ 9 ], parent [ 9 ]; int find ( int ); int uni ( int , int ); int main () {     printf ( " \n\t Implementation of Kruskal's Algorithm \n " );     printf ( " \n Enter the no. of vertices:" );     scanf ( " %d " , & n );     printf ( " \n Enter the cost adjacency matrix: \n " );     for ( i = 1 ; i <= n ; i ++)     {         for ( j = 1 ; j <= n ; j ++)         {             scanf ( " %d " , & cost [ i ][ j ]);             if ( cost [ i ][ j ] == 0 )                 cost [ i ][ j ] = 999 ;         }     }     printf ( "The edges of Minimum Cost Spanning Tree are \n " );     while ( ne < n )     {         for ( i = 1 , min = 999 ; i <= n ; i ++)         {  

C program to Find Cartesian Product of Two Sets | C programming

Image
C program to find the Cartesian Product of two sets   Cartesian product  is a mathematical operation that returns a set (or  product set  or simply  product ) from multiple sets. That is, for sets  A  and  B , the Cartesian product  A  ×  B  is the set of all ordered pairs  ( a ,  b )  where  a  ∈  A  and  b  ∈  B . Products can be specified using set-builder notation, e.g. {\displaystyle A\times B=\{\,(a,b)\mid a\in A\ {\mbox{ and }}\ b\in B\,\}.}

C program To Calculate The Intersection Of Two Sets | Union Of Two Sets | Differences Between Two Sets And Symmetric Difference Of Two Sets | C Programming

This Program helps to calculate intersection of two sets, union of two sets, differences of two sets and symmetric difference of two sets using one simple program in which different variables are declared so that it can be useful to find intersection of two sets, union of two sets, differences of two sets and symmetric difference of two sets Codes #include <stdio.h> int a [ 10 ], b [ 10 ], c [ 10 ], d [ 10 ], i , j , k = 0 , n , m , flag = 0 ; void unio () {     for ( i = 0 ; i < n ; i ++)     {         c [ k ] = a [ i ];         k ++;     }     for ( i = 0 ; i < m ; i ++)     {         flag = 0 ;         for ( j = 0 ; j < n ; j ++)         {             if ( b [ i ] == a [ j ])             {                 flag = 1 ;                 break ;             }         }         if ( flag == 0 )         {             c [ k ] = b [ i ];             k ++;         }     }     printf ( " \n Union \n " );     for ( i = 0 ; i < k ; i ++)

C Program To Calculate Age and Compare Using Concept of Fuzzy Set | C Programming

C Program To Calculate Age and Compare Using Concept of Fuzzy Set  #include <stdio.h> int i , age [ 5 ]; float a [ 5 ], b [ 5 ], c [ 5 ]; char name [ 5 ][ 15 ]; void unio () {     for ( i = 0 ; i < 5 ; i ++)     {         if ( a [ i ] >= b [ i ])             c [ i ] = a [ i ];         else             c [ i ] = b [ i ];     }     printf ( "union \n " );     printf ( "{ " );     for ( i = 0 ; i < 5 ; i ++)     {         printf ( " %.2f / %s ," , c [ i ], name [ i ]);     }     printf ( "}" ); } void intersection () {     for ( i = 0 ; i < 5 ; i ++)     {         if ( a [ i ] <= b [ i ])             c [ i ] = a [ i ];         else             c [ i ] = b [ i ];     }     printf ( " \n intersection \n " );     printf ( "{" );     for ( i = 0 ; i < 5 ; i ++)     {         printf ( " %.2f / %s , " , c [ i ], name [ i ]);     }     printf ( "}" ); } void comple

C Program To Find Floor and Celing Value | C Programming

C Program To Find Floor and Celing Value Using If and Else

C Program To Find Union Of Two Sets | C Programming

The collection of well-defined distinct objects is known as a set. The word well-defined refers to a specific property that makes it easy to identify whether the given object belongs to the set or not. The word ‘distinct’ means that the objects of a set must be all different. 

C Program To Find Intersection Of Two Sets | C Programming

C Program To Find Intersection Of Two Sets #include <stdio.h> #include <conio.h> int main () {     int a [ 10 ], b [ 10 ], m , n , i , j ;     int c [ 20 ], k = 0 , flag = 0 ;     int ch ;     printf ( "Enter the number of elements in first set: \n " );     scanf ( " %d " , & m );     printf ( "Enter the elements: \n " );     for ( i = 0 ; i < m ; i ++)     {         scanf ( " %d " , & a [ i ]);     }     printf ( " \n Element of First set: \n " );     for ( i = 0 ; i < m ; i ++)     {         printf ( " %d \t " , a [ i ]);     }     printf ( " \n Enter the number of elements in second set: \n " );     scanf ( " %d " , & n );     printf ( " \n Enter the elements:" );     for ( i = 0 ; i < n ; i ++)     {         scanf ( " %d " , & b [ i ]);     }     printf ( " \n Element of Second set: \n " );     for ( i = 0 ; i &l

C++ Program To Swap Value By Passing Reference | C Programming

C++ Program To Swap Value By Passing Reference #include <iostream> using namespace std ; #include <iomanip> int swap ( int & a , int & b ) {     int temp ;     temp = a ;     a = b ;     b = temp ;     return 0 ; } int main () {     int a , b ;     cout << "Enter the value of a and b \n " ;     cin >> a >> b ;     swap ( a , b );     cout << "The swapped value of a is " << a << endl          << "The swapped value of b is " << b ; } OUTPUT Enter the value of a and b 60 90 The swapped value of a is 90 The swapped value of b is 60

Differences between Break and Continue | C Programming

Differences between Break and Continue in C Programming The major difference between break and continue statements in C language is that a break causes the innermost enclosing loop or switch to be exited immediately. Whereas, the continue statement causes the next iteration of the enclosing for, while, or do loop to begin. The continue statement in while and do loops takes the control to the loop's test-condition immediately, whereas in the for loop it takes the control to the increment step of the loop. The continue statement applies only to loops, not to switch. A continue inside a switch inside a loop causes the next loop iteration. Practically, break is used in switch, when we want to exit after a particular case is executed; and in loops, when it becomes desirable to leave the loop as soon as a certain condition occurs (for instance, you detect an error condition, or you reach the end of your data prematurely). The continue statement is used when we want to skip one