Programming Articles - Page 2485 of 3363

Sum of first n natural numbers in C Program

sudhir sharma
Updated on 01-Jul-2020 11:08:28

1K+ Views

The concept of finding the sum of sum of integers is found such that first, we will find the sum of numbers up to n and then add all the sums to get a value which will be the sum of sum which is our desired sum.For this problem, we are given a number n up to which we have to find the sum of the sum. Let's take an example to find this sum.n = 4Now we will find the sum of numbers for every number from 1 to 4 :Sum of numbers till 1 = 1 Sum of ... Read More

Importance of XOR operator in Java?

Vivek Verma
Updated on 14-May-2025 19:35:13

12K+ Views

Bitwise XOR (exclusive or) "^" is an operator in Java that provides the answer '1' if both of the bits in its operands are different; if both of the bits are the same, then the XOR operator gives the result '0'. XOR is a binary operator that is evaluated from left to right. The operator "^" is undefined for the argument of type String. Importance of the XOR (^) Operator in Java In Java, the XOR (^) operator is important for both bitwise and boolean operations. It returns true or 1 only when the two operands "differ". XOR is commonly ... Read More

How to convert an OutputStream to a Writer in Java?

Vivek Verma
Updated on 14-May-2025 19:09:21

2K+ Views

Input and output Streams in Java are objects that accepts sequence of information and sends them further. These are used to read and write data from/to various sources.What are Output Streams & WritersA Java output streams accept output data (bytes) from a source and sends it to the destination. An output stream is represented by an abstract class known as OutputStream. This is the super class of all the OutputStream classes. There are various output streams in Java namely, ByteArrayOutputStream, FileOutputStream, FilterOutputStream, ObjectOutputStream, PipedOutputStream.Writers are objects that are used to write data to character streams. These are represented by the abstract ... Read More

C++ Programming Internals?

sudhir sharma
Updated on 09-Aug-2019 07:28:43

618 Views

C++ Internals means how the working of C++ compiler compiling the .cpp code and giving us the output. C++ is a popular programming language mostly used for writing system software. It is an extension of the C programming language. C is a compiled language. The C++ compiler compiles C++ code to an object or executable file is generated. The executable or the binary files contains machine executable instructions and some metadata of the machine instructions.A typical way of compiling a C++ program is to run the compiler on C++ code. The compiler will generate machine instructions which are set of ... Read More

C++ mutable keyword?

sudhir sharma
Updated on 30-Jun-2025 11:23:16

5K+ Views

The mutable keyword in C++ is a storage class specifier. It enables non-static, non-const, and non-reference data members (i.e., mutable data member) of a class to be changed even when the object containing them is declared constant. Mutable data members are those members whose values can be changed in runtime even if the object is of constant type. It is just the opposite of a constant. What is Need of Mutable? Sometimes, it is necessary to modify one or more data members of a class/struct through the constant function, even if you do not want the function to update another ... Read More

C Program for simple interest?

sudhir sharma
Updated on 09-Aug-2019 07:20:30

685 Views

Simple Interest is the product of principal amount, rate of interest and the time duration (in years) by 100.Example,Input − p=5, r=4, t=5Output − 1Explanation: Simple Interest = (Principal Amount * Rate of Interest * Number of years) / 100SI= 5*4*5/100 = 1Example#include #include using namespace std; int main() {    //principle amount    float p = 5;    //time    float r = 4;    //rate in years    float t = 5;    // Simple interest    float SI = 0;    SI =(p * t * r) / 100;    printf("Simple Interest = %f ",SI);    return 0; }OutputSimple Interest = 1.0000

Area of a n-sided regular polygon with given Radius in C Program?

sudhir sharma
Updated on 13-Aug-2019 08:27:29

431 Views

A polygon is a ‘n’ sided closed figure.N sided polygon means a polygon with n equal sides. The radius of a polygon is distance between center and vertex.In the figure we can see that the whole polygon can be divided into n equal polygonWe know, area of the triangle = (base * height)/2Area of the small triangle using trigonometric logic, area = r2*sin(t)cos(t) = (r2*sin(2t))/2So, area of the polygon:Area = n * (area of one triangle)= n*r2*sin(2t)/2 = n*r2*sin(360/n)/2Example#include #include int main() {    float r = 4 n = 12;    float area = ((r * r ... Read More

Area of a leaf inside a square in C Program?

sudhir sharma
Updated on 09-Aug-2019 07:07:47

350 Views

To find the area of leaf inside a square, we need to split it into parts and find the area of parts and then add the areas to find the area of leaf.To calculate the area we are splitting the leaf into two parts.To find the area of 1st part AECA, we will find the area of quad circle AECDA and subtract the area of triangle ACDA from it.area of a Quadrant = 1⁄4 *(π*r2) whereπ = 22/7 or 3.141.area of a right angle triangle= 1⁄2*B*H = ½ a2Example#include #define PI 3.14159265 int main() {    float a = 12.3; ... Read More

C Program for Area of a square inscribed in a circle which is inscribed in a hexagon?

sudhir sharma
Updated on 09-Aug-2019 06:57:01

241 Views

Given, A square that is inscribed within a circle that is inscribed in a regular hexagon and we need to find the area of the square, for that we need to find the relation of the side of square and the side of the hexagon.The mathematical formula for the radius of circle inscribed within the hexagon is, r=A√3/2Since, the diagonal of square is equal to diameter of the circle, so the relation between the radius and side is, a=√rBased on the side of hexagon, a = √3A/√2So, Area of the Square, Area=a2 = (√3A/√2)2Example#include #include int main() { ... Read More

Area of a triangle inscribed in a rectangle which is inscribed in an ellipse?

sudhir sharma
Updated on 09-Aug-2019 06:52:46

361 Views

For understanding this complex problem, let's do it in two parts. First we will find the dimensions of the rectangle and based on that we can find the area of a triangle inscribed in it.Using the equation of ellipse and differential calculus, mathematical formula for the area of a rectangle is,  area = 2ab, where 2a = major axis and 2b = minor axis.The largest triangle that can be inscribed in the rectangle, should stand on the same base & has height raising between the same parallel sides of the rectangle.The area of largest triangle inscribed within the rectangle is ... Read More

Advertisements