Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes

C++ Programming Code Examples

C++ > Mathematics Code Examples

Program to solve a 3 Variable Linear Equation

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
/* Program to solve a 3 Variable Linear Equation */ #include<stdio.h> #include<conio.h> #include<stdlib.h> main() { clrscr(); float a,b,c,d,l,m,n,k,p,D,q,r,s,x,y,z; printf("PROGRAM TO SOLVE THREE VARIABLE LINEAR SIMULTANEOUS EQUATIONS "); printf("The equations are of the form: ax+by+cz+d=0 lx+my+nz+k=0 px+qy+rz+s=0 "); printf("Enter the coefficients in the order a,b,c,d,l,m,n,k,p,q,r,s "); scanf("%f%f%f%f%f%f%f%f%f%f%f%f",&a,&b,&c,&d,&l,&m,&n,&k,&p,&q,&r,&s); printf(" The equations you have input are: "); printf(" %.2f*x + %.2f*y + %.2f*z + %.2f = 0 ",a,b,c,d); printf(" %.2f*x + %.2f*y + %.2f*z + %.2f = 0 ",l,m,n,k); printf(" %.2f*x + %.2f*y + %.2f*z + %.2f = 0 ",p,q,r,s); D = (a*m*r+b*p*n+c*l*q)-(a*n*q+b*l*r+c*m*p); x = ((b*r*k+c*m*s+d*n*q)-(b*n*s+c*q*k+d*m*r))/D; y = ((a*n*s+c*p*k+d*l*r)-(a*r*k+c*l*s+d*n*p))/D; z = ((a*q*k+b*l*s+d*m*p)-(a*m*s+b*p*k+d*l*q))/D; printf("The solutions to the above three equations are : "); printf(" x = %5.2f y = %5.2f z = %5.2f ",x,y,z); getch(); return 0; }

The C++ comments are statements that are not executed by the compiler. The comments in C++ programming can be used to provide explanation of the code, variable, method or class. If we write comments on our code, it will be easier for us to understand the code in the future. Also, it will be easier for your fellow developers to understand the code. By the help of comments, you can hide the program code also. There are two types of comments in C++: • Single Line comment. • Multi Line comment

The getch() is a predefined non-standard function that is defined in conio.h header file. It is mostly used by the Dev C/C++, MS- DOS's compilers like Turbo C to hold the screen until the user passes a single value to exit from the console screen. It can also be used to read a single byte character or string from the keyboard and then print. It does not hold any parameters. It has no buffer area to store the input character in a program. The getch() function does not accept any parameter from the user. It returns the ASCII value of the key pressed by the user as an input.

#include is a way of including a standard or user-defined file in the program and is mostly written at the beginning of any C/C++ program. This directive is read by the preprocessor and orders it to insert the content of a user-defined or system header file into the following program. These files are mainly imported from an outside source into the current program. The process of importing such files that might be system-defined or user-defined is known as File Inclusion. This type of preprocessor directive tells the compiler to include a file in the source code program.

A return statement ends the processing of the current function and returns control to the caller of the function. A value-returning function should include a return statement, containing an expression. If an expression is not given on a return statement in a function declared with a non-void return type, the compiler issues an error message. If the data type of the expression is different from the function return type, conversion of the return value takes place as if the value of the expression were assigned to an object with the same function return type.

It is a predefined function in "conio.h" (console input output header file) used to clear the console screen. It is a predefined function, by using this function we can clear the data from console (Monitor). Using of clrscr() is always optional but it should be place after variable or function declaration only. It is often used at the beginning of the program (mostly after variable declaration but not necessarily) so that the console is clear for our output.

Arithmetic Operator is used to performing mathematical operations such as addition, subtraction, multiplication, division, modulus, etc., on the given operands. For example: 6 + 3 = 9, 5 - 3 = 2, 3 * 4 = 12, etc. are the examples of arithmetic operators. Let's discuss the different types of Arithmetic Operators in the C programming. Plus Operator is a simple Plus (+) Operator used to add two given operands. We can use Plus Operator with different data types such as integer, float, long, double, enumerated and string type data to add the given operand. The minus operator is denoted by the minus (-) symbol. It is used to return the subtraction of the first number from the second number. The data type of the given number can be different types, such as int, float, double, long double, etc., in the programing language.

A program shall contain a global function named main, which is the designated start of the program in hosted environment. main() function is the entry point of any C++ program. It is the point at which execution of program is started. When a C++ program is executed, the execution control goes directly to the main() function. Every C++ program have a main() function.

Program 'takes the input' of a set of integers or characters. It firstly generates the random partition of the "Length of the Set". Starting from the beginning, it 'prints the number' of

In The C++ programming, When a default or parameterized constructor of a derived class is called, the "Default Constructor" of a base class is called automatically. As you create an

Finding the smallest item in the tree. Not the most efficient implementation ('two passes'), but has correct "amortized behavior". A good alternative is to first call Find with parameter

In mathematics, the 'Euclidean' algorithm, or Euclid's algorithm, is a method for computing the 'greatest common divisor' of two (usually positive) integers, also known as the greatest