Skip to content

Instantly share code, notes, and snippets.

View outlinepix's full-sized avatar
🎯
Focusing

Viraat Maurya outlinepix

🎯
Focusing
View GitHub Profile
@outlinepix
outlinepix / Linear search Implementation in C using Pointers.
Last active July 21, 2022 17:14
Linear search for integers using pointer.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int compare(void *a, void *b)
{
int * ap = a;
int * bp = b;
return *ap - *bp;
}
void * lsearch(void *key, void *base, int n, int elemsize)
@outlinepix
outlinepix / Linux "wc" command implementation in C language.
Created July 21, 2022 17:22
Linux "wc" command implementation in C language.(Noobish)
/* compile using "gcc -o wc <file.c>" and work just like wc only tested on asci text file*/
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<unistd.h>
FILE * getFileBuffer(char * file_name);
int lineCount(char * filepath);
int wordCount(char * filepath);
@outlinepix
outlinepix / Numbers to Indian currency text conversion in c Under 10 Lines(Noobish)
Created July 22, 2022 14:10
Numbers to Indian currency text conversion in C Language Under 30 Lines(Noobish)
*/ Usage : <a.uot> <Number> ">
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc, char **argv){
int num = atoi(argv[1]);
printf("%d : ", num);
char * oneToText[] = {"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen","Nineteen" };
char * tenToText[] = {"", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"};
@outlinepix
outlinepix / Numbers to Indian currency text conversion in C Language detailed
Last active August 4, 2022 09:38
Numbers to Indian currency text conversion in C Language detailed
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc, char **argv)
{
int num = atoi(argv[1]);
char * oneToText[] = {"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen","Nineteen" };
char * tenToText[] = {"", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"};
char * moreThenHundredToText[] = {"", "Hundred", "Thousand", "Lakhs", "Crore"};
@outlinepix
outlinepix / Find the nth Reverse Number (Extreme) in C language
Created July 29, 2022 11:31
Find the nth Reverse Number (Extreme) in C language
unsigned long long int find_reverse_number(unsigned long long int nth) {
unsigned long long int result = 0, count = 0;
for ( unsigned long long int i = 0; i <= 10000000000; i++)
{
unsigned long long int reversed = 0, remainder;
unsigned long long int n = i;
while (n != 0)
{
remainder = n % 10;
@outlinepix
outlinepix / Next smaller number with the same digits in C language - 4 kyu
Created August 1, 2022 10:55
Next smaller number with the same digits in C language - 4 kyu
/*Doesn't work on 970*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
unsigned long long int next_smaller_number(unsigned long long int number);
int main(int argc, char const *argv[])
{
unsigned long long int result = 0;
@outlinepix
outlinepix / Large Factorials (code wars) in C language.
Created August 1, 2022 12:43
Large Factorials (code wars) in C language.
include<stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char const *argv[])
{
factorial(5);
return 0;
}
char *factorial(int n)
@outlinepix
outlinepix / Fibonacci Sequence using Recursion and Memoization in C language.
Created August 2, 2022 15:35
Fibonacci Sequence using Recursion and Memoization in C language.
/* Program will break after sum reachs to int holding limit which is around 4 billion*/
/* Usage : gcc -o fib <file.c> --std=c99
./fib <number>
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@outlinepix
outlinepix / Counting Coin Change Sum problem using Momoization in C language
Last active August 6, 2022 06:08
Counting Coin Change Sum problem using Recursion and Momoization in C language
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <assert.h>
int *cache(int n);
int canSum(int target, int numbers[], int len, int *memo);
int main(int argc, char const *argv[])
{
assert(canSum(11, (int[]){1, 4}, 2, cache(11)));
@outlinepix
outlinepix / Compare function for qsort() in C language.
Last active August 7, 2022 12:00
Compare function for qsort() in C language. ( Both Ascending and descending order output)
/* IF YOU WANT TO SORT IN DESCENDING ORDER */
int cmp(const void *a, const void *b)
{
const int *A = a, *B = b;
/* a>b => -1, a<b => 1, a==b => 0 */
return (*A < *B) - (*A > *B);
}
/* FOR ASCENDING ORDER SORT*/
int cmp(const void *a, const void *b)