Found 1401 Articles for C

C Program to Sort an array of names or strings

sudhir sharma
Updated on 18-Jul-2020 06:19:21

1K+ Views

In this problem, we are given an array of string. Our task is to create a c program to sort an array of name or string. This program will sort all the names we have given in the input in ascending alphabetical order.Let’s take an example to understand the problem, InputnamesArray = ["Rishabh", "Jyoti", "Palak", "Akash"]Output["Akash", "jyoti", "palak", "Rishabh"]To solve this we will use the qsort() function of the standard template library as we know sorting of integer values the thing that changes here is we are considering string for comparison instead of integer values.So, the comparator that is used ... Read More

C program to simulate Nondeterministic Finite Automata (NFA)

sudhir sharma
Updated on 18-Jul-2020 06:16:51

3K+ Views

In this problem, we are will create a C program to simulate non-deterministic Finite automata (NFA).NFA (Non-deterministic Finite automata) finite state machine that can move to any combination of states for an input symbol i.e. there is no exact state to which the machine will move.Formal definition of NDFA −NFA / NDFA (Non-deterministic Finite automata) can be represented by 5-tuple (Q, ∑, δ, q0, F) where −Q is a finite set of states.∑ is a finite set of symbols called the alphabets.δ is the transition function where d: Q × ∑ → 2Q (Here the power set of Q (2Q) ... Read More

C Program to reverse each node value in Singly Linked List

sudhir sharma
Updated on 18-Jul-2020 06:09:34

300 Views

In this article, we are given a linked list. Our task is to create a C program to reverse each node value in singly linked list.We will take each node of the linked list and reverse the value.Linked list is a sequence of links that contains items that are linked to another link.Let’s take an example to understand the problem, Input34 12 89 56 72Output43 21 98 65 27To solve this problem, we will traverse the singly linked list and take each node. And then reverse the value of the current node.Program to reverse each node value in Singly Linked ... Read More

C Program to Reverse Array of Strings

sudhir sharma
Updated on 18-Jul-2020 06:05:30

2K+ Views

In this problem, we are given an array of string. Our task is to create a c program to reverse array of strings.We will reverse the array elements i.e. last element to the first value and so on.Let’s take an example to understand the problem, Inputstrarr[] = {"learn", "programming", "at", "tutorialspoint"}Outputstrarr[] = {"tutorialspoint", "at", "programming", "learn"}To solve this problem, we will create an array of pointers and use two pointers from start and end. then move the pointers towards the opposite side, and keep on swapping the pointer values.C program to reverse array of strings.//c program to reverse array of ... Read More

C program to Replace a word in a text by another given word

sudhir sharma
Updated on 18-Jul-2020 06:03:28

5K+ Views

In this program, we have given three strings txt, oldword, newword. Our task is to create a C program to replace a word in a text by another given word.The program will search for all the occurrences of the oldword in the text and replace it with newword.Let’s take an example to understand the problem −Inputtext = “I am learning programming” oldword = “learning” newword = “practicing”Output“I am practicing programming”To solve this problem, we will first find the number of occurrence of the oldword in the string and then create a new string which will store the text with replaced ... Read More

C program to print number series without using any loop

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

439 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

864 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

6K+ 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 Matrix Chain Multiplication

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

10K+ 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

Advertisements