A

@Adarsh222

convert arry to linkedlist

C
1 year ago
#include <stdio.h> #include <stdlib.h> typedef struct Node { int data; struct Node *next; } node; // Function to convert array to linked list node* convertToLL(int arr[], int sz) {

Typedef with struct and enum

C
1 year ago
Here are simple examples of using typedef with both struct and enum to make the code cleaner and easier to understand. Example 1: typedef with struct Instead of writing struct repeatedly, you can use typedef to create an alias for a struct. c Copy Edit #include <stdio.h>

Segmentation Fault

C
1 year ago
#include <stdio.h> int main() { int *ptr = NULL; // Null pointer int var = 6; *ptr = 6; // Dereferencing a null pointer causes segmentation fault // ptr = &var; //correct return 0; }

hexdecimal extract and store imp

C
1 year ago
#include <stdio.h> void printhex(int hex) { int digits[8]; // Assuming the maximum digits needed for a 32-bit integer int i = 0; // Extract hexadecimal digits while (hex != 0) { digits[i] = hex & 0xF; // Extract the last 4 bits (hexadecimal digit) hex = hex >> 4; // Shift right by 4 bits

Insert middle

C
1 year ago
#include <stdio.h> #include <stdlib.h> struct node{ int data; struct node* next; }; void append(struct node **head, int val){ struct node *new_node = (struct node*)malloc(sizeof(struct node));

**store inform of array in single variable

C
2 years ago
#include <stdio.h> #include <stdlib.h> struct node { int data; struct node* next; }; void append(struct node** head_ref, int new_data) { // Allocate memory for the new node and initialize its values

linkedlist sum

C
2 years ago
#include <stdio.h> #include <stdlib.h> struct node{ int data; struct node* next; }; int main() { struct node *a, *b, *c;

Recursion backtracking

C
2 years ago
#include <stdio.h> void findWays(int steps[], int n, int index) { if (n == 0) { for (int i = 0; i < index; i++) printf("%d ", steps[i]); printf("\n"); return; } if (n < 0) return;

optimisation Time complexity

C
2 years ago
#include <stdio.h> int main() { int a; int sum = a+1; printf(); } //O(3);

optimisation Time complexity

C
2 years ago
#include <stdio.h> int main() { int a; int sum = a+1; printf(); } //O(3);

tree

C
2 years ago
#include <stdio.h> #include <stdlib.h> // Definition of the node structure struct Node { int data; struct Node* left; struct Node* right; };

rec

C
2 years ago
#include <stdio.h> void fun(int a){ if(a<=0) return; printf("pre %d\n",a); fun(a-1); printf("in %d\n",a); fun(a-1); printf("out %d\n",a);

merge sort

C
2 years ago
#include <stdio.h> void mergeSort(int arr[], int n) { if (n > 1) { int mid = n / 2; int L[mid], R[n - mid]; for (int i = 0; i < mid; i++) L[i] = arr[i]; for (int i = mid; i < n; i++)

Binary to decimal convert

C
2 years ago
#include <stdio.h> #include <math.h> int main() { long long binary; printf("Enter a binary number: "); scanf("%lld", &binary); int decimal = 0, i = 0, rem; while (binary != 0) {

Convert hexadecimal to decimal

C
2 years ago
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> /* Here is the math using using the steps above showing you how to convert 0X0110 to decimal. 0 × 1 = 0 1 × 16 = 16

Arrange in ascending order all letters

C
2 years ago
#include <stdio.h> int main(){ char a[10] = "adarsh"; for(int i=0;a[i]!='\0';i++){ for(int j=i;a[j]!='\0';j++){ if(a[j]>a[j+1] && a[j+1]!='\0'){ char tmp = a[j]; a[j] = a[j+1];

bubble reverse sort imp

C
2 years ago
#include <stdio.h> int main() { int a[10] = {9, 2, 4, 6, 5, 2, 1}; int c = 7; // Number of elements in the array printf("%d\n", c); for (int i = 0; i < c; i++) { for (int j = 0; j < c - 1 - i; j++) {//imp

Alternate Char caps

C
2 years ago
#include <stdio.h> int main() { char a[10]; scanf("%s",a); for(int i=0;a[i]!='\0';i++){ if(a[i]>='a' && a[i]<='z'){ if(i % 2 == 0){ a[i] = a[i] - ('a' - 'A');// a=97 A=65 ..-32 then all letters become small

Hexadecimal & Binary print no what we need only

C
2 years ago
#include <stdio.h> #if 0 void printh(int hex, int n){ for(int i=n-2;i>=1;i--){ printf("%x", (hex>>4*i)&0xf); } }

Find the required value from hex

C
2 years ago
#include <stdio.h> void printHex(int hex, int no){ for(int i=no-1; i>=0; i--){ printf("%x",(hex>>4*i)&0xF); } printf("\n"); } int main() {