From 7335268652afa7d8369914e49683ca9cb522fefe Mon Sep 17 00:00:00 2001 From: VikasGwala Date: Sun, 26 Jul 2026 12:18:52 +0530 Subject: [PATCH 01/10] Refactor linked list implementation in Appending_Node.c and improve array addition logic in additionarray.c --- Appending_Node.c | 84 ++++++++++++++++++++++---------------------- additionarray.c | 10 +++--- tempCodeRunnerFile.c | 5 +++ 3 files changed, 52 insertions(+), 47 deletions(-) create mode 100644 tempCodeRunnerFile.c diff --git a/Appending_Node.c b/Appending_Node.c index 4d9e308..dfe87d2 100644 --- a/Appending_Node.c +++ b/Appending_Node.c @@ -1,69 +1,69 @@ -#include -#include -void append(); -struct node +#include +#include + +typedef struct node { int data; struct node *link; -}; -struct node *root; +} node; + +node *append(node *); +void print(node *); + int main() { - root=(struct node*)malloc(sizeof(struct node)); + node *root=NULL; + node *current=NULL; + current = (node *)malloc(sizeof(node)); printf("ROOT 1 DATA:"); - scanf("%d", &root->data); - root->link=NULL; - - struct node*current; - current=(struct node*)malloc(sizeof(struct node)); - - - printf("ROOT 2 DATA:"); - scanf("%d", ¤t->data); - current->link=NULL; - root->link=current; // this will store the address of the second node into the link part of the first node - - current=malloc(sizeof(struct node)); - - printf("ROOT 3 DATA:"); scanf("%d", ¤t->data); - current->link=NULL; - root->link->link=current; // this will store the base address of the third node into the link part of the second node + current->link = NULL; + root = current; // this will store the address of the second node into the link part of the first node printf("APPENDING NODE:\n"); - append(); // now the user will be prompted for appending the element to the last of the linked list - + root = append(root); // now the user will be prompted for appending the element to the last of the linked list + print(root); + return 0; } -void append() +node *append(node *root) { - struct node *temp; - temp=(struct node*)malloc(sizeof(struct node)); + node *temp=NULL; + temp = (node *)malloc(sizeof(node)); + printf("ENTER NODE DATA:"); scanf("%d", &temp->data); + temp->link = NULL; - if(root==NULL) + if (root == NULL) { - root=temp; // we are checking if the linked list is empty then this will be the first node to be inserted in the linked list + root = temp; // we are checking if the linked list is empty then this will be the first node to be inserted in the linked list } else { - struct node *ptr; // used for traversing through nodes - ptr=root; - while(ptr->link!=NULL) + node *ptr; // used for traversing through nodes + ptr = root; + while (ptr->link!= NULL) { - ptr=ptr->link; + ptr = ptr->link; } - ptr->link=temp; // this will connect the last node with the temp node which we created before + ptr->link = temp; // this will connect the last node with the temp node which we created before } - printf("PRINTING DATA IN ALL NODES\n"); - - printf("NODE 1: %d\n", root->data); - printf("NODE 2: %d\n", root->link->data); - printf("NODE 3: %d\n", root->link->link->data); - printf("NODE 4: %d\n", root->link->link->link->data); + return root; +} +void print(node *root) +{ + node *ptr; + ptr = root; + printf("PRINTING DATA IN ALL NODES:\n"); + while (ptr->link != NULL) + { + printf("%d->",ptr->data); + ptr = ptr->link; + } + printf("%d", ptr->data); } \ No newline at end of file diff --git a/additionarray.c b/additionarray.c index 5ce2ad1..1555bf2 100644 --- a/additionarray.c +++ b/additionarray.c @@ -3,22 +3,22 @@ int main() { int arr1[5],arr2[5],arr3[5],i; printf("Enter 5 numbers of arr1:"); - for(i=0;i<=4;i++) + for(i=0;i<5;i++) { scanf("%d",&arr1[i]);//Taking input from the user for the first array. } printf("Enter 5 numbers of arr2:"); - for(i=0;i<=4;i++) + for(i=0;i<5;i++) { scanf("%d",&arr2[i]);//Taking input from the user for the second array. } - for(i=0;i<=4;i++) + for(i=0;i<5;i++) { arr3[i]=arr1[i]+arr2[i];//Addition of the two arrays. } printf("Addition of two array:"); - for(i=0;i<=4;i++) + for(i=0;i<5;i++) { - printf("%d\t",arr3[i]);//Printing the new array. + printf("%d ",arr3[i]);//Printing the new array. } } diff --git a/tempCodeRunnerFile.c b/tempCodeRunnerFile.c new file mode 100644 index 0000000..18030f2 --- /dev/null +++ b/tempCodeRunnerFile.c @@ -0,0 +1,5 @@ +root = (node *)malloc(sizeof(node)); + + printf("ROOT 1 DATA:"); + scanf("%d", &root->data); + root->link = NULL; \ No newline at end of file From e9ce4d78241352726488f9e527904ebcfe2ca075 Mon Sep 17 00:00:00 2001 From: VikasGwala Date: Sun, 26 Jul 2026 12:21:53 +0530 Subject: [PATCH 02/10] Remove temporary code runner file and its associated node initialization --- tempCodeRunnerFile.c | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 tempCodeRunnerFile.c diff --git a/tempCodeRunnerFile.c b/tempCodeRunnerFile.c deleted file mode 100644 index 18030f2..0000000 --- a/tempCodeRunnerFile.c +++ /dev/null @@ -1,5 +0,0 @@ -root = (node *)malloc(sizeof(node)); - - printf("ROOT 1 DATA:"); - scanf("%d", &root->data); - root->link = NULL; \ No newline at end of file From ce6096f1003785990a684ad4839d1d6dc708e72c Mon Sep 17 00:00:00 2001 From: VikasGwala Date: Sun, 26 Jul 2026 12:31:45 +0530 Subject: [PATCH 03/10] Fix formatting and indentation issues in calculator.c, difference.c, and even.c --- calculator.c | 4 ++-- difference.c | 1 + even.c | 26 +++++++++++++------------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/calculator.c b/calculator.c index 7660434..8ae1262 100644 --- a/calculator.c +++ b/calculator.c @@ -28,8 +28,8 @@ int main() result=a/b; printf("The Division Is %d", result); break; - default: - printf("Please Enter a valid Operator"); + default: + printf("Please Enter a valid Operator"); break; } return 0; diff --git a/difference.c b/difference.c index 4766f36..e83c3ee 100644 --- a/difference.c +++ b/difference.c @@ -24,6 +24,7 @@ int main() break; default: printf("Wrong Choice!!!"); + break; } return 0; } diff --git a/even.c b/even.c index ae71b50..ff3320a 100644 --- a/even.c +++ b/even.c @@ -1,17 +1,17 @@ -//C program to find out a number is even or not. +// C program to find out a number is even or not. -#include +#include void main() -{ int numb,i; -printf("Enter a number:"); -scanf("%d",&numb); -if(numb%2==0) // condition to check even logic { -printf("A even number"); -} -else -{ -printf("A odd number"); -} - + int numb, i; + printf("Enter a number:"); + scanf("%d", &numb); + if (numb % 2 == 0) // condition to check even logic + { + printf("A even number"); + } + else + { + printf("A odd number"); + } } From 052522acb84618d1b6649ca4880d39bf3f13d2a8 Mon Sep 17 00:00:00 2001 From: VikasGwala Date: Sun, 26 Jul 2026 12:34:32 +0530 Subject: [PATCH 04/10] Add missing break and fix formatting in default case Fix indentation issue in default case of calculator.c --- Calculator.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Calculator.c b/Calculator.c index 7660434..8ae1262 100644 --- a/Calculator.c +++ b/Calculator.c @@ -28,8 +28,8 @@ int main() result=a/b; printf("The Division Is %d", result); break; - default: - printf("Please Enter a valid Operator"); + default: + printf("Please Enter a valid Operator"); break; } return 0; From a9dd5228aa1438913a00911ca43b07b1be651a4c Mon Sep 17 00:00:00 2001 From: VikasGwala Date: Tue, 28 Jul 2026 19:22:05 +0530 Subject: [PATCH 05/10] simplify multiplication table output --- table10num.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/table10num.c b/table10num.c index 9687294..fc9c6e9 100644 --- a/table10num.c +++ b/table10num.c @@ -4,8 +4,6 @@ int main() { int i,j,num; - printf("Enter a number:\n"); - scanf("%d",&num); printf("Table of 10 numbers\n"); for(i=1;i<=10;i++) { From 799a26724f60484324d1432d07ba7f90b7e9c212 Mon Sep 17 00:00:00 2001 From: VikasGwala Date: Tue, 28 Jul 2026 19:36:12 +0530 Subject: [PATCH 06/10] Fix include directive and ensure return statement is present in swapping.c --- swapping.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/swapping.c b/swapping.c index cd35cd2..39f17b5 100644 --- a/swapping.c +++ b/swapping.c @@ -1,6 +1,6 @@ //C program to swap the values of two numbers. -#include +#include int main() { int x,y,t; @@ -11,4 +11,5 @@ int main() x=y; y=t; printf("The swapped values of x=%d and y=%d",x,y); + return 0; } From b3a26a11b5aa9bc7d4dfa6f403e15272f3ced332 Mon Sep 17 00:00:00 2001 From: VikasGwala Date: Tue, 28 Jul 2026 19:36:22 +0530 Subject: [PATCH 07/10] Ensure return statement is present in table.c --- table.c | 1 + 1 file changed, 1 insertion(+) diff --git a/table.c b/table.c index e6a8f81..f8c454d 100644 --- a/table.c +++ b/table.c @@ -10,4 +10,5 @@ int main() { printf("%d * %d = %d\n",n,i,n*i); } + return 0; } From bcdbe5d71dff2501025033853c9abafdc82dc73d Mon Sep 17 00:00:00 2001 From: VikasGwala Date: Tue, 28 Jul 2026 19:36:31 +0530 Subject: [PATCH 08/10] Ensure return statement is present in table2.c --- table2.c | 1 + 1 file changed, 1 insertion(+) diff --git a/table2.c b/table2.c index fd80eff..e114498 100644 --- a/table2.c +++ b/table2.c @@ -10,4 +10,5 @@ int main() { printf("%d\n",n*i); } + return 0; } From 7883a0f53ba8b621ed7647dfb40185a4598ce641 Mon Sep 17 00:00:00 2001 From: VikasGwala Date: Tue, 28 Jul 2026 19:36:47 +0530 Subject: [PATCH 09/10] Ensure proper formatting and return statement in table10num.c --- table10num.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/table10num.c b/table10num.c index fc9c6e9..1f162e6 100644 --- a/table10num.c +++ b/table10num.c @@ -11,5 +11,7 @@ int main() { printf("%d\t",i*j); } + printf("\n"); } + return 0; } From 90ef06ac61e2ed8d12d9c215f754c2f708b68bd3 Mon Sep 17 00:00:00 2001 From: VikasGwala Date: Tue, 28 Jul 2026 19:36:56 +0530 Subject: [PATCH 10/10] Fix typo in subtraction operation and ensure proper return statement in Take input from user --- Take input from user | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Take input from user b/Take input from user index 14f1e9e..7031308 100644 --- a/Take input from user +++ b/Take input from user @@ -10,7 +10,7 @@ int main() // Performs all arithmetic operations sum = no1 + no2; - sub = no - no2; + sub = no1 - no2; mult = no1 * no2; div = (float)no1 / no2; mod = no1 % no2; @@ -21,5 +21,5 @@ int main() printf("The product of the entered numbers : %d\n", mult); printf("The quotient of the entered numbers : %f\n", div); printf("Mod = %d\n", mod); //remainder - + return 0; }