C Program for Binomial Coefficients Table

Sunidhi Bansal
Updated on 09-Jul-2020 08:48:19

8K+ Views

Given with a positive integer value let’s say ‘val’ and the task is to print the value of binomial coefficient B(n, k) where, n and k be any value between 0 to val and hence display the result.What is Binomial CoefficientBinomial coefficient (n, k) is the order of choosing ‘k’ results from the given ‘n’ possibilities. The value of binomial coefficient of positive n and k is given by$$C_k^n=\frac{n!}{(n-k)!k!}$$where, n >= kExampleInput-: B(9, 2) Output-:$$B_2^9=\frac{9!}{(9-2)!2!}$$ $$\frac{9\times 8\times 7\times 6\times 5\times 4\times 3\times 2\times 1}{6\times 5\times 4\times 3\times 2\times 1)\times 2\times 1}=\frac{362, 880}{1440}=252$$What is Binomial Coefficient TableThe Binomial Coefficient Table is formed ... Read More

C Program for Circumference of a Parallelogram

Sunidhi Bansal
Updated on 09-Jul-2020 08:45:53

200 Views

We are given with the sides of parallelogram and the task is to generate the circumference of a parallelogram with its given sides and display the resultWhat is a Parallelogram?Parallelogram is a type of quadratic which have −Opposite sides parallelOpposite angles equalPolygon diagonals bisects each otherShown in the below figure ‘a’ and ‘b’ are the sides of a parallelogram where parallel sides are shown in the figure.Perimeter/Circumference of a parallelogram is defined as −Circumference of Parallelogram = 2(a + b)                                           ... Read More

C++ Program for Class Interval Arithmetic Mean

Sunidhi Bansal
Updated on 09-Jul-2020 08:44:06

677 Views

We are given with three arrays where first array contains the upper limit for arithmetic mean, second array contains the lower limit for arithmetic mean and third array contains the frequencies and the task is to generate the arithmetic mean of class intervals given.What is Arithmetic Mean?Arithmetic mean is the average value that is calculated by dividing the sum of all the elements in the set with the total number of elements in the given set.How to calculate Class Interval Arithmetic MeanGiven with Lower Limit, Upper Limit, FrequencyLower LimitUpper LimitFrequency121342563784Calculate the mid-point by adding the upper limit and lower limit ... Read More

Convert Hours into Minutes and Seconds in C++

Sunidhi Bansal
Updated on 09-Jul-2020 08:23:37

1K+ Views

Given with the input as hours and the task is to convert the number of hours into minutes and seconds and display the corresponding resultFormula used for converting the hours into minutes and seconds is −1 hour = 60 minutes    Minutes = hours * 60 1 hour = 3600 seconds    Seconds = hours * 3600ExampleInput-: hours = 3 Output-: 3 hours in minutes are 180    3 hours in seconds are 10800 Input-: hours = 5 Output-: 5 hours in minutes are 300    5 hours in seconds are 18000Approach used in the below program is as follows ... Read More

C++ Program for Triangular Pattern Mirror Image Around 0

Sunidhi Bansal
Updated on 09-Jul-2020 08:23:06

344 Views

Given with the positive value n and the task is to generate the triangular pattern i.e. mirror image of the printed numbers and display the resultExampleInput-: n = 6 Output-:Input-: n = 3 Output-:Approach used in the below program is as follows −Input the value of n as a positive integerTraverse one loop i for the number of rows in a pattern i.e. nTraverse one loop j for the number of spaces in a patternTraverse another loop for the digits in a patternAlgorithmSTART Step 1-> declare function to print mirror image of triangular pattern    void print_mirror(int n)    declare ... Read More

Find Sum of Odd Factors of a Number in C++

Sunidhi Bansal
Updated on 09-Jul-2020 08:22:32

570 Views

Given with a positive integer and the task is to generate the odd factors of a number and finding out the sum of given odd factors.ExampleInput-: number = 20 Output-: sum of odd factors is: 6 Input-: number = 18 Output-: sum of odd factors is: 13So, result = 1 + 5 = 6Approach used in the below program is as follows −Input the number for calculating the sum of odd factors of that numberIgnore the digit 0 and 2 because both are even digits and store the digit 1 because it is an odd digitStart the loop from 3 ... Read More

Use @SerializedName Annotation with Gson in Java

raja
Updated on 09-Jul-2020 08:17:53

8K+ Views

The @SerializedName annotation can be used to serialize a field with a different name instead of an actual field name. We can provide the expected serialized name as an annotation attribute, Gson can make sure to read or write a field with the provided name.Syntax@Retention(value=RUNTIME) @Target(value={FIELD, METHOD}) public @interface SerializedNameExampleimport com.google.gson.*; import com.google.gson.annotations.*; public class SerializedNameTest {    public static void main(String args[]) {       Gson gson = new GsonBuilder().setPrettyPrinting().create();       Person person = new Person(115, "Raja Ramesh", "Hyderabad");       String jsonStr = gson.toJson(person);       System.out.println(jsonStr);    } } // Person class class ... Read More

Implement Custom JsonAdapter Using Gson in Java

raja
Updated on 09-Jul-2020 08:15:08

3K+ Views

The @JsonAdapter annotation can be used at field or class level to specify the Gson. The TypeAdapter class can be used to convert Java objects to and from JSON. By default, Gson library converts application classes to JSON by using built-in type adapters but we can override it by providing custom type adapters.Syntax@Retention(value=RUNTIME) @Target(value={TYPE, FIELD}) public @interface JsonAdapterExampleimport java.io.IOException; import com.google.gson.Gson; import com.google.gson.TypeAdapter; import com.google.gson.annotations.JsonAdapter; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; public class JsonAdapterTest {    public static void main(String[] args) {       Gson gson = new Gson();       System.out.println(gson.toJson(new Customer()));    } } // Customer class class Customer { ... Read More

Convert JSONNode to ArrayNode using Jackson API in Java

raja
Updated on 09-Jul-2020 07:59:35

18K+ Views

A JsonNode is a base class for all JSON nodes that forms the JSON Tree Model whereas ArrayNode is a node class that represents an array mapped from JSON content. We can convert or translate JsonNode to ArrayNode by typecasting the ArrayNode to retrieve the values using the readTree() method of ObjectMapper class and get() method for accessing the value of a specified element of an array node.Syntaxpublic JsonNode readTree(String content) throws IOException, com.fasterxml.jackson.core.JsonProcessingExceptionExampleimport com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.core.JsonProcessingException; public class JSonNodeToArrayNodeTest {    public static void main(String args[]) throws JsonProcessingException {       String jsonStr = "{\"Technologies\" : [\"Java\", ... Read More

Search Value Inside a JSON File Using Jackson in Java

raja
Updated on 09-Jul-2020 07:52:12

3K+ Views

The com.fasterxml.jackson.databind.node.ObjectNode class can be used to map the JSON object structure in Json content. We can search for a particular value inside the JSON file using the get() method of ObjectNode class, this method used for accessing the value of a specified field of an object node.Syntaxpublic JsonNode get(String fieldName)Exampleimport com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; public class ObjectNodeTest {    public static void main(String args[]) throws Exception {       String jsonString = "{\"Id\":101, \"name\":\"Raja Ramesh\", \"address\":\"Madhapur\"}";       ObjectMapper mapper = new ObjectMapper();       ObjectNode node = mapper.readValue(jsonString, ObjectNode.class);       if(node.has("name")) {       ... Read More

Advertisements