G

@ganeshchenniah

bubble sort

C
4 years ago
// C program for implementation of Bubble sort #include <stdio.h> void swap(int *xp, int *yp) { int temp = *xp; *xp = *yp; *yp = temp; }

check whether number is palindrome or not

C
4 years ago
#include <stdio.h> int main() { int num,actual,reverse=0; printf("Enter the number to check palindrome!\n"); scanf("%d",&num); actual = num; printf("Entered number is %d\n",num); //Logic to reverse the number while(num!=0){

reverse a number

C
4 years ago
#include <stdio.h> int main() { int num,reverse=0; printf("Enter a number to be reversed\n"); scanf("%d",&num); printf("Number is %d",num); //Logic to reverse a number while(num!=0){ reverse = reverse * 10 + num%10;

text_segment

C
4 years ago
#include <stdio.h> int main() { printf("Text Segment!\n"); /* *char pointer address gets stored in stack but string literal value gets stored text segment which is read only, when you try to modify text segment ,it gives segmentation fault (core dump) , to change the string value you need allocate memory i.e char str[] = "Ganesh" ptr[2] = 'T' gives GaTesh output */

complement sum diff multiply without operators

C
4 years ago
#include <stdio.h> int main() { int x ,y; printf("complement sum diff multiply without operators\n"); //Find complement . ~x = -(x+1); printf("Enter two numbers\n"); scanf("%d %d",&x,&y); printf("Value a %d b %d\n",x,y); //~a = FFFF FFFF FFFF FFF5 = -11

struct vs union

C
4 years ago
#include <stdio.h> struct emptyStr{ }; union emptyUni{ }; struct str{ int a; int b;

swap bytes in 32 bit integer

C
4 years ago
#include <stdio.h> void print_binary(unsigned int number); int main() { printf("Swap integers!\n"); unsigned int n; printf("Enter a number\n"); scanf("%x",&n); printf("The Entered number is %x \n",n); printf("n & 0x000000ff %x\n",(n & 0x000000ff));

toggle a particular bit

C
4 years ago
#include <stdio.h> void print_binary(unsigned int number); int main() { printf("Bitwise Toggle a particular bit!\n"); unsigned int n,pos; printf("Enter a number\n"); scanf("%x",&n); printf("The Entered number is %x ",n); print_binary(n);

clear a particular bit

C
4 years ago
#include <stdio.h> void print_binary(unsigned int number); int main() { printf("Bitwise clear a particular bit!\n"); unsigned int n,pos; printf("Enter a number\n"); scanf("%x",&n); printf("The Entered number is %x ",n); print_binary(n);

set a particular bit

C
4 years ago
#include <stdio.h> void print_binary(unsigned int number); int main() { printf("Bitwise set a particular bit!\n"); unsigned int n,pos; printf("Enter a number\n"); scanf("%x",&n); printf("The Entered number is %x ",n); print_binary(n);

linked_list

C
4 years ago
#include <stdio.h> #include <stdlib.h> //Run this program on https://www.onlinegdb.com/ compiler struct node{ int data; struct node *next; };

sizeof

C
4 years ago
#include <stdio.h> struct node{ int data; struct node *next; }; int main() { /****** 32Bit 64Bit char 1 1

signed

C
4 years ago
#include <stdio.h> int main() { /* Ascii table starts from 0 and end at 127 . So that unsigned char can have all 127 characters signed char is -128 to +127 unsigned char is 0 to 255. In the below example when var1 is -0x127 dec %d prints 127 , when it crosses 128 it prints -127. 127 is delete character */

endianess

C
4 years ago
#include <stdio.h> int main() { /* Little endian Always remember LL0 (little lsb stores in 0 location) If the var prints as it on the console i.e 0x11223344 on console , it is little endian LSB byte gets stored in 0x0 . 44 -> ptr[0] 33 -> ptr[1] 22 -> ptr[2] 00 -> ptr[3]

string_reversal

C
4 years ago
#include <stdio.h> int main() { char str[] = "Ganesh"; char rev[] =""; // int i =0; printf("strlen(str) %d\n",strlen(str)); for(int i=strlen(str)-1;i>=0;i--){ printf("i %d str[%c] \n",i,str[i]);

strcpy_memcpy

C
4 years ago
#include <stdio.h> int main() { char src[10] = "Ganesh"; char dst[10]; int ret = strcpy(dst,src); printf("ret %d src %s dst %s\n",ret,src,dst); /* strcpy copied only till it encounters '\0' . Usually it will be at the end of script . But if you put it in between the string , it copies only till that . Same with strncpy , either it stops till

find_substring

C
4 years ago
#include <stdio.h> int main() { char *ptr = "Ganesha"; char *sub = "ns"; //fInd character 'a' in a given string int i =0,j=0,k=0; while(ptr[i]!='\0'){ printf("ptr[%d] %d\n",i,ptr[i]); k=i,j=0;

find_duplicate_character

C
4 years ago
#include <stdio.h> int main() { char *ptr = "Ganenha"; //fInd character 'a' in a given string int i =0; while(ptr[i]!='\0'){ printf("ptr[%d] %d\n",i,ptr[i]); for(int j=i+1;j<strlen(ptr);j++)

hello_world

C
4 years ago
#include <stdio.h> int main() { printf("Hello world!\n"); return 0; }

linked_list

C
4 years ago
#include <stdio.h> struct node{ int data; struct node *link; }; int main() { printf("Linked List!\n"); create_numberof_nodes_seq(6);