Programming Articles - Page 2523 of 3366

Average of ASCII values of characters of a given string?

Arnab Chakraborty
Updated on 02-Jul-2020 07:26:14

883 Views

Here we will see how to count the average of the ASCII values of each character in a given string. Suppose the string is “ABC”. The asci values are 65, 66, 67. So the average of these three is 66.AlgorithmasciiAverage(String)Begin    sum := 0    for each character c in String, do       sum := sum + ASCII of c    done    return sum/length of String EndExample Live Demo#include using namespace std; float asciiAverage(string str){    int sum = 0;    for(int i = 0; i str;    cout

Average of first n odd naturals numbers?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

281 Views

Here we will see how to get the average of n odd natural numbers. The n is given by the user. To get the ith odd number we can use this formula 2*i+1. Here also we are using this formula. Let us see the algorithm to get the clear idea.AlgorithmavgOddNaturalNumber(n)Begin    sum := 0    for i in range 0 to n-1, do       sum := sum + (2i + 1)    done    return sum/n EndExample Live Demo#include using namespace std; float asciiAverage(string str){    int sum = 0;    for(int i = 0; i str;    cout

ASCII NUL, ASCII 0 (‘0’) and Numeric literal 0?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

7K+ Views

Here we will see the ASCII NUL, ASCII 0 and the Numeric Literal 0. The ASCII null is represented as 0x00, and zero is represented as 0x30. The ASCII NUL character is used to denote the end of the string in C or C++. When programmer used ‘0’ (character 0) it is treated as 0x30. This is a hexadecimal number. The decimal equivalent is 48. To put ASCII NUL we have to mention ‘\0’ instead of ‘0’.char asciiNul = ‘\0’; int zero = 0; char zeroChar = ‘0’;The first one is ASCII NUL, second one is numeric 0, and the third one is character 0.

How to change the position of a JSlider to horizontal/vertical programmatically in Java?

raja
Updated on 10-Feb-2020 10:48:18

412 Views

A JSlider is a subclass of JComponent class and it is similar to scroll bar which allows the user to select a numeric value from a specified range of integer values. It has a knob which can slide on a range of values and can be used to select a particular value. A JSlider can generate a ChangeListener interface and the important methods of JSlider are getMaximum(), getMinimum(), getOrientation(), getValue() and setValue(). The default position of a JSlider is horizontal and we can also set the position to vertical programmatically by selecting a menu item from a menu bar. It can generate an ActionListener interface ... Read More

Array::fill() and array::swap() in C++ STL?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

588 Views

In this section we will see what are the usage of array::fill() and the array::swap() in C++ STL.The array::fill() function is used to fill the array with some specified value. Let us see one example to get the idea.Example Live Demo#include #include using namespace std; main() {    array arr = {00, 11, 22, 33, 44, 55, 66, 77, 88, 99};    cout

Array::crbegin() and array::crend() in C++ STL?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

130 Views

Here we will see the crbegin() and crend() functions of array in C++ STL.The array::crbegin() function is used to get reverse iterator. It returns constant reverse iterator pointing to the last element of the container. This function does not take any parameter.The array::crend() function is reverse of crbegin(). This returns the iterator which is pointing the last element of the reversed iterator.Let us see some code examples to get better idea.Example Live Demo#include #include using namespace std; main() {    array arr = {00, 11, 22, 33, 44, 55, 66, 77, 88, 99};    cout

Array get() function in C++ STL?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

333 Views

In this section we will see the get() function of array in C++ STL. This function is used to get the ith element of the array container. The syntax is like below −Syntaxget array_nameThis function takes two mandatory parameters. The is the index parameter. It is used to point to the ith position of the array. The second argument is array_name. This is the actual array from this ith element will be taken. This function returns the ith element.Let us see one example to get the idea.Example Live Demo#include #include using namespace std; main() {    array arr = {00, 11, ... Read More

Arrange given numbers to form the biggest number?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

304 Views

Here we will see how to generate the biggest number by rearranging the given numbers. Suppose there are {45, 74, 23} is given, the program will find the largest number, that is 744523. So each digit will not be arranged. but the whole number will be placed to make largest number.To solve this problem, we will use the string sorting. But the comparison logic is different. The comparing function will take two numbers a and b, then concatenate them to form ab and ba. Among them which one is bigger, that is considered.AlgorithmcompareStrings(a, b)begin    ab := concatenate b with ... Read More

Argument Coercion in C/C++?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

2K+ Views

Here we will see about the argument coercion in C or C++. The Argument Coercion is one technique by which the compiler can implicitly convert the arguments from one type to another type. It follows argument promotion rule. If one argument is lower datatype, that can be converted into higher datatypes, but the reverse is not true. The reason is if one higher datatype is converted into a lower datatype, it may loss some data.Let us see one pyramid that can express how the implicit conversion takes place.Example Live Demo#include using namespace std; double myAdd(double a, double b){    return a+b; ... Read More

Area of triangle formed by the axes of co-ordinates and a given straight line?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

151 Views

Here we will see how to get the area of a triangle formed by the x and y axis and another straight line. The diagram will be look like below. The equation of the straight line is −𝑎𝑥+𝑏𝑦+𝑐=0The line is cutting the x-axis at the point B, and cutting the y-axis at the point A. The intercept form will be like below −So the x-intercept is −𝑐∕𝑎 and y-intercept is −𝑐∕𝑏 . So the area of the triangle isExample Live Demo#include #include using namespace std; double areaTriangle(double a, double b, double c){    return fabs((c*c) / (2*a*b)); } main() {   ... Read More

Advertisements