Found 1401 Articles for C

MCQ on Memory allocation and compilation process in C

Arnab Chakraborty
Updated on 21-Oct-2019 12:52:48

388 Views

Here we will see some MCQ questions on Memory Allocation and Compilation Processes.Question 1 − What will be the output of the following code − Live Demo#include #include int main() {    union my_union {       int i;       float f;       char c;    };    union my_union* u;    u = (union my_union*)malloc(sizeof(union my_union));    u->f = 20.60f;    printf("%f", u->f); }Options −Garbage Value20.600000Syntax Error20.6ExplanationUsing unions, we can use same memory location to hold multiple type of data. All member of union uses same memory location which has maximum space. Here ... Read More

C Program to check if a number is divisible by any of its digits

Sunidhi Bansal
Updated on 21-Oct-2019 11:59:18

1K+ Views

Given a number n, task is to find that any of the digit in the number divides the number completely or not. Like we are given a number 128625 is divisible by 5 which is also present in the number.ExampleInput: 53142 Output: yes Explanation: This number is divisible by 1, 2 and 3 which are the digits of the number Input: 223 Output: No Explanation: The number is not divisible by either 2 or 3The approach used below is as follows −We will start from the unit place and take the unit place’s number.Check whether the number is divisible or ... Read More

C Program for product of array

Sunidhi Bansal
Updated on 21-Oct-2019 11:53:57

8K+ Views

Given an array arr[n] of n number of elements, the task is to find the product of all the elements of that array.Like we have an array arr[7] of 7 elements so its product will be likeExampleInput: arr[] = { 10, 20, 3, 4, 8 } Output: 19200 Explanation: 10 x 20 x 3 x 4 x 8 = 19200 Input: arr[] = { 1, 2, 3, 4, 3, 2, 1 } Output: 144The approach used below is as follows −Take array input.Find its size.Iterate the array and Multiply each element of that arrayShow resultAlgorithmStart In function int prod_mat(int arr[], ... Read More

C Program for Arrow Star Pattern

Sunidhi Bansal
Updated on 21-Oct-2019 11:49:31

1K+ Views

Given a number n and we have to print the arrow star pattern of maximum n number of stars.The star pattern of input 4 will look like −ExampleInput: 3 Output:Input: 5 Output:The approach used below is as follows −Take input in integer.Then print n spaces and n stars.Decrement till n>1.Now increment till n.And print spaces and stars in increasing order.AlgorithmStart In function int arrow(int num)    Step 1-> declare and initialize i, j    Step 2-> Loop For i = 1 and i

C Program for subtraction of matrices

Sunidhi Bansal
Updated on 21-Oct-2019 11:42:24

777 Views

Given two matrices MAT1[row][column] and MAT2[row][column] we have to find the difference between two matrices and print the result obtained after subtraction of two matrices. Subtraction of two matrices are MAT1[n][m] – MAT2[n][m].For subtraction the number of rows and columns of both matrices should be same.ExampleInput: MAT1[N][N] = { {1, 2, 3},    {4, 5, 6},    {7, 8, 9}} MAT2[N][N] = { {9, 8, 7},    {6, 5, 4},    {3, 2, 1}} Output: -8 -6 -4 -2 0 2 4 6 8Approach used below is as follows −We will iterate both matrix for every row and column and ... Read More

C Program to check if an array is palindrome or not using Recursion

Sunidhi Bansal
Updated on 21-Oct-2019 11:35:40

1K+ Views

Given an array arr[n] where n is some size of an array, the task is to find out that the array is palindrome or not using recursion. Palindrome is a sequence which can be read backwards and forward as same, like: MADAM, NAMAN, etc.So to check an array is palindrome or not so we can traverse an array from back and forward like −In recursion also we have to change the start and end value till they are equal or when the values as start and end are not equal then exit and return false that the given array is ... Read More

C Program to check if a number is divisible by sum of its digits

Sunidhi Bansal
Updated on 21-Oct-2019 11:28:40

1K+ Views

Given a number n we have to check whether the sum of its digits divide the number n or not. To find out we have to sum all the numbers starting from the unit place and then divide the number with the final sum.Like we have a number “521” so we have to find the sum of its digit that will be “5 + 2 + 1 = 8” but 521 is not divisible by 8 without leaving any remainder.Let’s take another example “60” where “6+0 = 6” which can divide 60 and will not leave any remainder.ExampleInput: 55 Output: ... Read More

C Program to check if the points are parallel to X axis or Y axis

Sunidhi Bansal
Updated on 21-Oct-2019 11:24:32

366 Views

Given n number of points we have to check that whether the point is parallel to x-axis or y-axis or no axis according to a graph. A graph is a figure which is used to show a relationship between two variables each measured along with axis at right angles. Parallel are the same lines which are having same distance at all points, like railway tracks are parallel to each other.So, we have to find whether the points are parallel to x-axis or y-axis means the distance between the coordinates and the axis are same at all points.What is an axisThe ... Read More

C Program to check if two strings are same or not

Sunidhi Bansal
Updated on 21-Oct-2019 11:18:33

9K+ Views

Given two strings str1 and str2 we have to check whether the two strings are same or not. Like we are given two stings “hello” and “hello” so they are identical and same.Identical are the strings which seems equal but are not equal like : “Hello” and “hello”, and same are the strings which are exactly same like : “World” and “World”.ExampleInput: str1[] = {“Hello”}, str2[] = {“Hello”} Output: Yes 2 strings are same Input: str1[] = {“world”}, str2[] = {“World”} Output: No, 2 strings are not sameThe approach used below is as follows −We can use strcmp(string2, string1).strcmp() string ... Read More

C Program for replacing one digit with other

Sunidhi Bansal
Updated on 21-Oct-2019 11:14:31

3K+ Views

Given a number n, we have to replace a digit x from that number with another given number m. we have to look for the number whether the number is present in the given number or not, if it is present in the given number then replace that particular number x with another number m.Like we are given with a number “123” and m as 5 and the number to be replaced i.e. x as “2”, so the result should be “153”.ExampleInput: n = 983, digit = 9, replace = 6 Output: 683 Explanation: digit 9 is the first digit ... Read More

Advertisements