Category: C++ Programs

C program to find the Euclidean distance between two points

Given four integers x1, y1, x2 and y2, which represents two coordinates (x1, y1) and (x2, y2) of a two-dimensional graph. The task is to find the Euclidean distance between these two points.Euclidean distance between two points is the length of a straight line drawn between those two given points.Attention reader! Don’t stop learning now. […]

Continue Reading

How to write in a file using fputs() in C

How to write in a file using fputs() in Cfputs() is a function declared in stdio.h header file. It is used to write the contents of the file. The function takes 2 arguments. The first argument is a pointer to the string which is to be written and the second argument is the name of […]

Continue Reading

Program to implement Hash Table using Open Addressing

#include #include   struct HashNode {    int key;    int value;};  const int capacity = 20;int size = 0;  struct HashNode** arr;struct HashNode* dummy;  void insert(int key, int V){      struct HashNode* temp        = (struct HashNode*)malloc(sizeof(struct HashNode));    temp->key = key;    temp->value = V;              int hashIndex = key % capacity;          while (arr[hashIndex] != NULL           && arr[hashIndex]->key != key           && arr[hashIndex]->key != -1) {        hashIndex++;        hashIndex %= capacity;    }              if (arr[hashIndex] == NULL        || arr[hashIndex]->key == -1)        size++;      arr[hashIndex] = […]

Continue Reading

Program and syntax for iscntrl(int c) function in C

In C, iscntrl() is a predefined function used for string and character handling. ctype is the header file required for character functions. A control character is one that is not a printable character i.e, it does not occupy a printing position on a display.This function is used to check if the argument contains any control […]

Continue Reading

push_back() vs emplace_back() in C++ STL Vectors

push_back() vs emplace_back() in C++ STL VectorsIn C++, vectors are dynamic arrays, that can grow or shrink and their storage is handled by the container itself. There are two ways of inserting an element in a vector. They are push_back() and emplace_back(). In this article, we will discuss the difference between them.push_back():This method is used […]

Continue Reading

Minimum Mex from all subarrays of length K

Given an array arr[] consisting of N distinct positive integers and an integer K, the task is to find the minimum MEX from all subarrays of length K. The MEX is the smallest positive integer that is not present in the array. Examples: Input: arr[] = {1, 2, 3}, K = 2Output: 1Explanation:All subarrays of […]

Continue Reading