Programming Articles - Page 2487 of 3366

Sum of the first N terms of the series 2,10, 30, 68,…. in C programming

sudhir sharma
Updated on 09-Aug-2019 11:28:04

220 Views

To find the sum of this series, we will first analyze this series.The series is:The given series is 2, 10, 30, 68…For exampleFor n = 6 Sum = 464On analysis of the given series, you will see that the series is the addition of two series first one is the series of n natural numbers and the second is the cube of n natural numbers this means the series can be split as:2, 10 , 30 ,68 = (1+13) , (2+23), (3 + 33), ( 4 + 43)so we can write the sum of the series as :sum = 2 ... Read More

Sum of the first N terms of the series 2, 6, 12, 20, 30…. in c programming

sudhir sharma
Updated on 09-Aug-2019 11:21:01

344 Views

To find the sum of this series, we will first analyze this series.The series is: 2,6,12,20,30…ExampleFor n = 6 Sum = 112 On analysis, (1+1),(2+4),(3+9),(4+16)... (1+12), (2+22), (3+32), (4+42), can be divided into two series i.e. s1:1,2,3,4,5… andS2: 12,2,32,....Find the sum of first and second using mathematical formulaSum1 = 1+2+3+4… , sum1 = n*(n+1)/2 Sum2 = 12+22+32+42… , sum1 = n*(n+1)*(2*n +1)/6Example#include int main() {    int n = 3;    int sum = ((n*(n+1))/2)+((n*(n+1)*(2*n+1))/6);    printf("the sum series till %d is %d", n,sum);    return 0; }OutputThe sum of series till 3 is 20

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

581 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

677 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

413 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

325 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

Advertisements