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

C Programming: Prakash Shantagiri

The document contains C program code examples for calculating simple interest, factorials, reversing integers, Fibonacci series, adding diagonal matrix elements, finding the biggest and smallest number in an array, generating patterns, generating bills with discounts, and calculating employee salaries. The programs demonstrate basic C programming concepts like input/output, loops, functions, arrays, and calculations.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

C Programming: Prakash Shantagiri

The document contains C program code examples for calculating simple interest, factorials, reversing integers, Fibonacci series, adding diagonal matrix elements, finding the biggest and smallest number in an array, generating patterns, generating bills with discounts, and calculating employee salaries. The programs demonstrate basic C programming concepts like input/output, loops, functions, arrays, and calculations.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 16

C programming

Prakash shantagiri

-1-

C PROGRAM TO FIND SIMPLE INTEREST.


#include<stdio.h>
#include<conio.h>
main ()
{
float p,t,r,si;
clrscr();
printf("Enter time:");
scanf("%f",&t);
printf("Enter principle amount:");
scanf("%f",&p);
printf("Enter rate of interest:");
scanf("%f",&r);
si=(p*t*r)/100;
printf("%f",si);
}
OUTPUT
Enter time:
9.5
Enter principle amount:
12050
Enter rate of interest:
5.9
906754.02
------------------------------Enter time:
1.5
Enter principle amount:
150000
Enter rate of interest:
8.2
18450.00

-2-

C PROGRAM TO FIND FACTORIAL OF POSITIVE INTEGER.


#include<stdio.h>
#include<conio.h>
main()
{
int cnt,no,fact=1;
puts("Enter a no");
scanf("%d",&no);
for(cnt=2;cnt<=no;cnt++)
{
fact=fact*cnt;
}
printf("factorial=%d",fact);
}
OUTPUT
Enter a no
5
factorial=120
---------------------------------------Enter a no
2
factorial=2

-3-

C- PROGARM TO FIND REVERS INTEGER


#include<stdio.h>
#include<conio.h>
void main()
{
int temp,rev=0,digit,n;
clrscr();
printf("ENTER THE NUMBER:");
scanf("%d",&n);
temp=n;
while(n>0)
{
digit=n%10;
rev=rev*10+digit;
n=n/10;
}
printf("THE ORIGINAL NUMBER IS %d\n",temp);
printf("THE REVERSED NUMBER IS %d\n",rev);
getch();
}
OUTPUT
ENTER THE NUMBER: 5432
THE ORIGINAL NUMBER IS 5432
THE REVERSED NUMBER IS 2345
----------------------------------------------------ENTER THE NUMBER: 258
THE ORIGINAL NUMBER IS 258
THE REVERSED NUMBER IS 852

-4-

C PROGARM TO FIND FIBONACCI SEREIS


#include<stdio.h>
#include<conio.h>
void main()
{
int f1,f2,f3,i,n;
f1=0;
f2=1;
clrscr();
printf("ENTER THE NUMBER:");
scanf("%d",&n);
printf("%d\n",f1);
printf("%d\n",f2);
for(i=2;i<n;i++)
{
f3=f1+f2;
printf("%d\n",f3);
f1=f2;
f2=f3;
}
getch();
}
OUTPUT:
ENTER THE NUMBER
5
0
1
1
2
3
-----------------------------------ENTER THE NUMBER
7
0
1
1
2
3
5
8

C PROGRAM TO GENERATE ELECTRICITY BILL


