/* 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 ;
}
}

45 r2 = -1.45 RUN 3 : ~~~~~~~ Enter the values of A. B & C : 0.j 2. } RUN 1 : ~~~~~~~ Enter the values of A.0 Equation is linear RUN 2 : ~~~~~~~ Enter the values of A.0 2. getch() .0 4.else printf("\nEquation is linear") .0 7.0 Roots are imaginary r1 = -1.0 1.15 r2 = -3.00 RUN 4 : ~~~~~~~ Enter the Values of A.00 + j 2. B & C : 2.0 1. B & C : 1.0 7.0 7.0 Roots are real and unequal r1 = -0. B & C : 1.35 .0 2.0 Roots are real and equal r1 = r2 = -1.00 .

i < n + 1 . (double) (2 * i . x = x * 3. printf("\nEnter the value for n : ") .1)) * x * x) / (2 * i * (2 * i + 1)) .5000 . for(i = 1 . &n) . sum) . scanf("%f". getch() . scanf("%d"./* Program to calculate the sine series */ # include <stdio. val. clrscr() . float x. sum = x .14159 / 180 . i++) { t = (t * pow((double) (-1).h> # include <conio. sum = sum + t . &x) . t=x.h> void main() { int i.4f". n . } RUN 1 : ~~~~~~~ Enter the value for x : 30 Enter the value for n : 20 Sine value of 30. printf("Enter the value for x : ") . t . val = x . val.h> # include <math.000000 is : 0. sum. } printf("\nSine value of %f is : %8.

h> # include <math. i < n + 1 . val = x . scanf("%f". printf("Enter the value for x : ") . x = x * 3.000000 is : 0.h> void main() { int i. sum = sum + t . scanf("%d". float x. &n) . getch() . for(i = 1 . i++) { t = t * pow((double) (-1). (double) (2 * i . } printf("\nCosine value of %f is : %8.14159 / 180 . sum) . val. val. &x) . printf("\nEnter the value for n : ") .h> # include <conio. t = 1 . sum = 1. clrscr() .1)) ./* Program to calculate the cosine series*/ # include <stdio.5000 . n . } RUN 1 : ~~~~~~~ Enter the value for x : 60 Enter the value for n : 20 Cosine value of 60.4f".1)) * x * x / (2 * i * (2 * i .

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

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

fah). printf("Enter the Celcius value : "). scanf("%f". clrscr(). getch().h> void main() { float cel.h> # include <conio. fah=cel*1.&cel). printf("\nThe Converted Farenheit value : %f". printf("\n\t\t***Temperature Conversion***\n\n"). } Output: ***Temperature Conversion*** Enter the Celcius value : 37 The Converted Farenheit value : 98.8+32./* Conversion of Celcius To Farenheit*/ # include <stdio.fah.599998 .

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

i<n.&a[i]). } 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 . for(i=0. int a[20].i<n.j++) { if(a[i]>a[j]) { temp=a[i]./* Sorting the Given Numbers*/ # include <stdio.a[i]). for(i=0.i++) printf("%d ".i++) scanf("%d". printf("Enter the elements\n"). getch().h> void main() { int i.h> # include <conio.i<n. printf("Enter number of Elements : ").j.temp. clrscr().i++) { for(j=i+1.j<=n-1. a[j]=temp. printf("\n\t***Sorting The Given Numbers***\n\n"). for(i=0. a[i]=a[j].&n).n. } } } printf("\n\nThe sorted elements in ascending :\n"). scanf("%d".

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

c[i][j]).j++) for (k=0. } 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 . printf("\n"). getch().i<r1. for (i=0.i<r1. printf("\n\nProduct of A and B is :\n"). } for (i=0.j<c2.printf("\n").i++) for (j=0.j<c2. } } else printf("\n\nMultiplication is not possible").j++) c[i][j]=0.i++) { for (j=0.j++) printf("%2d ".k<c1.k++) c[i][j]=c[i][j]+a[i][k]*b[k][j]. if (c1==r2) { for (i=0.i<r1.i++) for (j=0.j<c2.

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 .

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

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

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

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

of students : 3 Enter the details of student 1 RollNo : 1009 Name : ABC M1.Output: ***Students Mark Calculation*** Enter the no. M3 : 78 90 67 Enter the details of student 2 RollNo : 1142 Name : DEF M1. M2.33 A 1142 DEF 67 59 87 213 71.00 B 1256 GHI 37 40 45 122 40. M2. M3 : 67 59 87 Enter the details of student 3 RollNo : 1256 Name : GHI M1. M2.67 F . M3 : 37 40 45 RollNo Name M1 M2 M3 Total Average Grade ____________________________________________________ 1009 ABC 78 90 67 235 78.

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

00 .00 14160.60 11768.00 600.00 7400.40 13098.00 1062.00 3540.00 8000.00 2000.00 882.00 8850 1770.00 7355 1471.Output: ***Employee Payslip Preparation*** Enter the no.00 2942. 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 10885.

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

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

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

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

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

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

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.