0% found this document useful (0 votes)
75 views

Simple Interest Calculation

The document contains C code for multiple programs: 1) A simple interest calculation program that takes inputs for principal, rate, and time and calculates simple interest. 2) A quadratic equation solver that determines the number and type of roots (real, imaginary, or equal) of a quadratic equation based on the values of a, b, and c. 3) Programs to calculate sine and cosine series for given values of x and n terms. 4) An Armstrong number generator that finds all Armstrong numbers up to a given limit. 5) Other programs for operations like swapping variables, temperature conversion, matrix operations, and student mark calculation using structures. Each program takes inputs, performs the relevant calculation and outputs

Uploaded by

Derrick Joel
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

Simple Interest Calculation

The document contains C code for multiple programs: 1) A simple interest calculation program that takes inputs for principal, rate, and time and calculates simple interest. 2) A quadratic equation solver that determines the number and type of roots (real, imaginary, or equal) of a quadratic equation based on the values of a, b, and c. 3) Programs to calculate sine and cosine series for given values of x and n terms. 4) An Armstrong number generator that finds all Armstrong numbers up to a given limit. 5) Other programs for operations like swapping variables, temperature conversion, matrix operations, and student mark calculation using structures. Each program takes inputs, performs the relevant calculation and outputs

Uploaded by

Derrick Joel
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 28

/* Simple Interest Calculation */

#include<stdio.h>
#include<conio.h>
void main()
{
float p,n,r,s;
clrscr();
printf("Enter the values of p,n and r");
scanf("%f%f%f",&p,&n,&r);
s=(p*n*r)/100;
printf("The Simple Interest is : %.2f",s);
}
RUN 1 :
~~~~~~~
Enter the values of p,n and r
5800
6
5.2
The Simple Interest is : 1809.59

/* Program to find the roots of a quadratic equation */


# include <stdio.h>
# include <conio.h>
# include <math.h>
void main()
{
float a, b, c, d, real, imag, r1, r2, n ;
int k ;
clrscr() ;
printf("Enter the values of A, B & C : ") ;
scanf("%f %f %f", &a, &b, &c) ;
if(a != 0)
{
d=b*b-4*a*c;
if(d < 0)
k=1;
if(d == 0)
k=2;
if(d > 0)
k = 3;
switch(k)
{
case 1 :
printf("\nRoots are imaginary\n") ;
real = - b / (2 * a) ;
d=-d;
n = pow((double) d, (double) 0.5) ;
imag = n / (2 * a) ;
printf("\nr1 = %7.2f + j%7.2f", real, imag) ;
printf("\nr2 = %7.2f - j%7.2f", real, imag) ;
break ;
case 2 :
printf("\nRoots are real and equal\n") ;
r1 = - b / (2 * a) ;
printf("\nr1 = r2 = %7.2f", r1) ;
break ;
case 3 :
printf("\nRoots are real and unequal\n") ;
r1 = (- b + sqrt((double) d)) / (2 * a) ;
r2 = (- b - sqrt((double) d)) / (2 * a) ;
printf("\nr1 = %7.2f",r1) ;
printf("\nr2 = %7.2f",r2) ;
break ;
}
}

else
printf("\nEquation is linear") ;
getch() ;
}
RUN 1 :
~~~~~~~
Enter the values of A, B & C : 0.0

4.0

7.0

Equation is linear
RUN 2 :
~~~~~~~
Enter the values of A, B & C : 1.0

2.0

7.0

2.0

1.0

7.0

1.0

Roots are imaginary


r1 = -1.00 + j 2.45
r2 = -1.00 - j 2.45
RUN 3 :
~~~~~~~
Enter the values of A, B & C : 1.0
Roots are real and equal
r1 = r2 = -1.00
RUN 4 :
~~~~~~~
Enter the Values of A, B & C : 2.0
Roots are real and unequal
r1 = -0.15
r2 = -3.35

/* Program to calculate the sine series */


