Total Program
Transcript of Total Program
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 1/35
/* area of triangle with sides a, b, c*/
#include<stdio.h>
#include<conio.h>
#include<math.h>float area(float a, float b, float c);
void main()
{
float a, b, c, z;
clrscr();
printf("\nenter three sides of the triangle:");
scanf("%f%f%f", &a, &b, &c);
z=area(a, b, c);
printf("\n\n area of the triangle=%3f", z);
getch();
}
/*function to calculate area from a formula*/
float area(float a, float b, float c)
{
float s, m, x;
s=(a+b+c)/2;
m=s*(s-a)*(s-b)*(s-c);
x=sqrt(m);
return(x);
}
******************************output***************************
enter three sides of the triangle:8 9 6
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 2/35
/*calculation of aggregate percentage marks*/
#include <stdio.h>
#include <conio.h>
void main(){
int m1,m2,m3,m4,m5,aggr;
float per;
clrscr();
printf("\nenter marks in 5 subjects:");
scanf("%d%d%d%d%d",&m1,&m2,&m3,&m4,&m5);
aggr=m1+m2+m3+m4+m5;
per=aggr/ 5;
printf("\n aggregate marks=%d",aggr);
printf("\n percentage marks =%f", per);
printf("\n\n\n\n\npress any key to exit....");
getch() ;
}
****************************************output**************
enter marks in 5 subjects:98 59 88 69 80
aggregate marks=394
percentage marks =78.000000
press any key to exit....
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 3/35
/* program to find a number & its frequency in array */
#include<stdio.h>
#include<conio.h>
void main()
{ int num[25], i, count=0,n;
clrscr();
printf("\nenter 25 elements of array:\n");
for(i=0; i<=24; i++)
scanf("%d", & num[i]); /* array elements */
printf("\nenter an element to search:");
scanf("%d", &n);
for(i=0; i<=24; i++)
{
if(num[i]==n)
count++;
}
printf("\nthe number%d found%d time(s) in the array", n,
count);
printf("\n\n\n\n\npress any key to exit.....");
getch();
}
*********************************output************************
enter 25 elements of array:
34 45 2 78 54 23 45 9 4 23 45 65 19 78 34 56 78 24 7 45 23 32 43
76 8
enter an element to search:56
the number56 found1 time(s) in the array
press any key to exit.....
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 4/35
/*program to calculate power of a value*/
#include<stdio.h>
#include<conio.h>
long power(int,int);
void main(){
int x,y;
long pow;
clrscr();
printf("enter two number:");
scanf("%d%d", &x, &y);
pow=power(x,y); /*function call*/
printf("\n%d to the power %d=%d", x,y, pow);
printf("\n\n\n\n\n press any key to exit.....");
getch();
}
long power(int x, int y)
{ int i;
long p=1;
for(i=1; i<=y; i++)
p=p*x;
return(p);
}
**********************output*******************************
enter two number:25 3
25 to the power 3=15625
press any key to exit.....
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 5/35
/*check if point lies within a circle*//*the center of the circle has been assumed to be at o,o*/
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,r;
int dis,d;
clrscr();
printf("\n enter the radius of the circle & coordinates of the
point(x,y):\n");
scanf("%d%d%d",&r,&x,&y);
dis= x*x+y*y; /*or use poe() function*/
d=r*r;
if(dis==d)
printf("\n point is on the circle");
else
{
if(dis>d)
printf("point is outside the circle");
else
printf("point is inside the");
}
printf("\n\n\n\n\n press any key to exit....");
getch();
}
*****************************output**********************
enter the radius of the circle & coordinates of the point(x,y):
3 6,3
point is outside the circle
press any key to exit....
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 6/35
/* to find greatest number using conditional operators */
#include<stdio.h>
#include<conio.h>
void main()
{ int n1, n2, n3, great;
clrscr();
printf("enter three numbers:");
scanf("%d%d%d", &n1, &n2, &n3);
great= n1>n2?(n1>n3?n1:n3):(n2>n3?n2:n3);
printf("greatest number is:%d", great);
printf("\n\n\n\n\npress any key to exit.........");
getch();
}
******************output*****************
enter three numbers: 25 58 36
greatest number is:58
press any key to exit.........
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 7/35
/*conversion of distance*/
#include<stdio.h>
#include<conio.h>
void main()
{ float km, m, cm, ft, inch;
clrscr();
printf("\nenter the distance in kilometers:");
scanf("%f",&km);
m=km*1000;
cm=m*100;
inch=cm/2.54;
ft=inch/12;
printf("\ndistabce in meters=%f",m);
printf("\ndistance in centimeter=%f",cm);
printf("\ndistance in feet=%f",ft);
printf("\ndistance in inches=%f",inch);
printf("\n\n\n\n\npress any key to exit.....");
getch();
}
*********************output**************************
enter the distance in kilometers:9
distabce in meters=9000.000000
distance in centimeter=900000.000000
distance in feet=29527.560547
distance in inches=354330.718750
press any key to exit.....
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 8/35
/*interchanging of contents of two variable c&d*/
#include<stdio.h>
#include<conio.h>
void main(){
int c,d,e;
clrscr();
printf("\nenter the number of location c:");
scanf("%d",&c);
printf("\nenter the number of location d:");
scanf("%d",&d);
/*interchanging the contents of two variables using a third
variables as temporary store*/
e=c;
c=d;
d=e;
printf("\nnew number at location c=%d",c);
printf("\nnew number at location d=%d",d);
printf("\n\n\n\n\npress any key to exit.......");
getch();
}
********************************output*******************
enter the number of location c:69
enter the number of location d:36
new number at location c=36
new number at location d=69
press any key to exit.......
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 9/35
/*sum of digits of a 5 digits number*/
#include<stdio.h>
#include<conio.h>
void main()
{ int num,a,n;
int sum=0; /*sum initialised tozero as otherwise it will
contain garbage value*/
clrscr();
printf("\nenter a 5 digit number( less than 32767)");
scanf("%d",&num);
a=num%10; /*last digit extracted as remainder*/
n=num/10; /*remaining digits*/sum=sum+a; /*sum updated with
addition of extracted digit*/
a=n%10; /*4th digit*/
n=n/10;
sum= sum+a;
a=n%10; /*3rd digit*/
n=n/10;
sum=sum+a;
a=n%10; /*2nd digit*/
n=n/10;
sum=sum+a;
a=n%10; /*1st digit*/
sum=sum+a;
printf("\n the sum of the 5 digits of %d is %d",num,sum);
printf("\n\n\n\n\npress any key to exit....");
getch();
}
*****************************output*********************
enter a 5 digit number( less than 32767)12345
the sum of the 5 digits of 12345 is 15
press any key to exit....
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 10/35
/*binary equivalent of a decimal number*/
#include<stdio.h>
#include<conio.h>
int binary(int);
void main(){
int num;
clrscr();
printf("\nenter the number:");
scanf("%d", &num);
binary(num); /*factorial call*/
printf("\n\n\n\npress any key to exit.....");
getch();
}
/*function to convert decimal to binary*/
int binary(int n)
{
int r;
r=n%2;
n=n/2;
if(n==0)
{
printf("\n the binary equivalent is %d", r);
return(r);
}
else
binary(n); /*recursive call*/
printf("%d", r);}
****************************output*******************************
enter the number:97
the binary equivalent is 1100001
press any key to exit.....
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 11/35
/*to display particular pattern*/
#include<stdio.h>
#include<conio.h>
void main()
{ int i, j, k, l, sp;
sp=20;
for(i=1, k=1; i<5; i++)
{
for(l=1; l<=sp; l++)
printf(" ");
sp=2;
for(j=1; j<=i; j++, k++)
printf("%d",k);
printf("\n");
}
printf("\n\n\n\n\n press any key to exit.....");
getch();
}
**********************output***********************
1
23
456
78910
press any key to exit.....
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 12/35
/*to display a particular pascal’s triangle series*/
#include<stdio.h>
#include<conio.h>
void main()
{ int i,j, k, t, f1, f2, f3, z, sp;sp=20;
clrscr();
for(i=0; i<=4; i++)
{ for(k=0; k<sp-i; k++)
printf(" ");
sp-=2;
for(j=0; j<=i; j++)
{
f1=f2=f3=1;
t=i;
while(t!=0)
{
f1=f1*t;
t--;
}
t=j;
while(t!=0)
{
f2=f2*t;
t--;
}
t=i-j;
while(t!=0){
f3=f3*t;
t--;
}
z=f1/(f2*f3);
printf("%4d ",z);
}
printf("\n");
}
getch();
}
***************************output****************************
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 13/35
/*check whether a number is even or odd*/
#include<stdio.h>
#include<conio.h>
void main()
{ int n;
clrscr();
printf(" enter any number");
scanf("%d",&n);
if(n%2==0) /*remainder after division by 2*/
printf("\nthe number is even");
else
printf("\n the number is odd");
printf("\n\n\n\n\n press any key to exit....");
getch();
}
*********************************OUTPUT*******************
enter any number361
the number is odd
press any key to exit....
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 14/35
/*BUBBLE sort*/
#include<stdio.h>
#include<conio.h>
void main()
{ int a[25], i, j, m, t;
clrscr();
printf("\n enter 25 numbers:");
for(i=0; i<=24; i++)
scanf("%d", &a[i]); /*enter array elements*/
for(i=0; i<=24; i++) /*number of passes*/
{
for(j=0; j<24-i; j++) /* start anthor loop from begning*/
{
/*compare an element with the next element one by one*/
if(a[j]> a[j+1])
{
t=a[j]; /* interchange the two if first is great*/
a[j]=a[j+1];
a[j+1]=t;
}
}
}
printf("\n sorted number are:\n");
for(i=0; i<=24; i++)
printf("%d ", a[i]);
printf("\n\n\n\n\npress any key to exit.......");
getch();}
*************************output***************************
enter 25 numbers:5 6 9 3 5 1 7 85 36 25 32 9 56 1 5 16 25 36 98
57 21 12 35 26 56
sorted number are:
1 1 3 5 5 5 6 7 9 9 12 16 21 25 25 26 32 35 36 36 56 56 57 85 98
press any key to exit.......
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 15/35
/*Generate first 25 terms of fibonacci sequence*/
#include<stdio.h>
#include<conio.h>
void fibo(int, int);
void main(){
int i, t, old=0, current=1, new;
clrscr();
printf("%d %d ", old, current);
fibo(old, current);
printf("\n\n\n\n\n press any key to exit.....");
getch();
}
void fibo(int old, int current)
{
static int terms=2;
int new;
if(terms<20)
{
new=old+current ;
printf("%d ", new);
terms=terms+1;
fibo(current, new);
}
else
return;
}
************************output*******************
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
press any key to exit.....
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 16/35
/* to calculate gross salary of ramesh*/
#include <stdio.h>
#include <conio.h>
void main(){
float bp,da ,hra,grpay;
clrscr(); /*clears screen*/
printf("\nenter the basic pay of ramesh:");
scanf("%f",&bp);
da = 0.4*bp;
hra = 0.2*bp;
grpay = bp+da+hra;/*gross pay = sum of basic & all
allowances*/
printf("\nbasic pay of ramesh =%f",bp);
printf("\ndearness allowance =%f",da);
printf("\nhouse rent allowance=%f",hra);
printf("\ngross pay of ramesh is %f",grpay);
printf("\n\n\n\n\npress any key to exit.........");
getch(); /*reads a character from keyboard*/
}
*****************************output********************
enter the basic pay of ramesh:10000
basic pay of ramesh =10000.000000
dearness allowance =4000.000000
house rent allowance=2000.000000
gross pay of ramesh is 16000.000000
press any key to exit.........
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 17/35
/* insertion sort */
#include<stdio.h>
#include<conio.h>
void main()
{ int a[25], i, j, k, t;
clrscr();
printf("\nenter 10 number:\n");
for(i=0; i<=9; i++)
scanf("%d", &a[i]); /* enter array elements */
for(i=1; i<=9; i++) /* number of passes */
{
t=a[i];
for(j=0; j<i; j++)
{
if(t<a[j])
{
for(k=i; k>=j; k--)
a[k]=a[k-1]; /* interchange elements */
a[j]=t;
break;
}
}
}
printf("\n sorted numbers are:\n");
for(i=0; i<=9; i++)
printf(" %d", a[i]);
printf("\n\n\n\n\n press any key to exit.......");getch();
}
***********************output********************************
enter 10 number:
56 89 25 36 75 32 15 45 65 36
sorted numbers are:
15 25 32 36 36 45 56 65 75 89
press any key to exit.......
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 18/35
/*calculate factorial value of an integer using a function*/
#include<stdio.h>
#include<conio.h>
long fact(int); /*will word upto num=19 only*/
void main()
{
int num;
long factorial;
clrscr();
printf("enter a number:");
scanf("%d", &num);
factorial=fact(num); /*function call*/
printf("\nfactoria; of %d=%1d", num, factorial);
printf("\n\n\n\n\n press any key to exit....");
getch() ;
}
long fact(int num)
{
int i;
long factorial=1;
for(i=1; i<=num;i++)
factorial=factorial*i;
return(factorial);
}
*****************************output***************************
enter a number:7
factoria; of 7=5040
press any key to exit....
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 19/35
/*determine leap or not a leap year*/
#include<stdio.h>
#include<conio.h>
void main()
{ int year;
clrscr();
printf("\n enter year");
scanf("%d", &year);
if(year%400==0|| year % 100 !=0 && year % 4==0)
printf("\n leap year");
else
printf("\n not a leap year");
printf("\n\n\n\n\n press any key to exit....");
getch();
}
************************output********************
enter year2008
leap year
press any key to exit....
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 20/35
/* program to addition two 3*3 matrices */
#include<stdio.h>
#include<conio.h>
void main()
{ int mat1[3][3], mat2[3][3], mat3[3][3], i, j, k, sum;
clrscr();
/* get values for first matrix */
printf("\nenter values for first 3*3 matrix:\n");
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
scanf("%d", &mat1[i][j]);
}
/* get values for second matrix */
printf("\nenter values for second 3*3 matrix:\n");
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
scanf("%d", &mat2[i][j]);
}
/* print the first matrix as entered */
printf("\nthe first 3*3 matrix entered by you is:\n");
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
printf("%d\t", mat1[i][j]);
printf("\n");
}
/* print the second matrix as entered */
printf("\nthe second 3*3 matrix entered by you is:\n");
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
printf("%d\t", mat2[i][j]);
printf("\n");
}
/* calculate the addition of the two matrices */for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
mat3[i][j]=mat1[i][j]+mat2[i][j];
}
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 21/35
/* print the new matrix containg the product */
printf("\nthe addition of the above two matrices is:\n");
for(i=0;i<=2;i++)
{
for(j=0; j<=2; j++)printf("%d\t", mat3[i][j]);
printf("\n");
}
printf("\n\npress any key to exit.......");
getch();
}
***************************output**********************
enter values for first 3*3 matrix:
1 2 3 4 5 6 7 8 9
enter values for second 3*3 matrix:
9 8 7 4 5 6 1 2 3
the first 3*3 matrix entered by you is:
1 2 3
4 5 6
7 8 9
the second 3*3 matrix entered by you is:
9 8 7
4 5 61 2 3
the addition of the above two matrices is:
10 10 10
8 10 12
8 10 12
press any key to exit.......
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 22/35
/* program to Addition two 3*3 matrices */
#include<stdio.h>
#include<conio.h>
void main(){
int mat1[3][3], mat2[3][3], mat3[3][3], i, j, k, sum;
clrscr();
/* get values for first matrix */
printf("\nenter values for first 3*3 matrix:\n");
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
scanf("%d", &mat1[i][j]);
}
/* get values for second matrix */
printf("\nenter values for second 3*3 matrix:\n");
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
scanf("%d", &mat2[i][j]);
}
/* print the first matrix as entered */
printf("\nthe first 3*3 matrix entered by you is:\n");
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
printf("%d\t", mat1[i][j]);printf("\n");
}
/* print the second matrix as entered */
printf("\nthe second 3*3 matrix entered by you is:\n");
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
printf("%d\t", mat2[i][j]);
printf("\n");
}/* calculate the product of the two matrices */
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
{
sum=0;
for(k=0; k<=2; k++)
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 23/35
sum=sum+mat1[i][k]*mat2[k][j];
mat3[i][j]=sum;
}
}
/* print the new matrix containg the product */
printf("\nthe product of the above two matrices is:\n");
for(i=0;i<=2;i++)
{
for(j=0; j<=2; j++)
printf("%d\t", mat3[i][j]);
printf("\n");
}
printf("\n\npress any key to exit.......");
getch();
}
*************************************output***********************
******
enter values for first 3*3 matrix:
1 2 3 4 5 6 7 8 9
enter values for second 3*3 matrix:
9 8 7 4 5 6 1 2 3
the first 3*3 matrix entered by you is:
1 2 3
4 5 67 8 9
the second 3*3 matrix entered by you is:
9 8 7
4 5 6
1 2 3
the product of the above two matrices is:
20 24 28
62 69 76
104 114 124
press any key to exit.......
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 24/35
/*program for 1223334444
55555 */
#include"stdio.h"
#include"conio.h"
void main()
{
int i,j,n;
printf(" Enter any number ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
getch();
}
**********************************output************************
Enter any number 9
1
22333
4444
55555
666666
7777777
88888888
999999999
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 25/35
/*program for 1121231234
12345 */
#include"stdio.h"
#include"conio.h"
void main()
{
int i,j,n;
printf(" Enter any number ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}
*******************************output************************
Enter any number 9
1
12123
1234
12345
123456
1234567
12345678
123456789
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 26/35
/*program for 12 34 5 66 8 9 10
11 12 13 14 */
#include"stdio.h"
#include"conio.h"
void main()
{
int i,j,n,a=1;
printf(" Enter any number ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf(" %d ",a);
a++;
}
printf("\n");
}
getch();
}
**************output************************
Enter any number 91
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
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 27/35
/*program to generate all prime numbers from 1to 300*/
#include<stdio.h>
#include<conio.h>
void main()
{ int i, n=1;
clrscr();
printf("\n prime numbers between 1&300 are: \n1\t");
while(n<=300) /*loop to check numbers upto 300*/
{
i=2;
while(i<n) /*loop starting from 2 to the number*/
{
if(n%i==0)
break; /*takes control out of the inner while as soon
as the number is fully divisible*/
else
i++;
}
if(i==n)
printf("%d\t", n); /*tab is used to print all number in
one screen*/
n++;
}
getch();
}
********************************output**************************
prime numbers between 1&300 are:
1 2 3 5 7 11 13 17 19
23
29 31 37 41 43 47 53 59 61
67
71 73 79 83 89 97 101 103
107 109
113 127 131 137 139 149 151 157
163 167173 179 181 191 193 197 199 211
223 227
229 233 239 241 251 257 263 269
271 277 281 283 293
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 28/35
/*program to produce a typical pattern*/
#include<stdio.h>
#include<conio.h>
void main()
{ int i=1, x=71, blanks=0, j, val, k;
clrscr();
while(i<=7)
{
j=65; /*ascii value of a*/
val=x;
while(j<=val)
{
printf(" %c",j);
j++;
}
if(i==1)
val--;
k=1;
while(k<=blanks)
{
printf(" ");
k++;
}
blanks=2*i-1;
while(val>=65)
{
printf(" %c",val);val--;
}
printf("\n");
x--;
i++;
}
getch();
}
**********************************output**************************
****A B C D E F G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 29/35
/*program for structure*/
#include"process.h"
#include"stdio.h"
#include"conio.h"
struct record{
char name[10];
int code,rate;
};
void main()
{
int a;
static int i=0;
int c,code;
char ch,ans;
struct record r[100];
while(1)
{
clrscr();
printf("1. Record entry \n\n");
printf("2. List of record \n\n");
printf("3. Delete any record \n\n");
printf("4. Quit \n\n");
printf("enter your choice \t");
scanf("%c",&ch);
switch(ch)
{
case '1':do
{
printf("\n your %d record :",i+1);
printf("\n name\t\t");
scanf("%s",r[i].name);
printf("Code\t\t");
scanf("%d",&r[i].code);
printf("rate : \n\t\t");
scanf("%d",&r[i].rate);
i++;
printf("\n Do you want more");ans=getch();
}while(ans=='Y'||ans=='y');
break;
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 30/35
case '2' : printf("Code\t\t Name\t rate");
for(c=0;c<i;c++)
{
printf("\n %d \t\t %s\t %d",r[c].code,r[c].name,r[c].rate);
}break;
case '3' :printf("enter Code which record you want Delete :");scanf("%d",&code);
for(c=0;c<i;c++)
{
for(c=c;c<i;c++)
{
r[c].code=r[c+1].code;
strcpy(r[c].name,r[c+1].name);
r[c].rate=r[c+1].rate;
}i--;
break;
// }
}break;
case '4' :exit(0);
break;
}
getch();
}
}
***************************OUTPUT********************
1. Record entry
2. List of record
3. Delete any record
4. Quit
enter your choice 2
Code Name rate
22 GFG 89
4 KJ 98
3 67 34
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 31/35
/*program for string ** ** * ** * * * */
#include"stdio.h"#include"conio.h"
void main()
{
int i,j,n;
clrscr();
printf(" Enter any number ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf(" * ");
}
printf("\n");
}
getch();
}
*****************OUTPUT********************
Enter any number 9
*
* *
* * ** * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 32/35
/*program for reverse number */
#include"stdio.h"
#include"conio.h"
void main()
{int n,i=0;
clrscr();
printf(" Enter any number ");
scanf("%d",&n);
printf("Reverse number is:=");
while(n!=0)
{
i=n%10;
printf("%d",i);
n=n/10;
}
getch();
}
*******************************output**************************
Enter any number 12345
Reverse number is:=54321
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 33/35
/*to reverse the digits of a 5 digit number*/
#include<stdio.h>
#include<conio.h>
void main()
{long int n, a,b;
long int revnum=0;
/*intialised otherwise it will contain garbage value. declared as
long as after reversing it may not be in the range*/
clrscr();
printf("\nenter a five digit number:=");
scanf("%ld",&n);
a=n%10; /*last digit*/
n=n/10; /*remaining digits*/
revnum=revnum+a*10000l; /*revnum updated with value of
extracted digit*/
a=n%10; /*4th digit*/
n=n/10; /*remaining digits*/
revnum=revnum+a*1000;
a=n%10; /*3rd digits*/
n=n/10; /*remaining digits*/
revnum=revnum+a*100;
a=n%10; /*2nd digit*/
n=n/10; /*remaining digits*/
revnum=revnum+a*10;
a=n%10; /*1st digit*/
revnum=revnum=revnum+a;
/*specifier %1d is used for printing a long integer*/
printf("\n the reversed number is %ld", revnum);
printf("\n\n\n\n\npress any key to exit.......");
getch();
}
******************************output****************************
enter a five digit number:=15541
the reversed number is 14551
press any key to exit.......
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 34/35
/*program for ** ** * ** * * ** * * * * */
#include"stdio.h"
#include"conio.h"
void main()
{
int i,j,n=0,s;
clrscr();
printf("\nEnter number : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(s=1;s<=n-i;s++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf(" *");
}
printf("\n");
}
getch();
}
Enter number : 12
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * ** * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * *
5/13/2018 Total Program - slidepdf.com
http://slidepdf.com/reader/full/total-program 35/35
/*program for table display*/
#include<stdio.h>
#include<conio.h>
void main()
{ int a,i,x;
clrscr();
printf("enter any number:");
scanf("%d", &a);
printf(" table of enter number is:");
for(i=1;i<=10; i++)
{
x=a*i;
printf("\n%d", x);
}
getch();
}
*************************output************************
enter any number:9
table of enter number is:
9
18
27
36
45
54
6372
81
90