Found 33676 Articles for Programming

C program to print number series without using any loop

sudhir sharma
Updated on 18-Jul-2020 06:01:29

635 Views

In this problem, we are given two numbers N and K. Our task is to create a program that will print number series without using any loop.The series that is to be printed will start from n and will be subtracted by k till it becomes zero or negative. After that, we will start to add k to it till it becomes n again. If this process we cannot use any type of loop.Let’s take an example to understand the problem, Inputn = 12 , k = 3Output12 9 6 3 0 3 6 9 12To solve this problem without ... Read More

C program to print environment variables

sudhir sharma
Updated on 18-Jul-2020 05:58:48

1K+ Views

Here, we will create a c program to print environment variables.Environment variable is a global variable that can affect the way the running process will behave on the system.Program to print environment variables//Program to print environment variablesExample Live Demo#include int main(int argc, char *argv[], char * envp[]){    int i;    for (i = 0; envp[i] != NULL; i++)    printf("%s", envp[i]);    getchar();    return 0; }OutputALLUSERSPROFILE=C:\ProgramData CommonProgramFiles=C:\Program Files\Common Files HOMEDRIVE=C: NUMBER_OF_PROCESSORS=2 OS=Windows_NT PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC PROCESSOR_ARCHITECTURE=x86 PROCESSOR_IDENTIFIER=x86 Family 6 Model 42 Stepping 7, GenuineIntel PROCESSOR_LEVEL=6 PROCESSOR_REVISION=2a07 ProgramData=C:\ProgramData ProgramFiles=C:\Program Files PUBLIC=C:\Users\Public SESSIONNAME=Console SystemDrive=C: SystemRoot=C:\Windows WATCOM=C:\watcom windir=C:\WindowsRead More

C Program to print all permutations of a given string

sudhir sharma
Updated on 17-Jul-2020 13:27:09

1K+ Views

In this problem, we are given a string. Our task is to create a c program to print all permutations of a given string.This program will find all possible combinations of the given string and print them.Permutation is the arrangement of all parts of an object, in all possible orders of arrangement.Let’s take an example to understand the problem, InputxyzOutputxyz, xzy, yxz, yzx, zxy, zyxExplanationThese are all permutations take in order.To solve this problem, we will use backtracking i.e. taking each character of the string as the first character of the permutation and then sequentially choosing all remaining characters of ... Read More

C Program to list all files and sub-directories in a directory

sudhir sharma
Updated on 17-Jul-2020 13:20:49

8K+ Views

Here, we are given a directory. Our task is to create a C program to list all files and sub-directories in a directory.The directory is a place/area/location where a set of the file(s) will be stored.Subdirectory is a directory inside the root directory, in turn, it can have another sub-directory in it.In C programming language you can list all files and sub-directories of a directory easily. The below program will illustrate how to list all files and sub-directories in a directory.//C program to list all files and sub-directories in a directoryExample Live Demo#include #include int main(void){    struct dirent ... Read More

C program for pipe in Linux

sudhir sharma
Updated on 17-Jul-2020 13:14:14

2K+ Views

Here, we will create a C program for pipe in Linux. In this program, we will read some text from the input stream and then print it to the output screen.First, let’s learn basics about pipe in LinuxPipe is used to transfer data, it can be used for communication between process/ command/ program for transferring standard output between two in Linux or Unix based system.One important thing to be noted is that pipes are unidirectional i.e. data can either flow from left to right or from right to left in the program.Here, we will create a pipe that will read ... Read More

C Program for Matrix Chain Multiplication

sudhir sharma
Updated on 17-Jul-2020 12:57:47

12K+ Views

In this problem, we are given a sequence( array) of metrics. our task is to create a C program for Matrix chain multiplication. We need to find a way to multiply these matrixes so that, the minimum number of multiplications is required.The array of matrices will contain n elements, which define the dimensions of the matrices as, arr[i-1] X arr[i].Let’s take an example to understand the problem, Inputarray[] = {3, 4, 5, 6}OutputExplanationthe matrices will be of the order −Mat1 = 3X4, Mat2 = 4X5, Mat3 = 5X6For these three matrices, there can be two ways to multiply, mat1*(mat2*mat3) -> ... Read More

C program to detect tokens in a C program

sudhir sharma
Updated on 07-Oct-2023 03:03:53

30K+ Views

Here, we will create a c program to detect tokens in a C program. This is called the lexical analysis phase of the compiler. The lexical analyzer is the part of the compiler that detects the token of the program and sends it to the syntax analyzer.Token is the smallest entity of the code, it is either a keyword, identifier, constant, string literal, symbol.Examples of different types of tokens in C.ExampleKeywords: for, if, include, etc Identifier: variables, functions, etc separators: ‘, ’, ‘;’, etc operators: ‘-’, ‘=’, ‘++’, etcProgram to detect tokens in a C program−Example Live Demo#include #include ... Read More

C program to demonstrate fork() and pipe()

sudhir sharma
Updated on 17-Jul-2020 12:49:55

3K+ Views

In this problem, we will demonstrate fork() and pipe(). Here we will create a C program for Linux that will concatenate two string, using 2 processes one will take input and send it to others which will concatenate the string with a predefined string and return the concatenated string.First lets recap fork() and pipe()fork() − it creates a child process, this child process ahs a new PID and PPID.pipe() is a Unix, Linux system call that is used for inter-process communication.Let’s take an example for understanding the problem, InputLearn programming Predefined string: at tutorialspointOutputLearn programming at tutorialspointExplanationP1 take input of ... Read More

C Program for Reverse a linked list

sudhir sharma
Updated on 17-Jul-2020 12:44:11

12K+ Views

In this problem, we are given a linked list. Our task is to create a program for reverse a linked list.The program will reverse the given linked list and return the reversed linked list.Linked List is a sequence of links with contains items. Each link contains a connection to another link.Example9 -> 32 -> 65 -> 10 -> 85 -> NULLReverse linked list is a linked list created to form a linked list by reversing the links of the list. The head node of the linked list will be the last node of the linked list and the last one ... Read More

C Program for Recursive Insertion Sort

sudhir sharma
Updated on 17-Jul-2020 12:38:47

4K+ Views

Insertion sort is a sorting algorithm which is an in-place comparison-based algorithm.The algorithm works by place element in their position in the sorted sub-array i.e. the sub-array preceding the element which is a sorted sub-array.AlgorithmStep1 − loop from 1 to n-1 and do −Step2.1 − select element at position i, array[i].Step2.2 − insert the element in its position in the sorted sub-array array[0] to arr[i].Let’s take an example to understand the algorithmArray = [34, 7, 12, 90, 51]For i = 1, arr[1] = 7, placing in its positon in subarray arr[0] - arr[1].[7, 34, 12, 90, 51]For i = 2, ... Read More

Advertisements