Found 1452 Articles for C

C program to dynamically make array and print elements sum

Arnab Chakraborty
Updated on 08-Oct-2021 11:09:20

6K+ Views

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

238 Views

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

655 Views

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

981 Views

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

22K+ Views

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

958 Views

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

2K+ Views

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

5K+ Views

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

C program to find maximum of four integers by defining function

Arnab Chakraborty
Updated on 14-Sep-2023 02:25:05

29K+ Views

Suppose we have four numbers a, b, c, and d. We shall have to find maximum among them by making our own function. So we shall create one max() function that takes two numbers as input and finds the maximum, then using them we shall find maximum of all four numbers.So, if the input is like a = 5, b = 8, c = 2, d = 3, then the output will be 8To solve this, we will follow these steps −define a function max(), this will take x and yreturn maximum of x and ytake four numbers a, b, ... Read More

C program to find sum and difference of two numbers

Arnab Chakraborty
Updated on 08-Oct-2021 10:50:57

5K+ Views

Suppose we have two integer numbers a, b and two floating point numbers c, d. We shall have to find the sum of a and b as well as c and d. We also have to find the sum of a and c as well. So depending on the printf function style, output may differ.So, if the input is like a = 5, b = 58 c = 6.32, d = 8.64, then the output will be a + b = 63 c + d = 14.960001 a + c = 11.320000To solve this, we will follow these steps −To ... Read More

Advertisements