diff --git a/c-programs-main/FullTreeCheck.c b/c-programs-main/FullTreeCheck.c new file mode 100644 index 00000000..ba633ab5 --- /dev/null +++ b/c-programs-main/FullTreeCheck.c @@ -0,0 +1,79 @@ +#include +#include +#include + +typedef struct Node{ + int data; + struct Node *left,*right; +}Node; + +Node* createNode(int data){ + Node* temp = (Node*)malloc(sizeof(Node)); + temp->data = data; + temp->left = NULL; + temp->right = NULL; + return temp; +} + +void linker(Node* left,Node* parent,Node* right){ + parent->left = left; + parent->right = right; +} + +bool preOrder(Node* root){ + if(!root) + return false; + printf("%d\n",root->data); + preOrder(root->left); + preOrder(root->right); + return true; +} + +bool inOrder(Node* root){ + if(!root) + return false; + printf("%d\n",root->data); + inOrder(root->left); + inOrder(root->right); + return true; +} + +bool postOrder(Node* root){ + if(!root) + return false; + printf("%d\n",root->data); + postOrder(root->left); + postOrder(root->right); + return true; +} + +bool checkFullTree(Node* root){ + if(root==NULL) + return true; + if(root->left==NULL && root->right==NULL) + return true; + if(root->left && root->right) + return checkFullTree(root->left) && checkFullTree(root->right); + return false; +} + +int main(){ + Node* n1 = createNode(12); + Node* n2 = createNode(11); + Node* n3 = createNode(14); + Node* n4 = createNode(18); + Node* n5 = createNode(120); + Node* n6 = createNode(121); + Node* n7 = createNode(124); + Node* n8 = createNode(22); + Node* n9 = createNode(28); + linker(n2,n1,n3); + linker(n4,n2,n5); + linker(n6,n3,n7); + linker(n9,n6,n8); + if(checkFullTree(n1)) + printf("It is a full tree\n"); + else + printf("Not a full tree\n"); + return(0); +} diff --git a/c-programs-main/c-examples/example-1.c b/c-programs-main/c-examples/example-1.c new file mode 100644 index 00000000..4a4f6f45 --- /dev/null +++ b/c-programs-main/c-examples/example-1.c @@ -0,0 +1,8 @@ +// C "Hello, World!" Program + +#include + +int main(){ + puts("Hello World!!"); + return(0); +} \ No newline at end of file diff --git a/c-programs-main/c-examples/example-10.c b/c-programs-main/c-examples/example-10.c new file mode 100644 index 00000000..a65ac73c --- /dev/null +++ b/c-programs-main/c-examples/example-10.c @@ -0,0 +1,33 @@ +// complex number + +#include + +typedef struct { + double real; + double imag; +}complex; + +complex add(complex a,complex b){ + complex c; + c.real = a.real+b.real; + c.imag = a.imag+b.imag; + return c; +} + +void print(complex a){ + printf("%.2lf + i%.2lf\n",a.real,a.imag); +} + +void input(complex *ptr){ + printf("Enter the number(use ',') : "); + scanf("%lf,%lf",&ptr->real,&ptr->imag); +} + +int main(){ + complex num1,num2; + input(&num1); + input(&num2); + complex sum = add(num1,num2); + print(sum); + return(0); +} \ No newline at end of file diff --git a/c-programs-main/c-examples/example-2.c b/c-programs-main/c-examples/example-2.c new file mode 100644 index 00000000..cf6e4537 --- /dev/null +++ b/c-programs-main/c-examples/example-2.c @@ -0,0 +1,11 @@ +// C Program to Print an Integer (Entered by the User) + +#include + +int main(){ + int integer; + printf("Enter the number : "); + scanf("%d",&integer); + printf("You entered : %d\n",integer); + return(0); +} \ No newline at end of file diff --git a/c-programs-main/c-examples/example-3.c b/c-programs-main/c-examples/example-3.c new file mode 100644 index 00000000..bfeed4ca --- /dev/null +++ b/c-programs-main/c-examples/example-3.c @@ -0,0 +1,12 @@ +// C Program to Add Two Integers + +#include + +int main(){ + int num1,num2,sum; + printf("Enter the numbers : "); + scanf("%d,%d",&num1,&num2); + sum = num1+num2; + printf("%d + %d = %d\n",num1,num2,sum); + return(0); +} \ No newline at end of file diff --git a/c-programs-main/c-examples/example-4.c b/c-programs-main/c-examples/example-4.c new file mode 100644 index 00000000..71c24d30 --- /dev/null +++ b/c-programs-main/c-examples/example-4.c @@ -0,0 +1,12 @@ +// C Program to Multiply Two Floating-Point Numbers + +#include + +int main(){ + float num1,num2,product; + printf("Enter the numbers(use ',') : "); + scanf("%f,%f",&num1,&num2); + product = num1*num2; + printf("%.2f x %.2f = %.2f\n",num1,num2,product); + return(0); +} \ No newline at end of file diff --git a/c-programs-main/c-examples/example-5.c b/c-programs-main/c-examples/example-5.c new file mode 100644 index 00000000..fbe97a4b --- /dev/null +++ b/c-programs-main/c-examples/example-5.c @@ -0,0 +1,11 @@ +// C Program to Find ASCII Value of a Character + +#include + +int main(){ + char symbol; + printf("Enter the symbol : "); + scanf("%c",&symbol); + printf("ASCII value of %c is %d\n",symbol,symbol); + return(0); +} \ No newline at end of file diff --git a/c-programs-main/c-examples/example-6.c b/c-programs-main/c-examples/example-6.c new file mode 100644 index 00000000..cc2b3927 --- /dev/null +++ b/c-programs-main/c-examples/example-6.c @@ -0,0 +1,19 @@ +// C Program to Compute Quotient and Remainder + +#include +int main() { + int dividend, divisor, quotient, remainder; + printf("Enter dividend: "); + scanf("%d", ÷nd); + printf("Enter divisor: "); + scanf("%d", &divisor); + + quotient = dividend / divisor; + + remainder = dividend % divisor; + + printf("Quotient = %d\n", quotient); + printf("Remainder = %d\n", remainder); + return (0); +} + diff --git a/c-programs-main/c-examples/example-7.c b/c-programs-main/c-examples/example-7.c new file mode 100644 index 00000000..35d6f04b --- /dev/null +++ b/c-programs-main/c-examples/example-7.c @@ -0,0 +1,11 @@ +// C Program to Find the Size of int, float, double and char + +#include + +int main(){ + printf("Size of Int is %d bytes\n",sizeof(int)); + printf("Size of float is %d bytes\n",sizeof(float)); + printf("Size of double is %d bytes\n",sizeof(double)); + printf("Size of char is %d byte\n",sizeof(char)); + return(0); +} \ No newline at end of file diff --git a/c-programs-main/c-examples/example-8.c b/c-programs-main/c-examples/example-8.c new file mode 100644 index 00000000..96af9a63 --- /dev/null +++ b/c-programs-main/c-examples/example-8.c @@ -0,0 +1,40 @@ +// various function/ways to to Swap Two Numbers + +#include + +void swap1(){ + int a,b,c; + printf("Enter the numbers(use ',') : "); + scanf("%d,%d",&a,&b); + c = a; + a = b; + b = c; + printf("a = %d\nb = %d\n",a,b); +} + +void swap2(){ + int a,b; + printf("Enter the numbers(use ',') : "); + scanf("%d,%d",&a,&b); + a = a+b; + b = a-b; + a = a-b; + printf("a = %d\nb = %d\n",a,b); +} + +void swap3(){ + int a,b; + printf("Enter the numbers(use ',') : "); + scanf("%d,%d",&a,&b); + a = a^b; + b = a^b; + a = a^b; + printf("a = %d\nb = %d\n",a,b); +} + +int main(){ + swap1(); + swap2(); + swap3(); + return(0); +} \ No newline at end of file diff --git a/c-programs-main/c-examples/example-9.c b/c-programs-main/c-examples/example-9.c new file mode 100644 index 00000000..ddc53c51 --- /dev/null +++ b/c-programs-main/c-examples/example-9.c @@ -0,0 +1,14 @@ +// C Program to Check Whether a Number is Even or Odd + +#include + +int main(){ + int number; + printf("Enter the number : "); + scanf("%d",&number); + if(number%2==0) + printf("%d is a even number\n",number); + else + printf("%d is not a even number\n",number); + return(0); +} \ No newline at end of file diff --git a/c-programs-main/games/number_guess.c b/c-programs-main/games/number_guess.c new file mode 100644 index 00000000..e4c5b419 --- /dev/null +++ b/c-programs-main/games/number_guess.c @@ -0,0 +1,32 @@ +#include + +int main(){ + int a = (int)__TIME__[7]-45; + int b = (int)__TIME__[6]-45; + for(int i = 1;i\n"); +printf(" ----------------- \n"); +printf(" \\ ^__^ \n"); +printf(" \\ (oo)\\______\n"); +printf(" (__)\\ )\\/\n"); +printf(" ||----w |\n"); +printf(" || ||\n"); + + break; + } + else if(guess +#include + +#define MIN 1 + +bool checkLeap(int year){ + if(year%400==0) + return true; + else if(year%100==0) + return false; + else if(year%4==0) + return true; + else + return false; +} + +int main(){ + int year; + bool flag; + printf("Enter the year to check : "); + scanf("%d",&year); + if(year + +struct node{ + int data; + struct node* next; +}; + +typedef struct node node; + +int print(node*); + + + +int main(){ + node n1,n2,n3,n4; + node* head; + n1.data = 12; + n2.data = 13; + n3.data = 15; + n4.data = 19; + head = &n1; + n1.next = &n2; + n2.next = &n3; + n3.next = &n4; + n4.next = NULL; + print(head); + return(0); +} + +int print(node* head){ + while(head!=NULL){ + printf("%d\n",head->data); + head = (head->next); + } + + return(0); +} \ No newline at end of file diff --git a/c-programs-main/natural_sum.c b/c-programs-main/natural_sum.c new file mode 100644 index 00000000..c5ec8425 --- /dev/null +++ b/c-programs-main/natural_sum.c @@ -0,0 +1,53 @@ +// various function to find sum of first n natural number + +#include + +int sum1(int number){ + if(number==1) + return 1; + else + return(sum1(number-1)+number); +} + +int sum2(int number){ + return (int)number*(number+1)/2; +} + +int sum3(int number){ + int sum = 0; + for(int i = 1;i +#include + +bool prime1(int number){ + for(int i = 2;i + +int main(){ + double speed , distance , time; + printf("distance(km) = "); + scanf("%lf",&distance); + printf("time(h) = "); + scanf("%lf",&time); + speed = distance/time; + printf("speed = %.2lfkm/h.\n",speed); + + return(0); +} \ No newline at end of file diff --git a/c-programs-main/stack.c b/c-programs-main/stack.c new file mode 100644 index 00000000..1974f614 --- /dev/null +++ b/c-programs-main/stack.c @@ -0,0 +1,63 @@ +#include + +#define LENGTH 10 + +int top = -1; +int stack[LENGTH]; + +void push_stack(int item){ + if(top==LENGTH){ + printf("Stack is full\n\a"); + } + else{ + top+=1; + stack[top] = item; + } +} + +int pop(){ + if(top==-1){ + printf("Stack is Empty\n\a"); + } + else{ + top-=1; + return stack[top+1]; + } +} + +void isEmpty(){ + if(top==-1) + printf("Yes!!\n\a"); + else + printf("No!!\n\a"); +} + +void isFull(){ + if(top==LENGTH) + printf("Yes!!\n\a"); + else + printf("No!!\n\a"); +} + +int displayStack(){ + if(top==-1){ + printf("Empty Stack!!\n\a"); + return(0); + } + printf("%d <----head\n",stack[top]); + for(int i = top-1;i>-1;--i){ + printf("%d\n",stack[i]); + } +} + + +int main(){ + push_stack(12); + push_stack(23); + push_stack(67); + push_stack(1128); + push_stack(444); + pop(); + displayStack(); + return(0); +} \ No newline at end of file diff --git a/c-programs-main/sum_dma.c b/c-programs-main/sum_dma.c new file mode 100644 index 00000000..a33c029d --- /dev/null +++ b/c-programs-main/sum_dma.c @@ -0,0 +1,18 @@ +#include +#include + +int main(){ + int num,*ptr_num,sum = 0; + printf("Enter the number you want to add : "); + scanf("%d",&num); + + for(int i = 0;i +#include +#include +#include + +typedef struct Node{ + int data; + struct Node *left,*right; +}Node; + +Node* createNode(int data){ + Node* temp = (Node*)malloc(sizeof(Node)); + temp->data = data; + temp->left = temp->right = NULL; + return temp; +} + +void linker(Node* left,Node* papa,Node* right){ + papa->left = left; + papa->right = right; +} + +bool checkFullTree(Node* root){ + if(!root) + return true; + if(!(root->left) && !(root->right)) + return true; + if((root->left) && (root->right)) + return checkFullTree(root->left) && checkFullTree(root->right); + return false; +} + +bool order(Node* root){ + if(!root) + return false; + + // pre-order + order(root->left); + order(root->right); + printf("%d\n",root->data); + + // in-order + // order(root->left); + // order(root->right); + // printf("%d\n",root->data); + + // post-order + // order(root->left); + // order(root->right); + // printf("%d\n",root->data); + + return true; +} + + + +int main(){ + Node* n1 = createNode(23); + Node* n2 = createNode(27); + Node* n3 = createNode(3); + Node* n4 = createNode(2); + Node* n5 = createNode(1); + Node* n6 = createNode(225); + Node* n7 = createNode(-1); + Node* n8 = createNode(0); + Node* n9 = createNode(-8); + // Node* n10 = createNode(44); + linker(n2,n1,n3); + linker(n4,n2,n5); + linker(n6,n3,n7); + linker(n8,n4,n9); + order(n1); + // if(checkFullTree(n1)) + // printf("This is a full tree\n"); + // else + // printf("this is not a full tree\n"); + return(0); +}