1.2D Matrix operations like Addition, Subtraction, Multiplication, Transpose
2. Solution of non-linear polynomial equations
3. Calculation of Sine, Cosine, Tangent of a given angle in degree.
4. Solution of simultaneous algebraic equations
5. Complex number operations like, addition, subtraction, multiplication of two complex numbers, magnitude of a complex number
INTRODUCTION
C is a procedural programming language. It was initially developed by Dennis Ritchie between 1969 and 1973. It was mainly developed as a system programming language to write operating system. The main features of C language include low-level access to memory, simple set of keywords, and clean style, these features make C language suitable for system programming like operating system or compiler development.
Many later languages have borrowed syntax/features directly or indirectly from C language. Like syntax of Java, PHP, JavaScript and many other languages is mainly based on C language. C++ is nearly a superset of C language.
Features of C language
· It is a robust language with rich set of built-in functions and operators that can be used to write any complex program.
· The C compiler combines the capabilities of an assembly language with features of a high-level language.
· Programs Written in C are efficient and fast. This is due to its variety of data type and powerful operators.
· It is many time faster than BASIC.
· C is highly portable this means that programs once written can be run on another machines with little or no modification.
· Another important feature of C program, is its ability to extend itself.
· A C program is basically a collection of functions that are supported by C library. We can also create our own function and add it to C library.
· C language is the most widely used language in operating systems and embedded system development today.
Project Description
The Advanced Calculator is a type of an electronic calculator in which different calculating methods are involved. The methods contain scientific, mathematical and some methods related to engineering. These types of calculators are used when one is going for a higher education, because higher education contains these types of essential elements. Other than that, the scientific calculators have more features as compared to the ordinary calculator in which many kinds of calculations can be performed. The functions which are involved in this type of calculator are scientific notation, floating point values, logarithmic functions, exponential functions, complex numbers, fractions, statistics, programmability, equation solving, matrix calculations, calculus, conversion of units and physical constants. The scientific calculator is used in various fields for example in astronomy, geology, physics, chemistry, somehow in biology as well. The calculators are mostly used by the students studying in schools, colleges, universities. This calculator will not only be performing the basic functions but also the complex calculations.
PURPOSE OF THE PROJECT
The project Advanced Calculator will give various outputs. It will be a bug free calculator. You will be able to understand the purpose of calculator. You will be easily understand the basic functions on the provided calculator. You will be able to understand which type of problem do you have and then you will be easily solving the given calculations along with the method which is given to you. Not only this, you will also be able to know whether you are performing right or wrong.
FUNCTIONAL REQUIREMENTS:
Software Requirements
The major software requirements of the project are as follows:
Language : C
Operating system: Windows 10
Hardware Requirements
The hardware requirements that map towards the software are as follows:
RAM : 8GB
Processor : Intel
SOURCE CODE:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define MAXSIZE 10
struct complex
{
int real, img;
};
int main()
{ printf("\t -+=*^ ADVANCED CALCULATOR ^*=+- \n\n");
printf("\tenter the Calculation you want to perform \n\n1.2D Matrix operations like Addition,Subtraction, Multiplication, Transpose\n2. Solution of non-linear polynomial equations \n3. Calculation of Sine, Cosine, Tangent of a given angle in degree. \n4. Solution of simultaneous algebraic equations \n5. Complex number operations like, addition, subtraction, multiplication of two complex numbers, magnitude of a complex number \n");
int i, j, k, n;
int x;
int array[MAXSIZE];
scanf("%d",&x);
switch (x)
{ //MODULE1
case 1: printf("Choice is 1\n");
int r, c, a[100][100], b[100][100], sum[100][100];
printf(" enter 6 for MATRIX Addition\n enter 7 for MATRIX subtraction\n enter 8 for MATRIX multiplication\nenter 9 for MATRIX TRANSPOSE\n");
int W;
scanf("%d",&W);
switch (W)
{
case 6: printf("Addition");
printf("Enter number of rows (between 1 and 100): ");
scanf("%d", &r);
printf("Enter number of columns (between 1 and 100): ");
scanf("%d", &c);
printf("\nEnter elements of 1st matrix:\n");
for(i=0; i<r; ++i)
for(j=0; j<c; ++j)
{
printf("Enter element a%d%d: ",i+1,j+1);
scanf("%d",&a[i][j]);
}
printf("Enter elements of 2nd matrix:\n");
for(i=0; i<r; ++i)
for(j=0; j<c; ++j)
{
printf("Enter element a%d%d: ",i+1, j+1);
scanf("%d", &b[i][j]);
}
// Adding Two matrices
for(i=0;i<r;++i)
for(j=0;j<c;++j)
{
sum[i][j]=a[i][j]+b[i][j];
}
// Displaying the result
printf("\nSum of two matrix is: \n\n");
for(i=0;i<r;++i)
for(j=0;j<c;++j)
{
printf("%d ",sum[i][j]);
if(j==c-1)
{
printf("\n\n");
}
}
break;
case 7: printf("Choice is 2");
printf("Enter number of rows (between 1 and 100): ");
scanf("%d", &r);
printf("Enter number of columns (between 1 and 100): ");
scanf("%d", &c);
printf("\nEnter elements of 1st matrix:\n");
for(i=0; i<r; ++i)
for(j=0; j<c; ++j)
{
printf("Enter element a%d%d: ",i+1,j+1);
scanf("%d",&a[i][j]);
}
printf("Enter elements of 2nd matrix:\n");
for(i=0; i<r; ++i)
for(j=0; j<c; ++j)
{
printf("Enter element a%d%d: ",i+1, j+1);
scanf("%d", &b[i][j]);
}
// subracting Two matrices
for(i=0;i<r;++i)
for(j=0;j<c;++j)
{
sum[i][j]=a[i][j]-b[i][j];
}
// Displaying the result
printf("\nSum of two matrix is: \n\n");
for(i=0;i<r;++i)
for(j=0;j<c;++j)
{
printf("%d ",sum[i][j]);
if(j==c-1)
{
printf("\n\n");
}
}
break;
case 8: printf("Choice is 3");
int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];
printf("Enter number of rows and columns of first matrix\n");
scanf("%d%d", &m, &n);
printf("Enter elements of first matrix\n");
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
scanf("%d", &first[c][d]);
printf("Enter number of rows and columns of second matrix\n");
scanf("%d%d", &p, &q);
if (n != p)
printf("The matrices can't be multiplied with each other.\n");
else
{
printf("Enter elements of second matrix\n");
for (c = 0; c < p; c++)
for (d = 0; d < q; d++)
scanf("%d", &second[c][d]);
for (c = 0; c < m; c++) {
for (d = 0; d < q; d++) {
for (k = 0; k < p; k++) {
sum = sum + first[c][k]*second[k][d];
}
multiply[c][d] = sum;
sum = 0;
}
}
printf("Product of the matrices:\n");
for (c = 0; c < m; c++) {
for (d = 0; d < q; d++)
printf("%d\t", multiply[c][d]);
printf("\n");
}
}
break;
case 9: printf("MATRIX TRANSPOSE");
int a[10][10], transpose[10][10], r;
printf("Enter rows and columns of matrix: ");
scanf("%d %d", &r, &c);
// Storing elements of the matrix
printf("\nEnter elements of matrix:\n");
for(i=0; i<r; ++i)
for(j=0; j<c; ++j)
{
printf("Enter element a%d%d: ",i+1, j+1);
scanf("%d", &a[i][j]);
}
// Displaying the matrix a[][] */
printf("\nEntered Matrix: \n");
for(i=0; i<r; ++i)
for(j=0; j<c; ++j)
{
printf("%d ", a[i][j]);
if (j == c-1)
printf("\n\n");
}
// Finding the transpose of matrix a
for(i=0; i<r; ++i)
for(j=0; j<c; ++j)
{
transpose[j][i] = a[i][j];
}
// Displaying the transpose of matrix a
printf("\nTranspose of Matrix:\n");
for(i=0; i<c; ++i)
for(j=0; j<r; ++j)
{
printf("%d ",transpose[i][j]);
if(j==r-1)
printf("\n\n");
}
break;
default: printf("Choice other than 1, 2 and 3");
break; }
break;
case 2: printf("Solution of non-linear polynomial equations");
{
int is, num, power;
float xs, polySum;
printf("Enter the order of the polynomial \n");
scanf("%d", &num);
printf("Enter the value of x \n");
scanf("%f", &xs);
/* Read the coefficients into an array */
printf("Enter %d coefficients \n", num + 1);
for (is = 0; is <= num; is++)
{
scanf("%d", &array[is]);
}
polySum = array[0];
for (is = 1; is <= num; is++)
{
polySum = polySum * xs + array[is];
}
power = num;
printf("Given polynomial is: \n");
for (is = 0; is <= num; is++)
{
if (power < 0)
{
break;
}
/* printing proper polynomial function */
if (array[is] > 0)
printf(" + ");
else if (array[is] < 0)
printf(" - ");
else
printf(" ");
printf("%dx^%d ", abs(array[is]), power--);
}
printf("\n Sum of the polynomial = %6.2f \n", polySum);}
break;
//MODULE2
case 3: printf(" Calculation of Sine, Cosine, Tangent of a given angle in degree");
float degrees,radians;
printf("Enter an angle in degrees: ");
scanf("%f",°rees);
radians = 0.0174532925*degrees;
printf("%.2f degrees is %.2f radians.n",degrees,radians);
float sin_value = sin(radians);
float cos_value = cos(radians);
float tan_value = tan(radians);
float sinh_value = sinh(radians);
float cosh_value = cosh(radians);
float tanh_value = tanh(radians);
float log_value = log(radians);
float log10_value = log10(radians);
float exp_value = exp(radians);
printf("The value of sin(%f) : %f \n", degrees, sin_value);
printf("The value of cos(%f) : %f \n", degrees, cos_value);
printf("The value of tan(%f) : %f \n", degrees, tan_value);
printf("The value of sinh(%f) : %f \n", degrees, sinh_value);
printf("The value of cosh(%f) : %f \n", degrees, cosh_value);
printf("The value of tanh(%f) : %f \n", degrees, tanh_value);
printf("The value of log(%f) : %f \n", degrees, log_value);
printf("The value of log10(%f) : %f \n",degrees,log10_value);
printf("The value of exp(%f) : %f \n",degrees, exp_value);
return 0;
break;
case 4: printf(" Solution of simultaneous algebraic equations");
double matrix[10][10],l,m;
printf("Enter the no of variables: ");
scanf("%d", &n);
printf("Enter the agumented matrix:\n");
for(i = 0; i < n ; i++){
for(j = 0; j < (n+1); j++){
scanf("%lf", &matrix[i][j]);
}
}
for(i = 0; i < n; i++){
for(j = 0; j < n; j++){
if(i != j){
l = matrix[j][i];
m = matrix[i][i];
for(k = 0; k < n+1; k++){
matrix[j][k] = matrix[j][k] - (l/m) * matrix[i][k];
}
}
}
}
for(i = 0; i < n; i++){
l = matrix[i][i];
for(j = 0; j < n+1; j++){
matrix[i][j] /= l;
}
}
printf("The required solution is: \n\n");
for(i = 0; i < n ; i++){
printf("%c => %.2f", i+97, matrix[i][n]);
printf("\n");
}
return 0;
break;
//module3
case 5: printf("Choice is 3");
int choice, xe, ye, ze;
struct complex ae, be, ce;
while(1)
{
printf("Press 1 to add two complex numbers.\n");
printf("Press 2 to subtract two complex numbers.\n");
printf("Press 3 to multiply two complex numbers.\n");
printf("Press 4 to divide two complex numbers.\n");
printf("Press 5 to exit.\n");
printf("Enter your choice\n");
scanf("%d", &choice);
if (choice == 5)
exit(0);
if (choice >= 1 && choice <= 4)
{
printf("Enter a and b where a + ib is the first complex number.");
printf("\na = ");
scanf("%d", &ae.real);
printf("b = ");
scanf("%d", &ae.img);
printf("Enter c and d where c + id is the second complex number.");
printf("\nc = ");
scanf("%d", &be.real);
printf("d = ");
scanf("%d", &be.img);
}
if (choice == 1)
{
ce.real = ae.real + be.real;
ce.img = ae.img + be.img;
if (ce.img >= 0)
printf("Sum of the complex numbers = %d + %di", ce.real, ce.img);
else
printf("Sum of the complex numbers = %d %di", ce.real, ce.img);
}
else if (choice == 2)
{
ce.real = ae.real - be.real;
ce.img = ae.img - be.img;
if (ce.img >= 0)
printf("Difference of the complex numbers = %d + %di", ce.real, ce.img);
else
printf("Difference of the complex numbers = %d %di", ce.real, ce.img);
}
else if (choice == 3)
{
ce.real = ae.real*be.real - ae.img*be.img;
ce.img = ae.img*be.real + ae.real*be.img;
if (ce.img >= 0)
printf("Multiplication of the complex numbers = %d + %di", ce.real, ce.img);
else
printf("Multiplication of the complex numbers = %d %di", ce.real, ce.img);
}
else if (choice == 4)
{
if (be.real == 0 && be.img == 0)
printf("Division by 0 + 0i isn't allowed.");
else
{
xe = ae.real*be.real + ae.img*be.img;
ye = ae.img*be.real - ae.real*be.img;
ze = be.real*be.real + be.img*be.img;
if (xe%ze == 0 && ye%ze == 0)
{
if (ye/ze >= 0)
printf("Division of the complex numbers = %d + %di", xe/ze, ye/ze);
else
printf("Division of the complex numbers = %d %di", xe/ze, ye/ze);
}
else if (xe%ze == 0 && ye%ze != 0)
{
if (ye/ze >= 0)
printf("Division of two complex numbers = %d + %d/%di", xe/ze, ye, ze);
else
printf("Division of two complex numbers = %d %d/%di", xe/ze, ye, ze);
}
else if (xe%ze != 0 && ye%ze == 0)
{
if (ye/ze >= 0)
printf("Division of two complex numbers = %d/%d + %di", xe, ze, ye/ze);
else
printf("Division of two complex numbers = %d %d/%di", xe, ze, ye/ze);
}
else
{
if (ye/ze >= 0)
printf("Division of two complex numbers = %d/%d + %d/%di",xe, ze, ye, ze);
else
printf("Division of two complex numbers = %d/%d %d/%di", xe, ze, ye, ze);
}
} break;
}
else
printf("Invalid choice.");
printf("\nPress any key to enter choice again...\n");
}
break;
default: printf("Choice other than 1, 2 and 3");
break;
}
return 0;
}
CONCLUSION:
Finally, we built a C programming code for an Advance Calculator
program that performs the following operations without any bugs
1.2D Matrix operations like Addition, Subtraction, Multiplication, Transpose
2. Solution of non-linear polynomial equations
3. Calculation of Sine, Cosine, Tangent of a given angle in degree.
Comments
Post a Comment