Found 1401 Articles for C

C program to compare two files and report mismatches

sudhir sharma
Updated on 19-Sep-2019 09:04:22

8K+ Views

In the C programming language, the programmer can excess the files and read and write content in them.A file is a simple memory block that can store information, here we are concerned with text only.In this program, we will compare two files and report mismatches that occur. These files are almost identical but may have some characters that are different. Also, the program will return the line and position of the file at which the first mismatch occurs.AlgorithmStep 1: Open both the file with pointer at the starting. Step 2: Fetch data from file as characters one by one. Step ... Read More

C program that does not suspend when Ctrl+Z is pressed

sudhir sharma
Updated on 19-Sep-2019 09:01:13

1K+ Views

In Programing when a program malfunction and runs unusually in the terminal compiler the programmer has the power to explicitly stop the program from running. For explicitly stopping the program, the user must know the right keyboard shortcut that is needed to be pressed.To terminate the execution of a block of code, there are two types of keyboard shortcuts used.Ctrl+c − It is used to stop the execution of the program, it take a bit of time to complete the i/o operations and then suspends the execution. It sends a SIGINT signal to the process which gets terminated. In some ... Read More

C Program for Reversal algorithm for array rotation

sudhir sharma
Updated on 19-Sep-2019 08:58:33

2K+ Views

An algorithm is a set of instructions that are performed in order to solve the given problem. Here, we will discuss the reversal algorithm for array rotation and create a program for a reversal algorithm.Now, let's get to some terms that we need to know to solve this problem −Array − A container of elements of the same data type. The size (number of elements) of the array is fixed at the time of the declaration of the array.Array rotation − Rotating an array is changing the order of the elements of the array. Increasing the index of the element ... Read More

Find the area of a circle in C programming.

sudhir sharma
Updated on 19-Sep-2019 08:53:05

12K+ Views

A circle is a closed figure. All the points of the circle are equidistant from a point that lies inside in circle. The point at the center is known as the center of the circle. The distance of points from the center is known as the radius.The area is the quantitative representation of the span of the dimensions of a closed figure.The area of circle is the area enclosed inside the dimensions of a circle.The formula for calculating the area of a circle, Area = π*r*rTo calculate the area we are given the radius of the circle as input and ... Read More

C Program for Number of stopping station problem

sudhir sharma
Updated on 19-Sep-2019 08:49:57

377 Views

Problem statement − A program to find the number of ways in which a train will stop in r stations out of n stations so that no two stopping stations are consecutive.Problem ExplanationThis program will calculate the number of ways i.e. permutations in which the train will stop. Here, the train will travel from point X to Y. Between these points, there are n stations. The train will stop on r stations of these n stations given the conditions that while stopping on r stations the train should not stop in two consecutive stations.This permutation can be found using the ... Read More

What is the Address of a function in C or C++?

sudhir sharma
Updated on 19-Sep-2019 08:44:02

2K+ Views

A function is a block of code that is defined to perform a specific piece of work in a program. It is used to ease the work of the programmer by defining a commonly occurring piece of code so that it can be reused when required.The address is the memory location where the entity is stored. Every block of code in the program has its own memory location in the program. Which means like any variable or object methods and functions also have memory address.To get the memory address of a function you need to use the pointer of the ... Read More

Add two unsigned numbers using bits in C++.

sudhir sharma
Updated on 19-Sep-2019 08:27:30

539 Views

An unsigned number represented as a stream of bits is written in binary form.The binary form of 54 is 110110.Adding two numbers using bits, we will add their binary form using the binary addition logic.Rules for bit addition is −0+0 = 01+0 = 10+1 = 11+1 = 0 with carry = 1Lets take an example to add two numbers, Input: a = 21 (10101) , b = 27 (11011) Output: 48 (110000)Explanation − 10101 + 11011 = 110000. We will add bits starting the least significant bit. And then propagating to the next bit.Example#include #define M 32 using namespace ... Read More

Add two numbers represented by two arrays in C Program

sudhir sharma
Updated on 19-Sep-2019 08:18:23

2K+ Views

A number represented by the array is stored in such a form that each digit of the number is represented by an element of the array. For example, Number 234 in array is {2, 3, 4}.To add to such numbers we will first add number at the least significant digit and if the sum is greater than 10 propagate the carry. After this, we will go for the next consecutive digits of the array doing the same procedure and finding the sum.Let’s take an example to add two numbers −a = {2, 9, 6} b = {6, 3, 8} Output: ... Read More

C/C++ Tricky Programs

sudhir sharma
Updated on 19-Sep-2019 08:11:14

5K+ Views

Here are 10 tricky programs that will test your programming basics.1. Program to print “ ” in C++In C++ programming language, we use quotes to denote the start and end of the text is to be printed. So, printing quotes “ needs a special escape sequence. So, we will use the \” to print quotes in c++.Example Live Demo#include using namespace std; int main() {    cout

C/C++ Program for Greedy Algorithm to find Minimum number of Coins

sudhir sharma
Updated on 19-Sep-2019 08:02:59

5K+ Views

A greedy algorithm is an algorithm used to find an optimal solution for the given problem. greedy algorithm works by finding locally optimal solutions ( optimal solution for a part of the problem) of each part so show the Global optimal solution could be found.In this problem, we will use a greedy algorithm to find the minimum number of coins/ notes that could makeup to the given sum. For this we will take under consideration all the valid coins or notes i.e. denominations of { 1, 2, 5, 10, 20, 50 , 100, 200 , 500 ,2000 }. And we ... Read More

Advertisements