Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 307 of 377

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 08-Oct-2021 32K+ 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
Arnab Chakraborty
Updated on 08-Oct-2021 1K+ 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
Arnab Chakraborty
Updated on 08-Oct-2021 3K+ 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
Arnab Chakraborty
Updated on 08-Oct-2021 7K+ 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 sum and difference of two numbers

Arnab Chakraborty
Arnab Chakraborty
Updated on 08-Oct-2021 6K+ 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

C Program to read and write character string and sentence

Arnab Chakraborty
Arnab Chakraborty
Updated on 08-Oct-2021 25K+ Views

Suppose you want to take a character, then a string and a sentence (string with spaces) using C. So we shall provide three inputs and print the same as output. The maximum size of the string is 500 here.So, if the input is likecharacter = 'T' string = "ProgrammingLanguage" sentence = "I love programming through C", then the output will beYour character: T Your string: ProgrammingLanguage Your sentence: I love programming through CTo solve this, we will follow these steps −For character we need to use scanf("%c", &character);For string we need to use scanf("%s", string);This step is optional, but required ...

Read More

Program to find largest color value in a directed graph in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 08-Oct-2021 368 Views

Suppose we have a directed graph with n colored nodes and m different edges. And the nodes are numbered from 0 to n-1. We have a string col with lowercase letters, where col[i] represents the color of the ith node in this graph (0-indexed). We also have an edge list where edges[j] = (u, v) represents, there is an edge between u and v.A valid path in the graph is a sequence of nodes xi for all i from 1 to k, such that there is a directed edge from xi to xi+1. The color of the path is the ...

Read More

Program to find minimum interval to include each query in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 08-Oct-2021 428 Views

Suppose we have a list of intervals, where intervals[i] has a pair (left_i, right_i) represents the ith interval starting at left_i and ending at right_i (both inclusive). We also have another array called queries. The answer to the jth query is the size of the smallest interval i such that left_i

Read More

Program to find closest room from queries in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 08-Oct-2021 253 Views

Suppose there is an array called rooms. where rooms[i] contains a pair [roomId_i, size_i] denotes a room whose id is roomId_i and size is size_i. All room numbers are distinct. We also have another array queries, where queries[j] contains a pair [preferred_j, minSize_j]. The answer to the jth query is the room number id of a room such that −The room has size of at least minSize_j, and|id - preferred_j| is minimized.Now, if there is a tie in the absolute difference, then use the room with the smallest id. If there is no such room, return -1. So we have ...

Read More

Program to find maximum building height in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 08-Oct-2021 908 Views

Suppose we have a value n and another list of pairs called restrictions. We want to build n new buildings in a city. But there are few restrictions. We can built in a line and buildings are labeled from 1 to n. The restrictions has two parameters, so restrictions[i] = (id_i, max_height_i) indicates id_i must have height less than or equal to max_height_i. The city restrictions on the heights of the new buildings are as follows −The height of each building must be 0 or positive values.First building height must be 0.The difference between any two adjacent buildings height cannot ...

Read More
Showing 3061–3070 of 3,768 articles
« Prev 1 305 306 307 308 309 377 Next »
Advertisements