diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..7a9dfa0 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "pwa-chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:8080", + "webRoot": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/Basic C Programs/BinarySearchTree/BinarySearchTree.cbp b/Basic C Programs/BinarySearchTree/BinarySearchTree.cbp new file mode 100644 index 0000000..a87f55e --- /dev/null +++ b/Basic C Programs/BinarySearchTree/BinarySearchTree.cbp @@ -0,0 +1,43 @@ + + + + + + diff --git a/Basic C Programs/BinarySearchTree/BinarySearchTree.depend b/Basic C Programs/BinarySearchTree/BinarySearchTree.depend new file mode 100644 index 0000000..e54549c --- /dev/null +++ b/Basic C Programs/BinarySearchTree/BinarySearchTree.depend @@ -0,0 +1,6 @@ +# depslib dependency file v1.0 +1574915131 source:f:\cprograms\binarysearchtree\main.c + + + + diff --git a/Basic C Programs/BinarySearchTree/BinarySearchTree.layout b/Basic C Programs/BinarySearchTree/BinarySearchTree.layout new file mode 100644 index 0000000..35cb75d --- /dev/null +++ b/Basic C Programs/BinarySearchTree/BinarySearchTree.layout @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Basic C Programs/BinarySearchTree/main.c b/Basic C Programs/BinarySearchTree/main.c new file mode 100644 index 0000000..35a7364 --- /dev/null +++ b/Basic C Programs/BinarySearchTree/main.c @@ -0,0 +1,249 @@ +#include +#include +#include + +//Structure Declarations +typedef struct node +{ + void * dataptr; + struct node *left,*right; +}NODE; + +typedef struct +{ + int count; + int (*compare)(void *argu1, void* argu2); + NODE *root; +}BST_TREE; + +//Prototype Declarations +BST_TREE *BST_Create (int (*compare)(void *argu1,void *argu2)); +BST_TREE *BST_Destroy(BST_TREE *tree); +bool BST_Insert(BST_TREE*tree,void*dataptr); +bool BST_Delete(BST_TREE *tree,void *dltkey); +bool BST_Empty(BST_TREE *tree); +bool BST_Full(BST_TREE *tree); +int BST_Count(BST_TREE *tree); +void BST_Traverse(BST_TREE *tree, void(*process)(void*dataptr)); +void *BST_Retrieve(BST_TREE *tree, void *keyptr); +static void _traverse(NODE *root, void(*process)(void *dataptr)); +static void _destroy(NODE *root); +static void *_retrieve(BST_TREE *tree, void *dataptr, NODE *root); +static NODE* _insert(BST_TREE*tree, NODE*root, NODE*newptr); +static NODE* _delete(BST_TREE* tree, NODE*root, void*dataptr, bool *success); + +//Create BST +BST_TREE *BST_Create(int (*compare)(void *argu1,void *argu2)) +{ + BST_TREE *tree; + tree=(BST_TREE*)malloc(sizeof(BST_TREE)); + if(tree) + { + tree->root=NULL; + tree->count=0; + tree->compare=compare; + } + return tree; +} + +//Insert BST +bool BST_Insert(BST_TREE*tree,void*dataptr) +{ + NODE *newptr; + newptr=(NODE*)malloc(sizeof(NODE)); + if(!newptr) + return false; + newptr->right=NULL; + newptr->left=NULL; + newptr->dataptr=dataptr; + if(tree->count==0) + tree->root=newptr; + else + _insert(tree,tree->root,newptr); + (tree->count)++; + return true; +} + +//INTERNAL insert +NODE *_insert(BST_TREE*tree, NODE*root, NODE*newptr) +{ +if(!root) + return newptr; +if(tree->compare(newptr->dataptr,root->dataptr)<0) +{ + root->left=_insert(tree,root->left,newptr); + return root; +} +else +{ + root->right=_insert(tree,root->right,newptr); + return root; +} +return root; +} + +//Delete +bool BST_Delete(BST_TREE *tree,void *dltkey) +{ + bool success; + NODE*newroot; + newroot=_delete(tree,tree->root,dltkey,&success); + if(success) + { + tree->root=newroot; + (tree->count)--; + if(tree->count==0) + tree->root=NULL; + } + return success; +} + +//INTERNAL Delete +NODE *_delete(BST_TREE* tree, NODE*root, void*dataptr, bool *success) +{ + NODE*dltptr; + NODE*exchptr; + NODE*newroot; + void* holdptr; + + if(!root) + { + *success=false; + return NULL; + } + if(!root) + { + *success=false; + return NULL; + } + if(tree->compare(dataptr,root->dataptr)<0) + root->left=_delete(tree,root->left,dataptr,success); + else if(tree->compare(dataptr,root->dataptr)>0) + root->right=_delete(tree,root->right,dataptr,success); + else + { + dltptr=root; + if(!root->left) + { + free(root->dataptr); + newroot=root->right; + free(dltptr); + *success=true; + return newroot; + } + else if(!root->right) + { + newroot=root->left; + free(dltptr); + *success=true; + return newroot; + } + else + { + exchptr=root->left; + while(exchptr->right) + exchptr=exchptr->right; + + holdptr=root->dataptr; + root->dataptr=exchptr->dataptr; + exchptr->dataptr=holdptr; + root->left=_delete(tree,root->left,exchptr->dataptr,success); + } + } + return root; +} + +//Retrieve BST +void *BST_Retrieve(BST_TREE *tree, void *keyptr) +{ + if(tree->root) + return _retrieve(tree, keyptr, tree->root); + else + return NULL; +} + +//INTERNAL Retrieve +void *_retrieve(BST_TREE *tree, void *dataptr, NODE *root) +{ + if(root) + { + if(tree->compare(dataptr, root->dataptr)<0) + return _retrieve(tree, dataptr, root->right); + else if(tree->compare(dataptr,root->dataptr)>0) + return _retrieve(tree, dataptr, root->left); + else + return root->dataptr; + } + else + return NULL; +} + +//Traverse BST +void BST_Traverse(BST_TREE *tree, void(*process)(void*dataptr)) +{ + _traverse(tree->root, process); + return; +} + +//INTERNAL Traverse +void _traverse(NODE *root, void(*process)(void *dataptr)) +{ + if(root) + { + _traverse(root->left, process); + process(root->dataptr); + _traverse(root->right, process); + } + return; +} + +//Empty BST +bool BST_Empty(BST_TREE *tree) +{ + return(tree->count==0); +} + +//Full BST +bool BST_Full(BST_TREE *tree) +{ + NODE *newptr; + newptr=(NODE*)malloc(sizeof(*(tree->root))); + if(newptr) + { + free(newptr); + return false; + } + else + return true; +} + +//Count BST +int BST_Count(BST_TREE *tree) +{ + return (tree->count); +} + +//Destroy BST +BST_TREE *BST_Destroy(BST_TREE *tree) +{ + if(tree) + _destroy(tree->root); + free(tree); + return NULL; +} + +//INTERNAL Destroy +void _destroy(NODE *root) +{ + if(root) + { + _destroy(root->left); + free(root->dataptr); + _destroy(root->right); + free(root); + } + return; +} + + + diff --git a/Basic C Programs/BinarySearchTree/obj/Debug/main.o b/Basic C Programs/BinarySearchTree/obj/Debug/main.o new file mode 100644 index 0000000..85d9ff2 Binary files /dev/null and b/Basic C Programs/BinarySearchTree/obj/Debug/main.o differ diff --git a/Basic C Programs/alpha-singlylinkedlist/alpha-singlylinkedlist.cbp b/Basic C Programs/alpha-singlylinkedlist/alpha-singlylinkedlist.cbp new file mode 100644 index 0000000..1c787bd --- /dev/null +++ b/Basic C Programs/alpha-singlylinkedlist/alpha-singlylinkedlist.cbp @@ -0,0 +1,43 @@ + + + + + + diff --git a/Basic C Programs/alpha-singlylinkedlist/alpha-singlylinkedlist.depend b/Basic C Programs/alpha-singlylinkedlist/alpha-singlylinkedlist.depend new file mode 100644 index 0000000..f3f489c --- /dev/null +++ b/Basic C Programs/alpha-singlylinkedlist/alpha-singlylinkedlist.depend @@ -0,0 +1,5 @@ +# depslib dependency file v1.0 +1573855023 source:f:\cprograms\alpha-singlylinkedlist\main.c + + + diff --git a/Basic C Programs/alpha-singlylinkedlist/alpha-singlylinkedlist.layout b/Basic C Programs/alpha-singlylinkedlist/alpha-singlylinkedlist.layout new file mode 100644 index 0000000..446a510 --- /dev/null +++ b/Basic C Programs/alpha-singlylinkedlist/alpha-singlylinkedlist.layout @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Basic C Programs/alpha-singlylinkedlist/bin/Debug/alpha-singlylinkedlist.exe b/Basic C Programs/alpha-singlylinkedlist/bin/Debug/alpha-singlylinkedlist.exe new file mode 100644 index 0000000..af7754f Binary files /dev/null and b/Basic C Programs/alpha-singlylinkedlist/bin/Debug/alpha-singlylinkedlist.exe differ diff --git a/Basic C Programs/alpha-singlylinkedlist/main.c b/Basic C Programs/alpha-singlylinkedlist/main.c new file mode 100644 index 0000000..faf01bd --- /dev/null +++ b/Basic C Programs/alpha-singlylinkedlist/main.c @@ -0,0 +1,105 @@ +#include +#include + +struct list +{ + int count; + struct node *head; // pointers for the nodes / / + struct node *pnew; + struct node *ploc; + struct node *ppre; +}; + +struct node +{ + char empname[15]; + struct node *link; +}; + +int main() +{ + int a,b,c; + char nameofthelist[20]; + printf("Hello world!\n"); + + printf("DO YOU WANT TO CREATE A SINGLY LINKED LIST(1/0)"); + scanf("%d",&a); + + struct list *lst; + lst=(struct list *)malloc(sizeof(struct list)); + lst->count=0; + lst->head=NULL; + lst->ploc=NULL; + lst->pnew=NULL; + lst->ppre=NULL; + + if(a==1) + { + while(1) + { + printf("ENTER THE NAME OF THE LIST.\n"); + scanf("%s",nameofthelist); + printf("ENTER THE OPTION AS REQUIRED \n"); + + printf("1. ADD ITEM TO THE LIST.\n"); + printf("2. DELETE AN ITEM ON THE LIST.\n"); + printf("3. PRINT THE WHOLE LIST.\n"); + printf("4. EXIT THE PROGRAM.\n"); + scanf("%d",&b); + + switch(b) + { + case 1: + { + struct node *nnew,*nloc; + nnew=(struct node *)malloc(sizeof(struct node)); + printf("ENTER THE DATA TO BE INSERTED IN THE LIST \n"); + scanf("%s",nnew->empname); + for(c=1;c<=lst->count;c++) + { + + } + break; + } + case 2: + { + + break; + } + case 3: + { + + break; + } + case 4: + { + printf("---------------------------\n"); + printf("EXIT SUCCESSFULL\n"); + printf("---------------------------\n"); + printf("\n THANK YOU FOR USING THIS PIECE OF SOFTWARE :)\n\n"); + printf(" BY :-\n"); + printf(" ROHAN R K \n"); + printf(" INDIA(+91)\n"); + printf(" 8762248660\n"); + exit(1); + } + default: + { + printf("---------------------------\n"); + printf("PLEASE ENTER A VALID OPTION\n"); + printf("---------------------------\n"); + break; + } + } + } + } + else + { + printf("\nTHANK YOU FOR USING THIS PIECE OF SOFTWARE\n\n"); + printf(" BY :-\n"); + printf(" ROHAN R K \n"); + printf(" INDIA(+91)\n"); + printf(" 8762248660\n"); + exit(1); + } +} diff --git a/Basic C Programs/alpha-singlylinkedlist/obj/Debug/main.o b/Basic C Programs/alpha-singlylinkedlist/obj/Debug/main.o new file mode 100644 index 0000000..c0742d5 Binary files /dev/null and b/Basic C Programs/alpha-singlylinkedlist/obj/Debug/main.o differ diff --git a/Basic C Programs/alphatest/alphatest.cbp b/Basic C Programs/alphatest/alphatest.cbp new file mode 100644 index 0000000..47fa3c0 --- /dev/null +++ b/Basic C Programs/alphatest/alphatest.cbp @@ -0,0 +1,43 @@ + + + + + + diff --git a/Basic C Programs/alphatest/alphatest.depend b/Basic C Programs/alphatest/alphatest.depend new file mode 100644 index 0000000..9c805b6 --- /dev/null +++ b/Basic C Programs/alphatest/alphatest.depend @@ -0,0 +1,7 @@ +# depslib dependency file v1.0 +1573976378 source:f:\cprograms\alphatest\main.c + + + + + diff --git a/Basic C Programs/alphatest/alphatest.layout b/Basic C Programs/alphatest/alphatest.layout new file mode 100644 index 0000000..d1b81cf --- /dev/null +++ b/Basic C Programs/alphatest/alphatest.layout @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Basic C Programs/alphatest/bin/Debug/alphatest.exe b/Basic C Programs/alphatest/bin/Debug/alphatest.exe new file mode 100644 index 0000000..d3aab79 Binary files /dev/null and b/Basic C Programs/alphatest/bin/Debug/alphatest.exe differ diff --git a/Basic C Programs/alphatest/main.c b/Basic C Programs/alphatest/main.c new file mode 100644 index 0000000..2552a51 --- /dev/null +++ b/Basic C Programs/alphatest/main.c @@ -0,0 +1,109 @@ +/******************************************************************* + PROGRAM TO SORT NAMES ALPHABETICALLY USING LINKED LIST +****************************************************************/ + +/*This program takes a set of strings as input and sorts them alphabetically before displaying */ +#include +#include +#include +#include + + void create(void); + void disp(void); + void sort(void); + +struct name + { + char info[20]; + struct name *link; + }*ptr,*start,*node; + +typedef struct name list; + +int main() + { + + // clrscr(); + printf("Program to enter the names and sort them using linked list.\n"); + create(); //fun to enter the names + printf(" The contents of the list were : \n"); + disp(); //fun to display the data + sort(); //fun to sort the data + printf("\n\nAfter sorting :\n"); + printf("The contents of the list are :"); + disp(); + getch(); + } + + + + + + + + + + +//------------------------------------------- +void create(void) + { + char ch='y'; + node=(list *)malloc(sizeof(list)); + start=node; + while(ch=='y') + { + printf("Enter the name :\n"); + gets(node->info); + ptr=node; + node=(list *)malloc(sizeof(list)); + ptr->link=node; + printf("Want to continue?(y/n)"); + fflush(stdin); + scanf("%c",&ch); + if(ch=='n') + break; + ch='y'; + } + ptr->link=NULL; + } + +//------------------------------------------- + + void disp(void) + { + ptr=start; + while(ptr!=NULL) + { + printf("\n%s",ptr->info); + ptr=ptr->link; + } + } + +//------------------------------------------- + + void sort(void) + { + int comp(char [],char []); + int i; + char temp[20],s1[20],s2[20]; + list *ptr2; + for(ptr=start;ptr!=NULL;ptr=ptr->link) + { + for(ptr2=ptr->link;ptr2!=NULL;ptr2=ptr2->link) + { + strcpy(s1,ptr->info); + strcpy(s2,ptr2->info); + i=comp(s1,s2); + if(i==1) + { + strcpy(temp,ptr->info); + strcpy(ptr->info,ptr2->info); + strcpy(ptr2->info,temp); + } + } +} +} +//------------------------------------------- +int comp(char s1[], char s2[]) { + return (strcmp(s1,s2)); +} diff --git a/Basic C Programs/alphatest/obj/Debug/main.o b/Basic C Programs/alphatest/obj/Debug/main.o new file mode 100644 index 0000000..a4a0b0c Binary files /dev/null and b/Basic C Programs/alphatest/obj/Debug/main.o differ diff --git a/Basic C Programs/bubble_sort/bin/Debug/bubble_sort.exe b/Basic C Programs/bubble_sort/bin/Debug/bubble_sort.exe new file mode 100644 index 0000000..5767ef5 Binary files /dev/null and b/Basic C Programs/bubble_sort/bin/Debug/bubble_sort.exe differ diff --git a/Basic C Programs/bubble_sort/bubble_sort.cbp b/Basic C Programs/bubble_sort/bubble_sort.cbp new file mode 100644 index 0000000..3b8a265 --- /dev/null +++ b/Basic C Programs/bubble_sort/bubble_sort.cbp @@ -0,0 +1,44 @@ + + + + + + diff --git a/Basic C Programs/bubble_sort/bubble_sort.depend b/Basic C Programs/bubble_sort/bubble_sort.depend new file mode 100644 index 0000000..c9029d9 --- /dev/null +++ b/Basic C Programs/bubble_sort/bubble_sort.depend @@ -0,0 +1,5 @@ +# depslib dependency file v1.0 +1596631002 source:c:\users\user\desktop\bubble_sort\main.c + + + diff --git a/Basic C Programs/bubble_sort/bubble_sort.layout b/Basic C Programs/bubble_sort/bubble_sort.layout new file mode 100644 index 0000000..93253f6 --- /dev/null +++ b/Basic C Programs/bubble_sort/bubble_sort.layout @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Basic C Programs/bubble_sort/main.c b/Basic C Programs/bubble_sort/main.c new file mode 100644 index 0000000..4810bfc --- /dev/null +++ b/Basic C Programs/bubble_sort/main.c @@ -0,0 +1,39 @@ +#include +#include +void swap(int* a,int* b){ + int temp=*a; + *a=*b; + *b=temp; +} + +int bubbleSort(int arr[], int n){ + for (int i=0;i +void main() +{ + int a,b,lcm,gcd,num,rem,den; + printf("enter the numbers"); + scanf("%d %d",&a,&b); + if(a>b) + { + num=b + den=a + } + else + { + num=a + den=b + rem=num%den; + while(rem==0) + if + { + rem=den; + printf("gcd of two numbers %d/n",gcd); + } + while(rem!=o) + lcm=(a*b)%gcd; + printf("lcm of two nuimbers %d/n",lcm); +} diff --git a/Basic C Programs/gcd and lcm/gcd and lcm.cbp b/Basic C Programs/gcd and lcm/gcd and lcm.cbp new file mode 100644 index 0000000..4ce6517 --- /dev/null +++ b/Basic C Programs/gcd and lcm/gcd and lcm.cbp @@ -0,0 +1,40 @@ + + + + + + diff --git a/Basic C Programs/gcd and lcm/gcd and lcm.depend b/Basic C Programs/gcd and lcm/gcd and lcm.depend new file mode 100644 index 0000000..c4ac310 --- /dev/null +++ b/Basic C Programs/gcd and lcm/gcd and lcm.depend @@ -0,0 +1 @@ +# depslib dependency file v1.0 diff --git a/Basic C Programs/gcd and lcm/gcd and lcm.layout b/Basic C Programs/gcd and lcm/gcd and lcm.layout new file mode 100644 index 0000000..593c06e --- /dev/null +++ b/Basic C Programs/gcd and lcm/gcd and lcm.layout @@ -0,0 +1,5 @@ + + + + + diff --git a/Basic C Programs/tax/income tax.c b/Basic C Programs/tax/income tax.c new file mode 100644 index 0000000..278e312 --- /dev/null +++ b/Basic C Programs/tax/income tax.c @@ -0,0 +1,20 @@ +#include +void main() +{ + float income,tax; + printf("enter the income"); + scanf("%f",&income); + if(income<=250000) + tax=0; + else + if(income>250000 && income<=500000) + tax=0.1*(income-250000); + else + if(income>500000 && income<=1000000) + tax=0.2*(income-500000)+25000; + else + if(income>1000000) + tax=0.3*(income-1000000)+125000; + printf("your income amount is Rs% 2f",income); + printf("you have pay the tax Rs% 2f",tax); +}