# include <stdio.h>
# include <conio.h>
# include <math.h>
void main()
{
int i, n ;
float x, val, sum, t ;
clrscr() ;
printf("Enter the value for x : ") ;
scanf("%f", &x) ;
printf("\nEnter the value for n : ") ;
scanf("%d", &n) ;
val = x ;
x = x * 3.14159 / 180 ;
t=x;
sum = x ;
for(i = 1 ; i < n + 1 ; i++)
{
t = (t * pow((double) (-1), (double) (2 * i - 1)) *
x * x) / (2 * i * (2 * i + 1)) ;
sum = sum + t ;
}
printf("\nSine value of %f is : %8.4f", val, sum) ;
getch() ;
}
RUN 1 :
~~~~~~~
Enter the value for x : 30
Enter the value for n : 20
Sine value of 30.000000 is : 0.5000

/* Program to calculate the cosine series*/


# include <stdio.h>
# include <conio.h>
# include <math.h>
void main()
{
int i, n ;
float x, val, sum = 1, t = 1 ;
clrscr() ;
printf("Enter the value for x : ") ;
scanf("%f", &x) ;
printf("\nEnter the value for n : ") ;
scanf("%d", &n) ;
val = x ;
x = x * 3.14159 / 180 ;
for(i = 1 ; i < n + 1 ; i++)
{
t = t * pow((double) (-1), (double) (2 * i - 1)) *
x * x / (2 * i * (2 * i - 1)) ;
sum = sum + t ;
}
printf("\nCosine value of %f is : %8.4f", val, sum) ;
getch() ;
}
RUN 1 :
~~~~~~~
Enter the value for x : 60
Enter the value for n : 20
Cosine value of 60.000000 is : 0.5000

/* Program to generate armstrong numbers */


# include <stdio.h>
# include <conio.h>
void main()
{
int i, a, r, s, n ;
clrscr() ;
printf("Enter the limit : ") ;
scanf("%d", &n) ;
printf("\nThe armstrong numbers are :\n\n") ;
for(i = 0 ; i <= n ; i++)
{
a=i;
s=0;
do
{
r = a % 10 ;
s = s + (r * r * r) ;
a = a / 10 ;
} while(a > 0);
if(i == s)
printf("%d\t", i) ;
}
getch() ;
}
RUN 1 :
~~~~~~~
Enter the limit : 1000
The armstrong numbers are :
0

153

370

371

407

/*Swapping Of Two Variables*/


# include <stdio.h>
# include <conio.h>
void main()
{
int a,b;
clrscr();
printf("\n\t***Swapping Of Two Variables***\n\n");
printf("\nEnter the value of a : ");
scanf("%d",&a);
printf("\nEnter the value of b : ");
scanf("%d",&b);
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter swapping a = %d and b = %d",a,b);
getch();
}
Output:
***Swapping Of Two Variables***
Enter the value of a :20
Enter the value of b : 30
After swapping a = 30 and b = 20

/* Conversion of Celcius To Farenheit*/


# include <stdio.h>
# include <conio.h>
void main()
{
float cel,fah;
clrscr();
printf("\n\t\t***Temperature Conversion***\n\n");
printf("Enter the Celcius value : ");
scanf("%f",&cel);
fah=cel*1.8+32;
printf("\nThe Converted Farenheit value : %f",fah);
getch();
}

Output:
***Temperature Conversion***
Enter the Celcius value : 37
The Converted Farenheit value : 98.599998

/* Factorial-Recursion*/
# include <stdio.h>
# include <conio.h>
void main()
{
int n;
long int f;
long int fact();
clrscr();
printf("\n\t***Factorial Of A Given Number***\n\n");
printf("Enter the number : ");
scanf("%d",&n);
f=fact(n);
printf("\nFactorial is : %ld",f);
getch();
}
long int fact(int n)
{
if (n==0)
return (1);
else
return (n*fact(n-1));
}
Output:
***Factorial Of A Given Number***
Enter the number : 6
Factorial is : 720

/* Sorting the Given Numbers*/


