Data Structure using C

Translate

Friday, December 18, 2020

Write a Program to implement DFS Graph Traversal Algorithm

December 18, 2020 0

 Write a Program to implement DFS Graph Traversal Algorithm.

Depth-first algorithm

code👇👇👇👇👇👇👇👇👇👇👇👇👇👇

#include<stdio.h>


void DFS(int);

int G[10][10],visited[10],n;


void main()

{

    int i,j;

    printf("Enter number of vertices:");


scanf("%d",&n);



printf("\nEnter adjecency matrix of the graph:");


for(i=0;i<n;i++)

       for(j=0;j<n;j++)

scanf("%d",&G[i][j]);



   for(i=0;i<n;i++)

        visited[i]=0;


    DFS(0);

}


void DFS(int i)

{

    int j;

printf("d",i);

    visited[i]=1;


for(j=0;j<n;j++)

       if(!visited[j]&&G[i][j]==1)

            DFS(j);

}




Read More

Wednesday, December 16, 2020

C program to find the sum of digit of a number.

December 16, 2020 0

   C program to find the sum of digit of a number.

code👇👇👇👇👇👇👇👇👇


#include<stdio.h>


int main()

{

    int n, r, sum = 0;


    printf("Enter a number: ");

    scanf("%d", &n);


    while(n != 0)

    {

        r = n % 10;

        sum += r;

        n = n / 10;

    }


    printf("sum = %d", sum);


    return 0;

}

output


Read More

Sunday, December 13, 2020

C program to print the Logic gates(AND, OR, NOT, NAND, NOR, XOR)

December 13, 2020 0

C program to print the LOgic gates(AND, OR, NOT, NAND, NOR, XOR). take input from the user.

code👇👇👇👇👇👇👇👇👇


#include<stdio.h>
int main()
{
int a,b;
printf("Enter input a=");
scanf("%d",&a);
printf("Enter input b=");
scanf("%d",&b);
printf("a AND b = %d\n",a&b);
printf("a OR b = %d\n",a|b);
printf("NOT a = %d\n",!a);
printf("a NAND b = %d\n",!(a&b));
printf("a NOR b = %d\n",!(a|b));
printf("a XOR b = %d\n",a^b);
return 0;
}


Read More

Introduction to Arrays

  Introduction to Arrays An array is a data structure that allows you to store a collection of elements of the same type. Each element in th...