#include <stdio.h>
main()
{
int oldrd,newrd,diff;

-5-

float rpu,bill,tax;
clrscr();
puts("\nEnter rate per unit ");
scanf("%f",&rpu);
puts("\nEnter old reading ");
scanf("%d",&oldrd);
puts("\nEnter new reading ");
scanf("%d",&newrd);
diff=newrd-oldrd;
puts("\nEnter the Total TAX ");
scanf("%f",&tax);
bill=(rpu*diff)+tax;
printf("\n\n Number of Units are : %d",diff);
printf("\n\n Rate per Unit is : %f",rpu);
printf("\n\n TAX is
: %f",tax);
printf("\n\n Electric Bill is : %f",bill);
}

-6-

OUTPUT
Enter rate per unit
2.90
Enter old reading
123
Enter new reading
234
Enter the Total TAX
80
-------------------------------Number of Units are : 111
Rate per Unit is

: 2.900000

TAX is
: 80.000000
-------------------------------Electric Bill is : 401.900024
---------------------------------------------OUTPUT
Enter rate per unit
1.75
Enter old reading
456
Enter new reading
987
Enter the Total TAX
80
-------------------------------Number of Units are : 531
Rate per Unit is

: 1.7500000

TAX is
: 80.000000
-------------------------------Electric Bill is : 611.0000

-7-

C PROGRAM TO ADD DIAGONAL ELEMENTS OF MATRIX */


#include<stdio.h>
main()
{
int m,n,matrix[50][50],add=0;
clrscr();
printf("\nEnter the matrix of 3x3\n");
for(m=0;m<3;m++)
{
for(n=0;n<3;n++)
{
scanf(" %d",&matrix[m][n]);
}
}
puts("\n Given Matrix :\n");
for(m=0;m<3;m++)
{
printf(" ");
for(n=0;n<3;n++)
{
printf(" %d ",matrix[m][n]);
}
puts("\n");
}
for(m=0;m<3;m++)
{
for(n=0;n<3;n++)
{
if(m==n)
{
add=add+matrix[m][n];
}
}
}
printf("\n Addition of diagonal elements of given matrix : %d",add);
}

-8-

OUTPUT
Enter the matrix of 3x3
123456789
Given Matrix :
1 2 3
4 5 6
7 8 9
Addition of diagonal elements of given matrix : 15
-----------------------------------------------------------------------------Enter the matrix of 3x3
147862359
Given Matrix :
1 4 7
8 6 2
3 5 9
Addition of diagonal elements of given matrix : 16

-9-

C PROGRAM TO FIND BIGGEST AND SMALLEST IN A ARRAY */


#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, a[5],big=0,small;
clrscr();
printf("Enter any digits:");
for( i=0;i<=5;i++)
{
scanf("%d",&a[i]);
if(a[i]>=big)
{
big=a[i];
}
if(a[i]<=small)
{
small=a[i];
}
}
printf("\n\n");
for(i=0;i<=5;i++)
{
printf("%d\n",a[i]);
}
printf("\n\nBiggest Number is:%d",big);
printf("\n\nSmallest Number is:%d",small);
getch();
}

- 10 -

OUTPUT:
Enter any digits:
4500
7008
1004
7821
6599
Biggest Number is:7821
Smallest Number is:1004
OUTPUT:
Enter any digits:
11
12
13
48
47
Biggest Number is:48
Smallest Number is:11

- 11 -

C PROGRAM TO GENERATE TWO PATTERNS */


#include<stdio.h>
main()
{
int i,j;
clrscr();
printf("\nEnter the no");
for(i=1;i<4;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
printf("\n");
for(i=3;i>0;i--)
{
for(j=3;j>=i;j--)
{
printf("%d",j);
}
printf("\n");
}
}

OUTPUT
Enter the no
3
1
12
123
3
32
321

- 12 -

C PROGRAM TO GENERATE BILL OF DISCOUNT BAZAAR


#include<stdio.h>
main()
{
int items,i;
float rate[9000],bill,disc,dr,discbill;
clrscr();
puts("\n Enter number of items");
scanf("%d",&items);
puts("\n Enter rate of each item one by one");
for(i=0;i<items;i++)
{
scanf("%f",&rate[i]);
bill = bill+rate[i];
}
puts("\n Enter the discount rate");
scanf("%f",&disc);
dr=(bill*disc)/100;
discbill=bill-dr;
printf("\n Number of Items are
: %d",items);
printf("\n Total amount of all items is : %f",bill);
printf("\n Discount Rate is
: %f",disc);
printf("\n\n Bill amount is
: %f",discbill);
}

- 13 -

OUTPUT
Enter number of items
5
Enter rate of each item one by one
20.00
34.50
15.90
25.60
5.50
Enter the discount rate
5.5
Numbers of Items are
:5
Total amount of all items is: 101.500000
Discount Rate is

; 5.500000

Bill amount is
: 95.917503
-----------------------------------------------------Enter number of items
5
Enter rate of each item one by one
120.00
134.50
115.90
125.60
105.50
Enter the discount rate
4.5
Numbers of Items are
:5
Total amount of all items is: 601.500000
Discount Rate is
Bill amount is

;4.500000
: 574.43

- 14 -

C PROGRAM FOR SALARY CALCULATION OF 10 EMPLOYEES*/


// ACCEPT NAME,BASIC,DA=43%,HRA=75%,CCA=100
#include<stdio.h>
#include<conio.h>
void main()
{
char name;
int i,n,basic,cca=100;
float da,hra,gp,ns,pf;
clrscr();
printf("\n employees salary \n");
for(n=1;n<=5;n++)
{
printf("\n enter name : ");
scanf("%s",&name);
printf("\n enter the basic salary :");
scanf("%d",&basic);
printf(" \n");
da=(0.43*basic);
hra=(0.75*basic);
gp=(basic+da+hra+cca);
pf=(0.12*basic);
ns=gp-pf;
printf("\n the total salary is %f",ns);
}
getch();
}

- 15 -

OUT PUT:
employees salary
enter name : PAVITRA
enter the basic salary :2500
the total salary is 5250.000000
enter name : ALI
enter the basic salary :4500
the total salary is 9370.000000
enter name : LOKESH
enter the basic salary :3500
the total salary is 7310.000000
enter name : SHIVRAJ
enter the basic salary :4500
the total salary is 9370.000000
enter name : Susma
enter the basic salary :4800
the total salary is 9988.000000

- 16 -

You might also like