Thursday, 15 November 2018

Write down a C Program to insert in beginning & end, delete a node in beginning & end, Traverse for the Doubly Linked List and also modify a specified node for the Doubly Linked List using Global start variable & call by reference & by using the Switch Case.

Write down a C Program to insert in beginning & end, delete a node in beginning & end, Traverse for the Doubly Linked List and also modify a specified node for the Doubly Linked List using Global start variable & call by reference & by using the Switch Case.

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <malloc.h>
  4. struct node 
  5. {
  6. struct node *prev;
  7. int data;
  8. struct node *next;
  9. };
  10. struct node *start=NULL;
  11. void create_nodebegining(int);
  12. void create_nodeend(int);
  13. void delete_nodebegining();
  14. void delete_nodeend();
  15. void modify(int,int);
  16. void traverse();
  17. int main()
  18. {
  19. int data,i,n,ch,data1;
  20. printf("\n Enter The Value of data to be Entered:\n");
  21. scanf("%d",&n);
  22. for(i=0;i<n;i++)
  23. {
  24. printf("\n Enter The Value Should be Enter In Data of Node:\n");
  25. scanf("%d",&data);
  26. create_nodeend(data);
  27. }
  28. printf("\n Please Enter Your Choise \n ");
  29. printf("\n Press 1 for Insert in Beginning \n Press 2 for Insert in end \n Press 3 Delete in Beginning \n Press 4 for delete in end \n Press 5 for modify \n press 6 for traverse \n");
  30. scanf("%d",&ch);
  31. switch(ch)
  32. {
  33. case 1:
  34. printf("\n Enter The Value For Node Data:\n");
  35. scanf("%d",&data);
  36. create_nodebegining(data);
  37. break;
  38. case 2:
  39. printf("\n Enter The Value For Node Data:\n");
  40. scanf("%d",&data);
  41. create_nodeend(data);
  42. break;
  43. case 3:
  44. delete_nodebegining();
  45. break;
  46. case 4:
  47. delete_nodeend();
  48. break;
  49. case 5:
  50. printf("\n Enter The Data To be Modified:\n");
  51. scanf("%d",&data1);
  52. printf("\n Enter The Data Modified:\n");
  53. scanf("%d",&data);
  54. modify(data1,data);
  55. break;
  56. case 6:
  57. traverse();
  58. break;
  59. }
  60. traverse();
  61. }
  62. void create_nodeend(int x)
  63. {
  64. struct node *t,*t1;
  65. t=(struct node*)malloc(sizeof(struct node));
  66. t->prev=NULL;
  67. t->data=x;
  68. t->next=NULL;
  69. if(start==NULL)
  70. {
  71. start=t;
  72. }
  73. else
  74. {
  75. t1=start;
  76. while(t1->next!=NULL)
  77. {
  78. t1=t1->next;
  79. }
  80. t1->next=t;
  81. t->prev=t1;
  82. }
  83. }
  84. void create_nodebegining(int x)
  85. {
  86. struct node *t,*t1;
  87. t1=start;
  88. t=(struct node*)malloc(sizeof(struct node));
  89. t->prev=NULL;
  90. t->data=x;
  91. t->next=t1;
  92. t1->prev=t;
  93. start=t;
  94. traverse();
  95. }
  96. void delete_nodeend()
  97. {
  98. struct node *t,*t1;
  99. t=start;
  100. while(t->next!=NULL)
  101. {
  102. t1=t;
  103. t=t->next;
  104. }
  105. free(t);
  106. t1->next=NULL;
  107. traverse();
  108. }
  109. void delete_nodebegining()
  110. {
  111. struct node *t,*t1;
  112. t1=start;
  113. start=t1->next;
  114. start->prev=NULL;
  115. traverse();
  116. }
  117. void modify(int x,int y)
  118. {
  119. struct node *t;
  120. t=start;
  121. while(t->data!=x)
  122. {
  123. t=t->next;
  124. }
  125. t->data=y;
  126. traverse();
  127. }

  128. void traverse()
  129. {
  130. struct node *t;
  131. t=start;
  132. while(t->next!=NULL)
  133. {
  134. printf("\n %d",t->data);
  135. t=t->next;
  136. }
  137. printf("\n %d\n\n",t->data);
  138. while(t->prev!=NULL)
  139. {
  140. printf("\n %d",t->data);
  141. t=t->prev;
  142. }
  143. printf("\n %d\n\n",t->data);
  144. }

