Found 1439 Questions for C

C program to print string tokens

Arnab Chakraborty
Updated on 08-Oct-2021 11:15:09
Suppose we have a string s that contains a sentence with few words. We shall have to print each word into new lines. To do this we can use the strtok() function under the string.h header file. This function takes the string and a delimiter. Here the delimiter is blank space " ".So, if the input is like s = "Let us see some string tokenizing fun", then the output will beLet us see some string tokenizing funTo solve this, we will follow these steps −token := first word by using strtok(s, " ") here delimiter is " "while token ... Read More

C program to reverse an array elements

Arnab Chakraborty
Updated on 08-Oct-2021 11:12:44
Suppose we have an array with n elements. We shall have to reverse the elements present in the array and display them. (Do not print them in reverse order, reverse elements in place).So, if the input is like n = 6 arr = [9, 8, 7, 2, 4, 3], then the output will be [3, 4, 2, 7, 8, 9]To solve this, we will follow these steps −for initialize i := 0, when i < quotient of n/2, update (increase i by 1), do:temp := arr[i]arr[i] := arr[n - i - 1]arr[n - i - 1] := tempfor initialize i ... Read More

C program to dynamically make array and print elements sum

Arnab Chakraborty
Updated on 08-Oct-2021 11:09:20
Suppose we have a number n. We shall have to make an array of size n dynamically and take n numbers one by one, then find the sum. To make the array we can use malloc() or calloc() function which is present inside the stdlib.h header file. The value of n is also provided as input through stdin.So, if the input is like n = 6, and array elements 9, 8, 7, 2, 4, 3, then the output will be 33 because sum of 9 + 8 + 7 + 2 + 4 + 3 = 33.To solve this, we ... Read More

C program to find amount of volume passed through a tunnel

Arnab Chakraborty
Updated on 08-Oct-2021 11:06:23
Suppose there is a tunnel whose height is 41 and width is very large. We also have a list of boxes with length, width and height. A box can pass through the tunnel if its height is exactly less than tunnel height. We shall have to find amount of volume that are passed through the tunnel. The volume is length * width * height. So we have a number N, an 2D array with N rows and three columns.So, if the input is like N = 4 boxes = [[9, 5, 20], [3, 7, 15], [8, 15, 41], [6, 3, ... Read More

C program to find marks of students for boys or girls

Arnab Chakraborty
Updated on 08-Oct-2021 11:04:55
Suppose we have an array called marks, where some marks are given, all even indices marks like marks[0], marks[2] and so on are holding marks of boys and all even indexed marks are holding for girls. We have another input called gender. The value of gender is either 'b' or 'g', when it is 'b' we shall have to return the sum of all boys, and when it is 'g' return sum of marks for all girls. (Size of array is N)So, if the input is like N = 9 marks = [8, 5, 2, 6, 7, 5, 9, 9, ... Read More

C program to find nth term of given recurrence relation

Arnab Chakraborty
Updated on 08-Oct-2021 11:02:52
Suppose we have three numbers a, b, c and a value n. We follow a recurrence formula S(n) −S(1) returns aS(2) returns bS(3) returns cS(n) returns S(n-1) + S(n-2) + S(n-3) for all n > 3.We shall have to find nth term by following this recurrence.So, if the input is like a = 5, b = 2, c = 3, n = 6, then the output will be 28 because −S(6) = S(5) + S(4) + S(3)S(5) = S(4) + S(3) + S(2)S(4) = S(3) + S(2) + S(1) = 3 + 2 + 5 = 10so now S(5) = ... Read More

C program to find sum of digits of a five digit number

Arnab Chakraborty
Updated on 08-Oct-2021 11:00:17
Suppose we have a five-digit number num. We shall have to find the sum of its digits. To do this we shall take out digits from right to left. Each time divide the number by 10 and the remainder will be the last digit and then update the number by its quotient (integer part only) and finally the number will be reduced to 0 at the end. So by summing up the digits we can get the final sum.So, if the input is like num = 58612, then the output will be 22 because 5 + 8 + 6 + ... Read More

C program to write all digits into words using for loop

Arnab Chakraborty
Updated on 08-Oct-2021 10:58:16
Suppose we have two digits a and b. We shall have to convert each digit into words and print them one by one. Printing digits into words means for a digit 5, it should print "Five".So, if the input is like a = 3, b = 8, then the output will beThreeFourFiveSixSevenEightTo solve this, we will follow these steps −Define a function solve(), this will take d, if d < 0 and d > 9, then:return ("Beyond range of 0 - 9")otherwise when d is same as 0, then:return ("Zero")otherwise when d is same as 1, then:return ("One")otherwise when d ... Read More

C program to convert digit to words

Arnab Chakraborty
Updated on 08-Oct-2021 10:56:42
Suppose we have a digit d, we shall have to convert it into words. So if d = 5, our output should be "Five". If we provide some d which is beyond the range of 0 and 9, it will return appropriate output.So, if the input is like d = 6, then the output will be "Six".To solve this, we will follow these steps −Define a function solve(), this will take d, if d < 0 and d > 9, then:return ("Beyond range of 0 - 9")otherwise when d is same as 0, then:return ("Zero")otherwise when d is same as ... Read More

C program to find sum and difference using pointers in function

Arnab Chakraborty
Updated on 08-Oct-2021 10:55:02
Suppose we have two numbers a and b. We shall have to define a function that can calculate (a + b) and (a - b) both. But using a function in C, we can return at most one value. To find more than one output, we can use output parameters into function arguments using pointers. Here in this problem we shall update a with a+b and b with a-b. When we call the function we shall have to pass the address of these two variables.So, if the input is like a = 5, b = 8, then the output will ... Read More
Advertisements