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/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/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; } 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/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"); + } } 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; } 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; } diff --git a/table10num.c b/table10num.c index 9687294..1f162e6 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++) { @@ -13,5 +11,7 @@ int main() { printf("%d\t",i*j); } + printf("\n"); } + return 0; } 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; }