Write down a C Program to insert in beginning & end, delete a node in beginning & end, Traverse for the singly linked list and also modify a specified node for the Singly Linked List using Global start variable & call by reference & by using the Switch Case

Write down a C Program to insert in beginning & end, delete a node in beginning & end, Traverse for the Singly Linked List and also modify a specified node for the Singly Linked List using Global start variable & call by reference & by using the Switch Case.

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <malloc.h>
  4. struct node 
  5. {
  6. int data;
  7. struct node *next;
  8. };
  9. struct node *start=NULL;
  10. void create_nodebegining(int);
  11. void create_nodeend(int);
  12. void delete_nodebegining();
  13. void delete_nodeend();
  14. void modify(int,int);
  15. void traverse();
  16. int main()
  17. {
  18. int data,i,n,ch,data1;
  19. printf("\n Enter The Value of data to be Entered:\n");
  20. scanf("%d",&n);
  21. for(i=0;i<n;i++)
  22. {
  23. printf("\n Enter The Value Should be Enter In Data of Node:\n");
  24. scanf("%d",&data);
  25. create_nodeend(data);
  26. }
  27. printf("\n Please Enter Your Choise \n ");
  28. printf("\n Press 1 for Insert in Beginning \n Press 2 for Insert in end \n Press 3 Delete in Beginning \n Press 4 for delete in end \n Press 5 for modify \n press 6 for traverse \n");
  29. scanf("%d",&ch);
  30. switch(ch)
  31. {
  32. case 1:
  33. printf("\n Enter The Value For Node Data:\n");
  34. scanf("%d",&data);
  35. create_nodebegining(data);
  36. break;
  37. case 2:
  38. printf("\n Enter The Value For Node Data:\n");
  39. scanf("%d",&data);
  40. create_nodeend(data);
  41. break;
  42. case 3:
  43. delete_nodebegining();
  44. break;
  45. case 4:
  46. delete_nodeend();
  47. break;
  48. case 5:
  49. printf("\n Enter The Data To be Modified:\n");
  50. scanf("%d",&data1);
  51. printf("\n Enter The Data Modified:\n");
  52. scanf("%d",&data);
  53. modify(data1,data);
  54. break;
  55. case 6:
  56. traverse();
  57. break;
  58. }
  59. traverse();
  60. }
  61. void create_nodeend(int x)
  62. {
  63. struct node *t,*t1;
  64. t=(struct node*)malloc(sizeof(struct node));
  65. t->data=x;
  66. t->next=NULL;
  67. if(start==NULL)
  68. {
  69. start=t;
  70. }
  71. else
  72. {
  73. t1=start;
  74. while(t1->next!=NULL)
  75. {
  76. t1=t1->next;
  77. }
  78. t1->next=t;
  79. }
  80. }
  81. void create_nodebegining(int x)
  82. {
  83. struct node *t,*t1;
  84. t=(struct node*)malloc(sizeof(struct node));
  85. t1=start;
  86. t->data=x;
  87. t->next=t1;
  88. start=t;
  89. traverse();
  90. }
  91. void delete_nodeend()
  92. {
  93. int d;
  94. struct node *t,*t1;
  95. t=start;
  96. while(t->next!=NULL)
  97. {
  98. t1=t;
  99. t=t->next;
  100. }
  101. d=t->data;
  102. free(t);
  103. t1->next=NULL;
  104. traverse();
  105. }
  106. void delete_nodebegining()
  107. {
  108. int d;
  109. struct node *t,*t1;
  110. t=start->next;
  111. d=start->data;
  112. free(start);
  113. start=t;
  114. traverse();
  115. }
  116. void modify(int x,int y)
  117. {
  118. struct node *t;
  119. t=start;
  120. while(t->data!=x)
  121. {
  122. t=t->next;
  123. }
  124. t->data=y;
  125. traverse();
  126. }
  127. void traverse()
  128. {
  129. struct node *t;
  130. t=start;
  131. while(t->next!=NULL)
  132. {
  133. printf("\n %d",t->data);
  134. t=t->next;
  135. }
  136. printf("\n %d\n\n",t->data);
  137. }



Thursday, 11 October 2018

C Program to Insert Node at The End of Single Linked List

Single Linked List: - Simply a list is a sequence of data, and the linked list is a sequence of data linked with each other. 

The formal definition of a single linked list is as follows.

The single linked list is a sequence of elements in which every element has link to its next element in the sequence.

