Algorithms_in_C
1.0.0
Set of algorithms implemented in C.
|
Client side implementation of Server-Client system.
More...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#include <unistd.h>
|
#define | MAX 80 |
| max. More...
|
|
#define | PORT 8080 |
| port number to connect to
|
|
#define | SA struct sockaddr |
| shortname for sockaddr
|
|
|
void | func (int sockfd) |
| Continuous loop to send and receive over the socket. More...
|
|
int | main () |
| Driver code.
|
|
Client side implementation of Server-Client system.
- Author
- Nairit11
-
Krishna Vedala
- See also
- client_server/server.c
◆ MAX
max.
characters per message
◆ func()
Continuous loop to send and receive over the socket.
Exits when "exit" is sent from commandline.
- Parameters
-
sockfd | socket handle number |
43 bzero(buff,
sizeof(buff));
44 printf(
"Enter the string : ");
46 while ((buff[n++] = getchar()) !=
'\n')
50 write(sockfd, buff,
sizeof(buff));
51 bzero(buff,
sizeof(buff));
52 read(sockfd, buff,
sizeof(buff));
53 printf(
"From Server : %s", buff);
54 if ((strncmp(buff,
"exit", 4)) == 0)
56 printf(
"Client Exit...\n");
int main(int argc, const char *argv[])
Driver Code.
Definition: selection_sort.c:69
unsigned long get_next_abundant(unsigned long N)
Find the next abundant number after N and not including N.
Definition: sol1.c:55
char is_prime(unsigned long n)
Function to check if a number is prime.
Definition: sol1.c:11
int main()
Main function.
Definition: sol1.c:12
void swap(int *a, int *b)
Swap two integer variables.
Definition: merge_sort.c:17
int main()
Main function.
Definition: jump_search.c:81
int main(void)
Main function.
Definition: merge_sort.c:101
int is_palindromic(unsigned int n)
Check if number is palindromic.
Definition: sol.c:12
uint64_t sigma2(uint64_t N)
compute sum of squares of all integer factors of a number
Definition: sol1.c:93
uint8_t N2
block of elements
Definition: sudoku_solver.c:36
static void test()
Test function.
Definition: insertion_sort.c:36
uint64_t get_divisors(uint64_t N, uint64_t *D)
Get all integer divisors of a number.
Definition: sol1.c:47
#define EPSILON
accuracy tolerance limit
Definition: qr_eigen_values.c:20
int compare(const void *a, const void *b)
comparison function for use with internal qsort algorithm
Definition: sol1.c:19
int jump_search(const int *arr, int x, size_t n)
Implement Jump-search algorithm.
Definition: jump_search.c:24
void shell_sort(char data[][MAX_NAME_LEN], int LEN)
Alphabetical sorting using 'shell sort' algorithm.
Definition: sol1.c:20
long long int get_product(FILE *fp, long start_pos, int num_digits)
Compute the product of two numbers in a file.
Definition: sol1.c:16
int main(int argc, char **argv)
main function
Definition: qr_eigen_values.c:315
static unsigned int divisors[]
Hack to store divisors between 1 & 20.
Definition: sol2.c:21
static void test()
Test function.
Definition: selection_sort.c:50
Definition: prime_factoriziation.c:25
void modifiedBinarySearch(const int **mat, int n, int m, int x)
Function to perform binary search on the mid values of row to get the desired pair of rows where the ...
Definition: modified_binary_search.c:48
void test()
Test implementation of the function.
Definition: jump_search.c:58
void display(const int *arr, int n)
Display elements of array.
Definition: bubble_sort.c:17
char get_perfect_number(unsigned long N)
Definition: sol2.c:31
unsigned long lcm(unsigned long a, unsigned long b)
Compute Least Common Multiple (LCM) of two numbers.
Definition: sol3.c:41
void lazy_sort(char data[][MAX_NAME_LEN], int LEN)
Alphabetical sorting using 'lazy sort' algorithm.
Definition: sol1.c:48
int main()
Main function.
Definition: so1.c:17
int main(void)
Main function.
Definition: sol.c:25
Node, the basic data structure in the tree.
Definition: binary_search_tree.c:15
#define MAX_NAME_LEN
Maximum length of each name.
Definition: sol1.c:15
static char check_number(unsigned long long n)
Pretty naive implementation.
Definition: sol1.c:18
#define min(X, Y)
Macro to return the minimum of two values.
Definition: jump_search.c:13
void bead_sort(int *a, size_t len)
This is where the sorting of the array takes place.
Definition: bead_sort.c:37
void stats_computer1(float x, float *mean, float *variance, float *std)
continuous mean and variance computance using first value as an approximation for the mean.
Definition: realtime_stats.c:24
#define MOD_LIMIT
modulo limit
Definition: sol1.c:17
void test2()
test function to compute eigen values of a 2x2 matrix
Definition: qr_eigen_values.c:271
char remove_digits(big_int *digit, int N)
Function to remove digits preceeding the current digit.
Definition: sol1.c:76
int main()
Main function.
Definition: sol3.c:14
uint8_t N
number of elements
Definition: sudoku_solver.c:35
char value
tens place (single digit)
Definition: sol1.c:19
void qr_decompose(double **A, double **Q, double **R, int M, int N)
Decompose matrix using Gram-Schmidt process.
Definition: qr_decompose.h:142
int add_numbers(uint8_t *a, uint8_t *b, uint8_t N)
Function to add arbitrary length decimal integers stored in an array.
Definition: sol1.c:48
char get_month_days(short month)
Function to get the number of days in a month.
Definition: sol1.c:15
int data
data of the node
Definition: binary_search_tree.c:18
#define MAX_NAMES
Maximum number of names to store.
Definition: sol1.c:14
char is_in(uint64_t N, uint64_t *D, uint64_t L)
Check if a number is present in given array.
Definition: sol1.c:28
int data
stores the number
Definition: threaded_binary_trees.c:28
unsigned long get_next_abundant(unsigned long N)
Find the next abundant number after N and not including N.
Definition: sol2.c:70
Node, the basic data structure of the tree.
Definition: threaded_binary_trees.c:27
void test1()
test function to compute eigen values of a 2x2 matrix
Definition: qr_eigen_values.c:224
void swap(int *first, int *second)
Swapped two numbers using pointer.
Definition: selection_sort.c:16
void test_function(const float *test_data, const int number_of_samples)
Test the algorithm implementation.
Definition: realtime_stats.c:92
#define MAX_DIGITS
maximum number of digits
Definition: sol1.c:13
unsigned long long sum_of_primes(unsigned long N)
Computes sum of prime numbers less than N.
Definition: sol1.c:21
void bubbleSort(int *arr, int size)
Bubble sort algorithm implements using recursion.
Definition: bubble_sort_recursion.c:29
void merge(int *a, int l, int r, int n)
Perform merge of segments.
Definition: merge_sort.c:33
int main()
Driver code.
Definition: client.c:70
Library functions to compute QR decomposition of a given matrix.
void swap(int *first, int *second)
Swap two values by using pointer.
Definition: bubble_sort.c:31
struct _big_int * next_digit
hundreds place
Definition: sol1.c:20
unsigned int get_digits(unsigned char *number)
Get number of digits in a large number.
Definition: sol1.c:75
void insertionSort(int *arr, int size)
Insertion sort algorithm implements.
Definition: insertion_sort.c:16
unsigned long is_abundant(unsigned long N)
Is the given number an abundant number (1) or not (0)
Definition: sol1.c:47
void print_matrix(double **A, int M, int N)
function to display matrix on stdout
Definition: qr_decompose.h:22
int print_number(uint8_t *number, uint8_t N, int8_t num_digits_to_print)
Function to print a long number.
Definition: sol1.c:92
void test()
Test function.
Definition: bubble_sort.c:70
unsigned long sum_of_divisors(unsigned int N)
function to return the sum of proper divisors of N
Definition: sol1.c:13
int binarySearch(const int **mat, int i, int j_low, int j_high, int x)
This function does Binary search for x in i-th row from j_low to j_high.
Definition: modified_binary_search.c:18
uint64_t sigma(uint64_t N)
sum of squares of factors of numbers from 1 thru N
Definition: sol1.c:114
char isprime(int no)
Check if the given number is prime.
Definition: sol1.c:15
struct _big_int big_int
store arbitratily large integer values as a linked list of digits.
int main(void)
main function
Definition: qr_decomposition.c:18
#define MAX_LENGTH
chunk size of array allocation
Definition: sol1.c:18
int main(int argc, char **argv)
Main function.
Definition: realtime_stats.c:128
int main()
Driver Code.
Definition: bubble_sort_recursion.c:72
double ** mat_mul(double **A, double **B, double **OUT, int R1, int C1, int R2, int C2)
Perform multiplication of two matrices.
Definition: qr_eigen_values.c:59
#define MAX_LEN
length of resulting recurring fraction number
Definition: sol1.c:15
void display(const int *arr, int n)
Displays the array, passed to this method.
Definition: bead_sort.c:23
int main(void)
Main function.
Definition: binary_search.c:105
#define MAX
max.
Definition: client.c:28
#define min(a, b)
shorthand for minimum value
Definition: kohonen_som_topology.c:43
struct _big_int * prev_digit
units place
Definition: sol1.c:21
store arbitratily large integer values as a linked list of digits.
Definition: sol1.c:18
int main()
Main function.
Definition: sol2.c:15
long count_divisors(long long n)
Get number of divisors of a given number.
Definition: sol1.c:19
#define max(a, b)
shorthand for maximum value
Definition: kohonen_som_topology.c:39
#define MAX_DENO
limit of unit fractions
Definition: sol1.c:14
void stats_computer2(float x, float *mean, float *variance, float *std)
continuous mean and variance computance using Welford's algorithm (very accurate)
Definition: realtime_stats.c:61
char is_abundant(unsigned long N)
Is the given number an abundant number (1) or not (0)
Definition: sol2.c:59
void display(double **A, int N)
Function to display square matrix.
Definition: lu_decompose.c:66
static int check_number(unsigned long long n)
Checks if a given number is devisable by every number between 1 and 20.
Definition: sol2.c:30
unsigned long long number_of_paths(int N)
At every node, there are 2 possible ways to move -> down or right.
Definition: sol1.c:17
char is_sum_of_abundant(unsigned long N)
check if a given number can be represented as a sum of two abundant numbers.
Definition: sol2.c:87
int get_number(FILE *fp, char *buffer, uint8_t *out_int)
Function to read the number from a file and store it in array.
Definition: sol1.c:16
void show_data(int *arr, long len)
Helper function to print array values.
Definition: shell_sort2.c:16
int main(int argc, const char *argv[])
Driver Code.
Definition: bubble_sort.c:89
uint8_t * a
matrix as a flattened 1D row-major array
Definition: sudoku_solver.c:34
long long collatz(long long start_num)
Computes the length of collatz sequence for a given starting number.
Definition: sol1.c:27
void test()
Test function.
Definition: bubble_sort_recursion.c:53
int main(int argc, const char *argv[])
Main function.
Definition: bead_sort.c:75
int main(int argc, char *argv[])
Main function.
Definition: shell_sort2.c:66
void test()
Test implementations.
Definition: binary_search.c:75
int main()
Main function.
Definition: sol4.c:12
struct node node
Node, the basic data structure in the tree.
unsigned long gcd(unsigned long a, unsigned long b)
Compute Greatest Common Divisor (GCD) of two numbers using Euclids algorithm.
Definition: sol3.c:18
int main()
Main function.
Definition: modified_binary_search.c:97
big_int * add_digit(big_int *digit, char value)
Function that allocates memory to add another digit at the MSB.
Definition: sol1.c:37
void merge_sort(int *a, int n, int l, int r)
Merge sort algorithm implementation.
Definition: merge_sort.c:82
#define LIMS
limit of range of matrix values
Definition: qr_eigen_values.c:19
int binarysearch2(const int *arr, int l, int r, int x)
Iterative implementation.
Definition: binary_search.c:51
double eigen_values(double **A, double *eigen_vals, int mat_size, char debug_print)
Compute eigen values using iterative shifted QR decomposition algorithm as follows:
Definition: qr_eigen_values.c:106
#define BEAD(i, j)
Create easy access of elements from a 2D matrix stored in memory as a 1D array.
Definition: bead_sort.c:16
void shell_sort(int *array, long LEN)
Shell sort algorithm.
Definition: shell_sort2.c:41
void swap(int *first, int *second)
Swapped two numbers using pointer.
Definition: bubble_sort_recursion.c:17
char is_leap_year(short year)
Check if input year is a leap year.
Definition: sol1.c:41
char get_perfect_number(unsigned long N)
Returns: -1 if N is deficient 1 if N is abundant 0 if N is perfect.
Definition: sol1.c:19
Definition: multikey_quick_sort.c:205
void bubbleSort(int *arr, int size)
Bubble sort algorithm implementation.
Definition: bubble_sort.c:43
char is_sum_of_abundant(unsigned long N)
check if a given number can be represented as a sum of two abundant numbers.
Definition: sol1.c:71
void create_matrix(double **A, int N)
create a square matrix of given size with random elements
Definition: qr_eigen_values.c:27
void print(CantorSet *head)
Print sets in the current range to stdout
Definition: cantor_set.c:55
void selectionSort(int *arr, int size)
Selection sort algorithm implements.
Definition: selection_sort.c:28
char * abundant_flags
This is the global array to be used to store a flag to identify if a particular number is abundant (1...
Definition: sol2.c:24
int binarysearch1(const int *arr, int l, int r, int x)
Recursive implementation.
Definition: binary_search.c:21