# include <stdio.h>
# include <conio.h>
void main()
{
int i,j,n;
int a[20],temp;
clrscr();
printf("\n\t***Sorting The Given Numbers***\n\n");
printf("Enter number of Elements : ");
scanf("%d",&n);
printf("Enter the elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
for(j=i+1;j<=n-1;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("\n\nThe sorted elements in ascending :\n");
for(i=0;i<n;i++)
printf("%d ",a[i]);
getch();
}
Output:
***Sorting The Given Numbers***
Enter number of Elements : 5
Enter the elements
12 34 10 87 43
The sorted elements in ascending :
10 12 34 43 87

/*Matrix Multiplication*/
# include <stdio.h>
# include <conio.h>
void main()
{

int a[10][10],b[10][10],c[10][10];
int i,j,k,r1,c1,r2,c2;
clrscr();
printf("\n\t\t***Matrix Multiplication***\n\n");
printf("Enter the order of Matrix A : ");
scanf("%d %d",&r1,&c1);
printf("\nEnter the Elements of A :\n");
for (i=0;i<r1;i++)
for (j=0;j<c1;j++)
scanf("%d",&a[i][j]);
printf("\n\nEnter the order of Matrix B : ");
scanf("%d %d",&r2,&c2);
printf("\nEnter the Elements of B :\n");
for (i=0;i<r2;i++)
for (j=0;j<c2;j++)
scanf("%d",&b[i][j]);
clrscr();
printf("\n\nMatrix A is :\n");
for (i=0;i<r1;i++)
{
for (j=0;j<c1;j++)
printf("%2d ",a[i][j]);
printf("\n");
}
printf("\n\nMatrix B is :\n");
for (i=0;i<r2;i++)
{
for (j=0;j<c2;j++)
printf("%2d ",b[i][j]);

printf("\n");
}
for (i=0;i<r1;i++)
for (j=0;j<c2;j++)
c[i][j]=0;
if (c1==r2)
{
for (i=0;i<r1;i++)
for (j=0;j<c2;j++)
for (k=0;k<c1;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
printf("\n\nProduct of A and B is :\n");
for (i=0;i<r1;i++)
{
for (j=0;j<c2;j++)
printf("%2d ",c[i][j]);
printf("\n");
}
}
else
printf("\n\nMultiplication is not possible");
getch();
}
Output:
***Matrix Multiplication***
Enter the order of Matrix A : 2 3
Enter the Elements of A :
2 4 3 1 5 6
Enter the order of Matrix B : 3 2
Enter the Elements of B :
1 5 4 6 3 4

Matrix A is :
2 4 3
1 5 6

Matrix B is :
1 5
4 6
3 4
Product of A and B is :
27 46
39 59
***Matrix Multiplication***
Enter the order of Matrix A : 2 3
Enter the Elements of A :
2 2 2 2 2 2
Enter the order of Matrix B : 2 3
Enter the Elements of B :
3 2 1 4 5 3
Matrix A is :
2 2 2
2 2 2
Matrix B is :
3 2 1
4 5 3
Multiplication is not possible

/*Matrix Addition*/
# include <stdio.h>
# include <conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10];
int i,j,r1,c1,r2,c2;
clrscr();
printf("\n\t\t***Matrix Addition***\n\n");
printf("Enter the order of Matrix A : ");
scanf("%d %d",&r1,&c1);
printf("\nEnter the Elements of A :\n");
for (i=0;i<r1;i++)
for (j=0;j<c1;j++)
scanf("%d",&a[i][j]);
printf("\n\nEnter the order of Matrix B : ");
scanf("%d %d",&r2,&c2);
printf("\nEnter the Elements of B :\n");
for (i=0;i<r2;i++)
for (j=0;j<c2;j++)
scanf("%d",&b[i][j]);
clrscr();
printf("\n\nMatrix A is :\n");
for (i=0;i<r1;i++)
{
for (j=0;j<c1;j++)
printf("%2d ",a[i][j]);
printf("\n");
}
printf("\nMatrix B is :\n");
for (i=0;i<r2;i++)
{

for (j=0;j<c2;j++)
printf("%2d ",b[i][j]);
printf("\n");
}
if ((r1==r2) && (c1==c2))
{
for (i=0;i<r1;i++)
for (j=0;j<c1;j++)
c[i][j]=a[i][j]+b[i][j];
printf("\nAddition of A and B is :\n");
for (i=0;i<r1;i++)
{
for (j=0;j<c1;j++)
printf("%2d ",c[i][j]);
printf("\n");
}
}
else
printf("\nAddition is not possible");
getch();
}

Output:
***Matrix Addition***
Enter the order of Matrix A : 3 2
Enter the Elements of A :
1
3
2
4
3

2
Enter the order of Matrix B : 3 2
Enter the Elements of B :
2
1
1
2
3
4
Matrix A is :
1 3
2 4
3 2
Matrix B is :
2 1
1 2
3 4
Addition of A and B is :
3 4
3 6
6 6

***Matrix Addition***
Enter the order of Matrix A : 2 2
Enter the Elements of A :
1
1
1
1

Enter the order of Matrix B : 3 2


Enter the Elements of B :
2
2
2
2
2
2
Matrix A is :
1 1
1 1
Matrix B is :
2 2
2 2
2 2
Addition is not possible

/*Students Mark Calculation Using Structure*/


# include <stdio.h>
# include <conio.h>
void main()
{
struct student
{
int Rollno;
char name[15];
int m1,m2,m3,total;
float avg;
char grade;
};
struct student s[10];
int i,n;
clrscr();
printf("\n\t\t***Students Mark Calculation***\n\n");
printf("Enter the no. of students : ");
scanf("%d",&n);
for (i=0;i<n;i++)
{
printf("\nEnter the details of student %d",i+1);
printf("\n\nRollNo : ");
scanf("%d",&s[i].Rollno);
printf("\nName : ");
scanf("%s",s[i].name);
printf("\nM1, M2, M3 : ");
scanf("%d %d %d",&s[i].m1,&s[i].m2,&s[i].m3);
s[i].total=s[i].m1+s[i].m2+s[i].m3;
s[i].avg=s[i].total/3.0;

if (s[i].avg>=75)
s[i].grade='A';
else
If ((s[i].avg>=60)&&(s[i].avg<75))
s[i].grade='B';
else
if ((s[i].avg>=50)&&(s[i].avg<60))
s[i].grade='C';
else
s[i].grade='F';
}
printf("\n\nRollNo\tName\tM1\tM2\tM3\tTotal\tAverage\tGrade\n");
printf("_____________________________________________________________\n
")
for (i=0;i<n;i++)
{
printf("\n%d\t",s[i].Rollno);
printf("%s",s[i].name);
printf("\t%d\t%d\t%d",s[i].m1,s[i].m2,s[i].m3);
printf("\t%d\t%5.2f\t%c",s[i].total,s[i].avg,s[i].grade);
}
getch();
}

Output:
***Students Mark Calculation***
Enter the no. of students : 3
Enter the details of student 1
RollNo : 1009
Name : ABC
M1, M2, M3 : 78 90 67
Enter the details of student 2
RollNo : 1142
Name : DEF
M1, M2, M3 : 67 59 87
Enter the details of student 3
RollNo : 1256
Name : GHI
M1, M2, M3 : 37 40 45
RollNo

Name

M1

M2

M3

Total

Average

Grade

____________________________________________________
1009

ABC

78

90

67

235

78.33

1142

DEF

67

59

87

213

71.00

1256

GHI

37

40

45

122

40.67

/*Employee Payslip Preparation*/


# include <stdio.h>
# include <conio.h>
void main()
{
struct employee
{
int empid;
char ename[15];
int basic;
float hra,da,epf,gs,net;
};
struct employee e[10];
int n,i;
clrscr();
printf("\n\t\t****Employee Payslip Preparation***\n\n");
printf("Enter the no. of employees : ");
scanf("%d",&n);
for (i=0;i<n;i++)
{
printf("\nEnter the details of employee %d ",i+1);
printf("\nEmployee Id : ");
scanf("%d",&e[i].empid);
printf("Employee Name : ");
scanf("%s",e[i].ename);
printf("Basic : ");
scanf("%d",&e[i].basic);
e[i].da = e[i].basic * 40.0 / 100;
e[i].hra = e[i].basic * 20.0 / 100;
e[i].epf = e[i].basic * 12.0 / 100;
e[i].gs= e[i].basic + e[i].hra + e[i].da;
e[i].net = e[i].gs - e[i].epf;
}
printf("\n\nEmpid\tName\tBasic\tHRA\t DA\t EPF\t Grosspay\tNetpay\n);
printf("---------------------------------------------------------\n\n")
for (i=0;i<n;i++)
{
printf("%d\t",e[i].empid);
printf("%s\t",e[i].ename);
printf("%d\t",e[i].basic);
printf("%5.2f\t %5.2f %5.2f",e[i].hra,e[i].da,e[i].epf);
printf(" %7.2f\t%7.2f\n",e[i].gs,e[i].net);
}
getch();
}

Output:
***Employee Payslip Preparation***
Enter the no. of employees : 3
Enter the details of employee 1
Employee Id : 255
Employee Name : ABC
Basic : 5000
Enter the details of employee 2
Employee Id : 377
Employee Name : DEF
Basic : 7355
Enter the details of employee 3
Employee Id : 750
Employee Name : GHI
Basic : 8850
Empid Name Basic HRA
DA
EPF
Grosspay
Netpay
--------------------------------------------------------------------------------------------255
377
750

ABC
DEF
GHI

5000 1000.00 2000.00 600.00 8000.00


7355 1471.00 2942.00 882.60 11768.00
8850 1770.00 3540.00 1062.00 14160.00

7400.00
10885.40
13098.00

/*Menu Driven calculator Using Functions*/


# include <stdio.h>
# include <conio.h>
void main()
{
int a,b,d,opt=1;
int add();
int sub();
int mul();
int div();
clrscr();
printf("\t****Menu Driven Calculator\n");
printf("\nEnter the values of a and b : ");
scanf("%d %d",&a,&b);
while (opt>=1 && opt<=5)
{
printf("\n\n**Main Menu**\n");
printf("\n1. Add");
printf("\n2. Sub");
printf("\n3. Mul");
printf("\n4. Div");
printf("\n5. Exit");
printf("\nEnter your option : ");
scanf("%d",&opt);
switch (opt)
{
case 1: d=add(a,b);
printf("\nSum is : %d",d);
break;
case 2: d=sub(a,b);
printf("\nDiff is : %d",d);

break;
case 3: d=mul(a,b);
printf("\nProd is : %d",d);
break;
case 4: d=div(a,b);
printf("\nDiv is : %d",d);
break;
case 5: exit(0);
}
}
}
int add(int x,int y)
{
return (x+y);
}
int sub(int x,int y)
{
return (x-y);
}
int mul(int x,int y)
{
return (x*y);
}
int div(int x,int y)
{
return (x/y);
}

Output:
****Menu Driven Calculator
Enter the values of a and b : 18
**Main Menu**
1. Add
2. Sub
3. Mul
4. Div
5. Exit
Enter your option : 1
Sum is : 24
**Main Menu**
1. Add
2. Sub
3. Mul
4. Div
5. Exit
Enter your option : 2
Diff is : 12
**Main Menu**
1. Add
2. Sub
3. Mul
4. Div
5. Exit
Enter your option : 3
Prod is : 108

**Main Menu**
1. Add
2. Sub
3. Mul
4. Div
5. Exit
Enter your option : 4
Div is : 3
**Main Menu**
1. Add
2. Sub
3. Mul
4. Div
5. Exit
Enter your option : 5

/* Program for reversing an integer */


# include <stdio.h>
# include <conio.h>
void main()
{
long n, r, s = 0 ;
clrscr() ;
printf("Enter a number : ") ;
scanf("%ld", &n) ;
while(n > 0)
{
r = n % 10 ;
s = r + s * 10 ;
n = n / 10 ;
}
printf("\nThe reversed number is : %ld", s) ;
getch() ;
}
RUN 1 :
~~~~~~~
Enter a number : 2468
The Reversed Numeral is : 8642

/*Fibonacci Series Recursion*/


# include <stdio.h>
# include <conio.h>
void main()
{
int n, f = -1, s =1;
void fibo();
clrscr();
printf("\n\n\t***Fibonacci Series****\n\n");
printf("Enter the no. of Terms : ");
scanf("%d", &n);
printf("\nFibonacci Series is :\n\n");
fibo(n, f, s);
getch();
}
void fibo(int n,int f, int s)
{
int no;
if (n > 0)
{
no=f+s;
printf("%d ", no);
fibo(n-1, s, no);
}
}

Output:
***Fibonacci Series****
Enter the no. of Terms : 8
Fibonacci Series is :
0

13

You might also like