In any single linked list, the individual element is called as "Node". Every "Node" contains two fields, data and next. The data field is used to store the actual value of that node and the next field is used to store the address of the next node in the sequence.



  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <malloc.h>
  4. struct node
  5. {
  6.  int data;
  7.  struct node *next;
  8. };
  9. struct node *start;
  10. void creat_node(int);
  11. void creat_nodee(int);
  12. void print();
  13. int main()
  14. {
  15. int data,i,n,neww;
  16. printf("Plese Enter the Length of the Linked List:\n");
  17. scanf("%d",&n);
  18. for(i=0;i<n;i++)
  19. {
  20. printf("Please Enter A Value:\n");
  21. scanf("%d",&data);
  22. creat_node(data);
  23. }
  24. print();
  25. printf("Please Enter A Value to be Insert at the End of the Linked LIST:\n");
  26. scanf("%d",&neww);
  27. creat_nodee(neww);
  28. print();
  29. }
  30. void creat_node(int x)
  31. {
  32. struct node *t,*t1;
  33. t=(struct node*)malloc(sizeof(struct node));
  34. t->data=x;
  35. t->next=NULL;
  36. if(start==NULL)
  37. {
  38. start=t;
  39. }
  40. else
  41. {
  42. t1=start;
  43. while(t1->next!=NULL)
  44. {
  45. t1=t1->next;
  46. }
  47. t1->next=t;
  48. }
  49. }
  50. void creat_nodee(int x)
  51. {
  52. struct node *t,*t1;
  53. t=(struct node*)malloc(sizeof(struct node));
  54. t->data=x;
  55. t->next=NULL;
  56. t1=start;
  57. while(t1->next!=NULL)
  58. {
  59. t1=t1->next;
  60. }
  61. t1->next=t;
  62. }
  63. void print()
  64. {
  65. struct node *t;
  66. t=start;
  67. while(t->next!=NULL)
  68. {
  69. printf("Your Entered DATA was: %d \n",t->data);
  70. t=t->next;
  71. }
  72. printf("Your Entered DATA was (END): %d \n",t->data);
  73. }

Sunday, 9 September 2018

C Program for Verifying or Identifying A Number is a Armstrong Number or Not | C Program for Armstrong Number |

This Program is for  Verifying or Identifying A Number is an Armstrong Number or Not, 

This program is applicable for identifying any digits of a number is Armstrong number or not.



#include <stdio.h>

main()
{
int number,temp,i=0,j=0,result=0,power,dig,remain;
printf("\nEnter Any Number:\n");
scanf("%d",&number);
temp=number;
while(temp!=0)    //for(temp=number;temp!=0;temp/=10) {i++}
{
temp/=10; //temp=temp/10;
i++;
}
printf("\nYOU HAVE ENTERED The Number %d Which is A %d DIGIT Number",number,i);
for(temp=number;temp!=0;temp/=10)
{
printf("\n\nAfter %d Loop Temp Value is \t %d\n\n",j,temp);
power=1;
remain=temp%10;
printf("\n Remain is %d \t  When Temp Value is = %d",remain,temp);
dig=i;
for(i=0;i<dig;i++)
{
power*=remain; //power = power*remain;
}
printf("\n Power Value = %d \t  When Temp Value is = %d",power,temp);
result+=power; //result = result+power;
printf("\n Result Value = %d \t  When \t Temp Value is = %d",result,temp);
j++;
}
if(result==number)
{
printf("\n\nUltimate Result\n\nYou Have Entered %d Number and It is a Armstrong Number as \nResult = \t %d and Number = \t %d is Same",number,result,number);
}
else
{
printf("\n\nUltimate Result\n\nYou Have Entered %d Number and It is NOT a Armstrong Number as \nResult = \t %d and Number = \t %d is NOT Same",number,result,number);
}
}

RESULT WILL BE LIKE THAT >>                                                                                                    













              

                                                                                                                                                                   








Wednesday, 29 August 2018

C Program For Printing Matrix & Sum of the Values in Each Rows Using The Concept of 2D / Two dimensional array and FOR Loop | C Program for Printing Values in Matrix Form & Sum of the Values in Each Rows By Using Two Dimensional Array and FOR Loop

C Program For Printing Matrix & Sum of the Values in Each Rows Using The Concept of 2D / Two-dimensional array and FOR Loop 

C Program for Printing Values in Matrix Form & Sum of the Values in Each Rows By Using Two Dimensional Array and FOR Loop 

2D / Two-dimensional array :- 2D array has a type such as int[][] or String[][], withtwo pairs of square brackets. The elements of a 2D array are arranged in rows and columns, and the new operator for 2D arrays specifies both the number of rows and the number of columns.

