Found 1339 Articles for C

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

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

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

Difference between Compile Time Errors and Runtime Errors in C Program

Nitin Sharma
Updated on 18-Sep-2019 11:49:02

2K+ Views

Error or exception is something that refers to the interruption of code execution due to which the expected outcome could not be attained to the end-user.On the basis of the event when an error is generated or identified we can classify them as Compile time error and runtime error.The following are the important differences between Compile Time Errors and Runtime Errors.Sr. No.KeyCompile Time ErrorsRuntime Errors1ReferenceCompile-time errors are generally referred to the error corresponding to syntax or semantics.Runtime errors on the other hand refer to the error encountered during the execution of code at runtime.2DetectionCompile-time errors get detected by compiler at ... Read More

Difference between C and C++

Akansha Kumari
Updated on 14-Apr-2025 11:35:43

8K+ Views

Both C and C++ are middle-level programming languages that are used for developing system software as well as application software. C is a procedural programming language which have low-level memory access and minimal runtime; therefore, it is used for writing operating systems, embedded systems, and system-level programs. whereas C++ is just an extension of the C language, which is both a procedural programming language and object-oriented. Therefore, having extra features that make it suitable for game development, GUI applications, and high-performance software. C Programming Language C is a general-purpose, procedural programming language, which was developed by Dennis M. Ritchie at ... Read More

Difference between Boxing and Unboxing in C# programming.

Nitin Sharma
Updated on 17-Sep-2019 11:06:03

1K+ Views

C# provides two methods to link value type to reference type and vice e Versa. These two methods for linking are named boxing and unboxing where Boxing is used for the conversion of the value type to an object type while Unboxing refers to the conversion of the object type to the value type.The following are the important differences between Boxing and Unboxing.Sr. No.KeyBoxingUnboxing1ImplementationBoxing made object type referred to as the value type.Unboxing basically processes the retrieving value from the boxed object.2StorageIn the case of boxing, the value stored on the stack is copied to the object stored on heap ... Read More

Print matrix in zag-zag fashion in C Programming.

Sunidhi Bansal
Updated on 04-Sep-2019 07:22:21

1K+ Views

Given a matrix mat[row][col] we have to print the given matrix in zig-zag fashion like in the given image below −So the output should be like −Output: 10 20 40 70 50 30 60 80 90For the above problem, we have followed a simple approach where we have to iterate the matrix diagonally and change the value of iteration to change the direction after every previous match.AlgorithmSTART STEP 1-> DECALRE AND SET k = 3, l = 3 STEP 2-> DECLARE A MATRIX mat[][3] STEP 3-> DECLARE AND SET row = 0, col = 0, flag = false; STEP 4-> ... Read More

Print matrix in snake pattern from the last column in C Programming.

Sunidhi Bansal
Updated on 04-Sep-2019 06:13:45

357 Views

Given an array of nxn size, the program must print the elements of an array in a snake pattern starting from the last column that means from arr[0][n]th element without doing any changes to their original locations.ExampleInput: arr[]= 100 99 98 97    93 94 95 96    92 91 90 89    85 86 87 88 Output: 97 98 99 100 96 95 94 93 92 91 90 89 88 87 86 85AlgorithmSTART Step 1 -> declare initial variable as int n to 5, i and j Step 2 -> declare array of 2-D matrix with elements Step 3 -> Loop For i=0 and i= 0; j--)             printf("%d ", arr[i][j]);       }    return 0; }Outputif we run the above program then it will generate the following output50 40 30 20 10 60 70 80 90 100 150 140 130 120 110 160 170 180 190 200 250 240 230 220 210

Print matrix in snake pattern in C Programming.

Sunidhi Bansal
Updated on 04-Sep-2019 06:08:53

4K+ Views

Given an array of nxn size, the program must print the elements of an array in a snake pattern without doing any changes to their original locationsExampleInput: arr[]= 100 99 98 97    93 94 95 96    92 91 90 89    85 86 87 88 Output: 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85The program will traverse each row of a matrix and check for even or odd rows.If the row is even it will print the elements of that row from left to rightIf the row is odd it ... Read More

Print shortest path to print a string on screen in C Program.

Sunidhi Bansal
Updated on 22-Aug-2019 09:14:49

312 Views

Given a string, the program must display the shortest path which will print the string over the screen using that shortest path.Like screen will store alphabets in the formatA B C D E F G H I J K L M N O P Q R S T U V W X Y ZExampleInput: HUP Output : Move Down Move Down Move Down destination reached Move Left Move Left Move Down Move Down Move Down destination reached Move Up destination reachedThe approach used here is to store the characters in the n x n matrix and perform the following operation ... Read More

Print sorted distinct elements of array in C language

Sunidhi Bansal
Updated on 22-Aug-2019 09:08:29

572 Views

Given with an array of integer elements, the task is to remove the duplicate values and print the distinct elements in sorted manner.Given below is an array that stores integer type values in the fashion 4, 6, 5, 3, 4, 5, 2, 8, 7 and 0 now, the result will print the sorted elements as 0, 2, 3, 4, 4, 5, 5, 6, 7 and 8 but this result still contains duplicate values 4 and 5 which should be removed and the final result will be 0, 2, 3, 4, 5, 6, 7 and 8ExampleInput: array[] = {4, 6, 5, ... Read More

Print numbers with digits 0 and 1 only such that their sum is N in C Program.

Sunidhi Bansal
Updated on 22-Aug-2019 09:09:48

330 Views

Given an integer n, the task is to print the numbers who consist only 0’s and 1’s and their sum is equal to the integer n.The numbers which contain only zeros and ones are 1, 10, 11 so we have to print all those numbers which can be added to form the sum equal to n.Like, we entered n = 31 then the answer can be 10+10+11 or 10+10+10+1 theExampleInput: 31 Output:10 10 10 1Algorithmint findNumbers(int n) START STEP 1: DECLARE AND ASSIGN VARAIBALES m = n % 10, a = n STEP 2: LOOP WHILE a>0    IF a/10 ... Read More

Advertisements