An array of arrays is known as a 2D array. The two dimensional (2D) array in C programming is also known as matrix. A matrix can be represented as a table of rows and columns. Before we discuss more about two Dimensional array lets have a look at the following C program

 The simplest form of multidimensional array is the two-dimensional array. A two-dimensional array is, in essence, a list of one-dimensional arrays. To declare a two-dimensional integer array of size [x][y], you would write something as follows − Type arrayName [x][y]

Where type can be any valid C data type and arrayName will be a valid C identifier. A two-dimensional array can be considered as a table which will have x number of rows and y number of columns. A two-dimensional array a, which contains three rows and four columns can be shown as follows −

Thus, every element in the array a is identified by an element name of the form a[ i ][ j ], where 'a' is the name of the array, and 'i' and 'j' are the subscripts that uniquely identify each element in 'a'.

C Program For Printing Matrix & Sum of the Values in Each Rows of that Matrix Using The Concept of 2D / Two-dimensional array and FOR Loop - 

Type 1 ->>



#include <stdio.h>

main()
{
int a,b,i,j,sum; //Some integer type variable declared
printf("\nEnter Rows and Coloumn:\n");
scanf("%d %d",&a,&b); //Enter the values for number of rows and number of columns
printf("\nRows = %d \n and \n Coloumn = %d\n",a,b); 
int k[a][b]; //2D Array declared
printf("\nEnter A Values\n");
for(i=0;i<a;i++) //For loop for Rows
{
for(j=0;j<b;j++) //For loop for column
{
scanf("%d",&k[i][j]); //Values of the matrix given here
printf("\n %6d (%d %d)\n",k[i][j],i+1,j+1); //Printing the given value with the same number like row number and column number For visualisation whole concept
}
}
printf("\nYour Matrex \n\n\n");

printf("\n                             Result\n");

for(i=0;i<a;i++) //For loop for Rows

{
sum=0; //
for(j=0;j<b;j++) //For Columns
{
printf("%6d",k[i][j]); //Printing the whole matrix
sum+=k[i][j]; //Addition of values in each row
}

printf("%15d",sum); //Printing the all or total value of addition
       }
}

Type 2 ->>

#include <stdio.h>
main()
{
int a,b,i,j,sum; 
//Some integer type variable declared
printf("\nEnter Rows and Coloumn:\n");
scanf("%d %d",&a,&b);
 //Enter the values for number of rows and number of columns
printf("\nRows = %d \n and \n Coloumn = %d\n",a,b);
int k[a][b];
 //2D Array declared
printf("\nEnter A Values\n");
for(i=0;i<a;i++)
//For loop for Rows
{
for(j=0;j<b;j++)
 //For loop for column
{
scanf("%d",&k[i][j]); 
 //Values of the matrix given here
printf("\n %6d (%d %d)\n",k[i][j],i+1,j+1); 
//Printing the given value with the same number like row number and column number For visualisation whole concept
}
}
printf("\nYour Matrex \n\n\n");
for(i=0;i<a;i++)
//For loop for Rows
{
sum=0;
for(j=0;j<b;j++)
 //For loop for column
{
printf("%6d",k[i][j]);
//Printing the whole matrix
sum+=k[i][j];
//Addition of values in each row
}
printf("  Result = %6d",sum); //Printing the all or total value of addition
printf("\n\n");
}
}

Monday, 27 August 2018

C Program to Find Log(n) Value Using For Loop | Program for Finding Logarithm Value using For Loop |

C Program to Find Log(n) Value Using For Loop | Program for Finding Logarithm Value using For Loop |

/*C Program to Find Log(n) Value Using For Loop | Program for Finding Logarithm Value using For Loop |*/
/* Program Developed by Anupam Dutta */
#include <stdio.h>
#include <math.h>
main()
{
int num,number,i,k; //Variable declaration
printf("\nAll Values Should be a Integer\n\nFloat Number Will not be applicable\n");
printf("Enter A Value:\n"); //A integer value should be entered
scanf("%d",&num);
number=num; //Value of 'num' will be assigned to 'number'
printf("Enter A Base Value:\n"); //Enter the base value of log
scanf("%d",&k); //Scanning the entered value
for(i=1;num!=k;i++) //For Loop
{
num=num/k;
}
printf("%d",i);
printf("\n  Log Base = (%d)^(%d) = (%d)",k,number,i); //Printing the result
printf("\n  X(%d)^Y(%d) = Z(%d)",k,i,number); //Printing the result
main();
}