You are on page 1of 37

Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
EXPERIMENT 1: PROGRAM TO PRINT THE SIZES AND sizeof(double),DBL_MIN_10_EXP,DBL_MA
RANGES OF DIFFERENT DATA TYPES X_10_EXP);
printf("\nLONG DOUBLE %d 3.4E%d
#include<stdio.h> 1.1E+%d",
#include<conio.h> sizeof(long
#include<limits.h> double),LDBL_MIN_10_EXP,LDBL_MAX_10_EXP);
#include<float.h> printf("\nCHARACTER(SIGNED) %d %d
void main() %d",
{ sizeof(char),SCHAR_MIN,SCHAR_MAX);
clrscr(); printf("\nUNSIGNED CHAR %d %d
printf(" DATA TYPE SIZE IN BYTES MINIMUM %d",
VALUE MAXIMUM VALUE"); sizeof(unsigned char),0,UCHAR_MAX);
printf("\n INTEGER(SIGNED) %d %i %d ", getch();
sizeof(int),INT_MIN,INT_MAX); }
printf("\nSHORT INTEGER %d %hi %hd", EXPERIMENT 2: DEMONSTRATING INTEGER
sizeof(short),SHRT_MIN,SHRT_MAX); CONSTANTS
printf("\nLONG INTEGER %d %ld %ld", #include<stdio.h>
sizeof(long),LONG_MIN,LONG_MAX); #include<conio.h>
printf("\nUNSIGNED INTEGER %d %u void main()
%u", {
sizeof(unsigned int),0,UINT_MAX); clrscr();
printf("\nUNSIGNED SHORT INTEGER %d %u printf("\n integer constants are three types");
%u", printf("\n[1] decimal integer consist of a set of digits,0 through
sizeof(unsigned short),0,USHRT_MAX); 9,\npreceded by an
printf("\nUNSIGNED LONG INTEGER %d %d optional - or + sign");
%lu", printf("\n valid examples of decimal integer constants are:");
sizeof(unsigned long),0,ULONG_MAX); printf("\nint %d \n int %d \n long int %ld \n unsigned long int
printf("\nFLOAT %d 3.4E%d 3.4E+%d", %lu \n long int
sizeof(float),FLT_MIN_10_EXP,FLT_MAX_10 %ld",+123,-378,-32271L,76542LU,12789845L);
_EXP); printf("\n[2] an octal integer constant consists of any
printf("\nDOUBLE %d 1.7E%d 1.7E+%d", combination of 0 through 7, with a

1
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
leading 0(means starting with 0)"); printf("\n a real number may also be expressed in exponential
printf("\n valid examples of octal integers:"); notation (or scientific
printf("\n octal integers %o \t %o \t %o \t notation)");
%o",037,0,0435,0551); printf("\n for example the value 215.65 may also be written as
printf("\n[3] A sequence of digits preceded by 0x and 0X is 2.1565e+2 where
considered as hexadecimal e2=100");
integer constants\nthey may also include alphabets A printf("\nexamples of legal floating point constants:");
through F or a through f\n printf("\n %f \t %f \t %f \t %f \t %f ",0.65e4,12e-
the letters A or a through F or f represents the 2,1.5e+5,3.18E+3,-1.2E-1);
numbers 10 to 15"); getch();
printf("\n following are the examples of valid hex integers"); }
printf("\n %X \t %x \t %X \t %x",0X2,0x9F,0Xbcd,0); EXPERIMENT 4: DEMONSTRATING CHARACTER AND
getch(); STRING CONSTANTS
} #include<stdio.h>
EXPERIMENT 3: DEMONSTRATING FLOATING POINT #include<conio.h>
CONSTANTS void main()
#include<conio.h> {
#include<stdio.h> int i,l;
void main() char string1[10]="MRITS";
{ clrscr();
clrscr(); printf("\n a single character constant contains a single
printf("\nReal constants are often known as floating point character enclosed between a pair
constants"); of single quote marks");
printf("\ninteger constants are unfit for many quantities for printf("\ncharacter constants have integer values known as
example ASCII values");
length,breadth,radius,price etc"); printf(" the ASCII (american standard code for information
printf("\n real numbers are in decimal notation, having a interchange) values of some
whole number followed by a character constants are :");
decimal point and a fractional part"); for(i=35;i<=122;i++)
printf("\n for example %f \t %f \t %f \t %f are valid real printf(" %c=%d\t ",i,i);
numbers", 21.5,.95,-.71,+.5);

2
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
printf("\n a string constant is a sequence of character enclosed printf("\n[1] Airthmetic operators");
in double quotes"); printf("\n[2] increment and decrement operators");
printf("\n the character may be letters,numbers,special printf("\n[3] relational operators");
characters and blank space"); printf("\n[4] Logical operators");
l=printf("\n%s",string1);/* now l contains length of the printf("\n[5] Bitwise operators");
string*/ printf("\nEnter ur choice");
puts(string1); scanf("%d",&choice);
for(i=0;i<l;i++)/* the is the another way of printing string*/ switch(choice)
printf("%c",string1[i]); {
printf("\n backslash characters constants are:"); case 1: {
printf("\n audible alert(bell) \a"); int a=5,b=3;
printf("\n back space mri\bts"); float x=5,y=3;
printf("\n new line \n"); clrscr();
printf("\n carriage return \r"); printf("\n integer addition a+b=%d \n float addition
printf("\n horizontal tab \t mrits"); x+y=%f ",a+b,x+y);
printf("\n vertical tab \v mrits"); printf("\n integer subtraction a-b=%d \n float
printf("\n single quote '\'' "); subtraction x-y=%f",a-b,x-y);
printf("\n double quote '\"' "); printf("\n integer multiplication a*b=%d \n float
printf("\n quetion mark '\?' "); multiplication
printf("\n backslash '\\' "); x*y=%f",a*b,x*y);
printf("\n null character '\0' "); printf("\n integer quetiont division a/b=%d \n
integer remainder division
getch(); amodb=%d",a/b,a%b);
} printf("\n there is no exact division in integer
EXPERIMENT 5: DEMONSTRATING C OPERATORS division \n and there is no
#include<stdio.h> remainder or quetiont division in float
#include<conio.h> division");
void main() printf("\n exact division or float division
{ x/y=%f",a/b);
int choice; }
clrscr(); break;

3
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
case 2: { clrscr();
int a=5; printf(" \n logical AND: logical OR");
clrscr(); printf(" \n 5<3 && 5>10 =%d 5<3 || 5>10 =%d
printf("\n now the a value is %d",a); ",5<3&&5>10,5<3||5>10);
printf("\n prefix increment ++a=%d",++a); printf("\n 5<3 && 5<10 =%d 5<3 || 5<10
printf("\n now the a value is %d",a); =%d",5<3&&5<10,5<3||5<10);
printf("\n prefix decrement --a=%d",--a); printf("\n 5>3 && 5>10 =%d 5>3 || 5>10
printf("\n now the a value is %d",a); =%d",5>3&&5>10,5>3||5>10);
printf("\n postfix increment a++=%d",a++); printf("\n 5>3 && 5<10 =%d 5>3 || 5<10
printf("\n now the a value is %d",a); =%d",5>3&&5<10,5>3||5<10);
printf("\n postfix decremnt a--=%d",a--); printf("\n logical NOT:");
printf("\n now the a value is %d",a); printf("\n !(8==8) =%d \t !(8==9)
} =%d",!(8==8),!(8==9));
break; }
case 3:{ break;
clrscr(); case 5:{
printf("\n Not equal to operator 10!=10 =%d", int x=8,y=2;
10!=10); clrscr();
printf("\n Equal to operator 10==10 printf("\n x=%d \t y=%d",x,y);
=%d",10==10); printf("\nBITWISE operators:");
printf("\n greater than or equal to operator 10>=10 printf("\n Right shift x>>2 =%d",x>>2);
=%d", 10>=10); printf("\n Left shift y<<3 =%d",y<<3);
printf("\n lesser than or equal to operator 10<=10 printf("\n Bitwise AND x&y =%d",x&y);
=%d",10<=10); printf("\n Bitwise OR x|y =%d",x|y);
printf("\n greater than operator 10>10 =%d and printf("\n Bitwise Exclusive OR x^y =%d",x^y);
11>10 =%d",10>10,11>10); printf("\n ones complemnt ~x =%d \t~(~x)
printf("\n lesser than operator 10<11 =%d and =%d",~x,~(~x));
10<10 =%d",10<11,10<10); }
} break;
break; default: printf("\n please choose ur choice between 1 to 5");
case 4:{ }

4
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
getch(); break;
} case 3 : a=a*b;
EXPERIMENT 6: INTERCHANGING VALUES OF TWO b=a/b;
VARIABLES a=a/b;
#include<stdio.h> break;
#include<conio.h> default : clrscr();
void main() printf("\n enter correct option");
{ break;
int a,b,temp; }
int option; printf("\n a=%d \t b=%d",a,b);
clrscr(); getch();
printf("\n enter the values of a AND b"); }
scanf("%d%d",&a,&b); EXPERIMENT 7: DEMONSTRATING TYPECASTING IN C
printf("\n a=%d \t b=%d",a,b); #include<stdio.h>
printf("\n[1] swaping with using temporary variable"); #include<conio.h>
printf("\n[2] swaping without using temporary variable void main()
type1"); {
printf("\n[3] swaping without using temporary variable clrscr();
type2"); printf("\n when the types of the two operands in a binary
printf("\n enter ur otion"); expression\n are different c automatically converts one type to
scanf("%d",&option); another called automatic promotion or IMPLICIT TYPE
CONVERSION");
switch(option) printf("\n the following block demonstrate implicit type
{ conversion");
case 1 : temp=a; printf("\n lower type automaticaly promotes to higer type");
a=b; {
b=temp; /* local declarations */
break; char c= 'A';
case 2 : a=a+b; float d=245.3;
b=a-b; int i=3650;
a=a-b; short s=78;

5
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
printf("\n char=%c \t float=%g \t int=%d \t short=%hd EXPERIMENT 8: MAXIMUM OF THREE NUMBERS
",c,d,i,s); USING IF,ELSE IF LADDER,NESTED IF AND
printf("\n float + char = float %f",d+c);/* char promoted to CONDITIONAL OPERATOR
float */ #include<stdio.h>
printf("\n int * short =int %d",i*s);/* short promoted to int #include<conio.h>
*/ void main()
printf("\n float * char = float %f",d*c);/* char promoted to {
float */ int a,b,c,choice;
printf("\n c=%d and c=%c ",c,c); clrscr();
} printf("\n enter the values for a,b and c");
printf("\n we can convert the data from one type to another scanf("%d%d%d",&a,&b,&c);
instead of complier using EXPLICIT TYPE CONVERSION"); printf("\n a=%d \t b=%d \t c=%d",a,b,c);
printf("\nthe following block demonstrate explicit type printf("\n MAXIMUM OF THREE NUMBERS USING");
conversion"); printf("\n[1] simplle if");
{ printf("\n[2] if else if ladder");
char c='\0'; printf("\n[3] nested if");
int a=100,b=45; printf("\n[4] conditional operator");
double x=100.0,y=45.0; printf("\n enter your choice");
double z; scanf("%d",&choice);
printf("\n char=%c \t a=%d \t b=%d \t x=%f \t switch(choice)
y=%g",c,a,b,x,y); {
z=(double)(a/b); case 1: if(a>b&&a>c)
printf("\n (double)(a/b)=%6.2f",z); printf("\n a=%d is big",a);
z=(double)a/b; if(b>a&&b>c)
printf("\n (double)(a/b)=%6.2f",z); printf("\n b=%d is big",b);
c=(char)(x/y); if(c>a&&c>b)
printf("\n (char)(x/y)=%3d",c); printf("\n c=%d is big",c);
} getch(); } break;
case 2: if(a>b&&b>c)
printf("\n a=%d is big",a);
else if(b>c)

6
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
printf("\n b=%d is big",b); and one operator form the user,performs the operation
else and then prints the result.
printf("\n c=%d is big",c); (Consider the operators +,-,*, /, % and use Switch Statement)
break;
case 3: if(a>b)
{ #include<stdio.h>
if(a>c) #include<conio.h>
printf("\n a=%d is big",a);
else void main()
printf("\n c=%d is big",c); {
} int a,b,res,ch;
else clrscr();
{ printf("\t *********************");
if(b>c) printf("\n\tMENU\n");
printf("\n b=%d is big",b); printf("\t********************");
else printf("\n\t(1)ADDITION");
printf("\n c=%d is big",c); printf("\n\t(2)SUBTRACTION");
} printf("\n\t(3)MULTIPLICATION");
break; printf("\n\t(4)DIVISION");
case 4: (a>b&&b>c)?printf("\n a=%d is printf("\n\t(5)REMAINDER");
big",a):(b>c)?printf("\n b=%d is big",b):printf("\n c=%d is printf("\n\t(0)EXIT");
big",c); printf("\n\t********************");
break; printf("\n\n\tEnter your choice:");
default : printf("\n enter correct choice"); scanf("%d",&ch);
break;
if(ch<=5 & ch>0)
} {
getch(); printf("Enter two numbers:\n");
} scanf("%d%d",&a,&b);
EXPERIMENT9: Write a C program, which takes two integer }
operands

7
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
switch(ch)
{ default:
case 1: printf("\n Invalid Choice");
res=a+b; }
printf("\n Addition:%d",res); getch();
break; }
EXPERIMENT 10: PROGRAM WILL EXAMINE THE
case 2: VALUE OF A FLOATING POINT
res=a-b; VARIABLE CALLED TEMP AND PRINT ICE IF
printf("\n Subtraction:%d",res); TEMP<0,WATER IF
break; 0<=TEMP<=100 AND STEAM IF TEMP>100

case 3: #include<conio.h>
res=a*b; #include<stdio.h>
printf("\n Multiplication:%d",res); void main()
break; {
int n;
case 4: float temp;
res=a/b; printf("\nenter the value for temp");
printf("\n Division:%d",res); scanf("%f",&temp);
break; if(temp<0)
n=1;
case 5: else if(temp<=100)
res=a%b; n=2;
printf("\n Remainder:%d",res); else
break; n=3;
switch(n)
case 0: {
printf("\n Choice Terminated"); case 1: printf("\n ICE");
exit(); break;
break; case 2: printf("\n WATER");

8
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
break; bin=1;
case 3: printf("\n STEAM"); else
break; bin=(bin*(q-x+1))/x;
} printf("%6d",bin);
getch(); }
}
EXPERIMENT 12A: Write a C program to generate Pascal's printf("\n");
triangle. ++q;
}
#include<stdio.h> getch();
#include<conio.h> }
EXPERIMENT 12B:Write a C program to construct a pyramid
void main() of numbers.
{
int bin,p,q,r,x; #include<stdio.h>
clrscr(); #include<conio.h>
bin=1;
q=0; void main()
{
printf("Rows you want to input:"); int num,i,y,x=35;
scanf("%d",&r); clrscr();
printf("\nEnter the number to generate the pyramid:\n");
printf("\nPascal's Triangle:\n"); scanf("%d",&num);

while(q<r) for(y=0;y<=num;y++)
{ {
for(p=40-3*q;p>0;--p) /*(x-coordinate,y-coordinate)*/
printf(" "); gotoxy(x,y+1);
for(x=0;x<=q;++x)
{ /*for displaying digits towards the left and right of zero*/
if((x==0)||(q==0)) for(i=0-y;i<=y;i++)

9
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
clrscr();
printf("%3d",abs(i)); printf("\nenter no for which you want to print Multiplication
x=x-3; table and also enter upto how many Values do you want to print
} it");
getch(); scanf("%d%d",&n,&m);
} for(i=1;i<=m;i++)
EXPERIMENT 12C : {
#include<stdio.h> printf("%d*%d=%d",n,i,n*i);
#include<conio.h> printf("\n");
void main() }
{ getch();
int n,i,j,k; }
clrscr(); EXPERIMENT 12E:
printf("\nEnter an integer number"); #include<stdio.h>
scanf("%d",&n); #include<conio.h>
for(i=1;i<=n;i++) void main()
{ {
for(k=0;k<=20-i;k++) int n,i,j;
printf(" "); clrscr();
for(j=i;j>=1;j--) printf("\nEnter an integer number");
printf("%4d",i); scanf("%d",&n);
printf("\n"); for(i=1;i<=n;i++)
} {
getch();
} for(j=1;j<=i;j++)
EXPERIMENT 12D: program to print multiplication table printf("%2d",i);
#include<stdio.h> printf("\n");
#include<conio.h> }
void main() getch();
{ }
int i, m, n; EXPERIMENT 12F:

10
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
#include<stdio.h> }
#include<conio.h> getch();
void main()
{ }
int n,i,j; EXPERIMENT 12H:
clrscr(); #include<stdio.h>
printf("\nEnter an integer number"); #include<conio.h>
scanf("%d",&n); void main()
for(i=1;i<=n;i++) {
{ int n,i,k,j;
for(j=i;j>=1;j--) clrscr();
printf("%2d",j); printf("\nEnter an integer number");
printf("\n"); scanf("%d",&n);
} for(i=1;i<=n;i++)
getch(); {
for(k=1;k<=20-i;k++)
} printf(" ");
EXPERIMENT 12 G: for(j=1;j<=i;j++)
#include<stdio.h> printf("%2d",i);
#include<conio.h> printf("\n");
void main() }
{ getch();
int n,i,j; }
clrscr(); EXPERIMENT 13A:GENERATING PRIME NUMBERS
printf("\nEnter an integer number"); (USE BREAK STATEMENT)
scanf("%d",&n); #include<stdio.h>
for(i=1;i<=n;i++) #include<conio.h>
{ void main()
for(j=1;j<=i;j++) {
printf("%2d",j); int i,j,n,r;
printf("\n"); clrscr();

11
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
printf("\n enter any number"); }
scanf("%d",&n); getch();
for(i=2;i<=n;++i) }
{ 14A:PROGRAM TO CONVERT DECIMAL TO BINARY
r=1; #include<conio.h>
for(j=2;j<=i/2;++j) #include<stdio.h>
{ void main()
r=i%j; {
if(r==0) int num,rem,a=1,k;
break; long int binaryno=0;
} clrscr();
if(r!=0) printf("\nEnter the number");
printf("%d\t",i); scanf("%d",&num);
} k=num;
getch(); while(k>0)
} {
EXPERIMENT 13B:PROGRAM TO PRINT A-Z AND a-z rem=k%2;
USING ASCII VALUES(USE CONTINUE STATEMENT) binaryno=binaryno+rem*a;
#include<stdio.h> k=k/2;
#include<conio.h> a=a*10;
void main() }
{ printf("\n Decimal number=%d-Binary
int i; number=%ld",num,binaryno);
clrscr(); getch();
printf("\n the ASCII values for A-Z and a-b are:"); }
for(i=65;i<=122;i++) EXPERIMENT 14B:PROGRAM TO CONVERT BINARY TO
{ DECIMAL
if(i>90&&i<97) #include<conio.h>
continue; #include<math.h>
else #include<stdio.h>
printf("\t%c = %d",i,i); void main()

12
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
{ do
long binaryno,binno; {
int rem,decimalno=0,i=0; if(n%2==0)
clrscr(); {
printf("\nEnter a binary no"); ecount++;
scanf("%ld",&binaryno); printf("\n%d is even no",n);
binno=binaryno; esum=esum+n;
while(binaryno!=0) }
{ else
rem=binaryno%10; {
decimalno=decimalno+rem*pow(2,i); ocount++;
binaryno=binaryno/10; printf("\n %d is odd no",n);
i++; osum=osum+n;
} }
printf("\n Equivalent decimal number for binary no %ld is printf("\n Enter a integer");
%d",binno,decimalno); scanf("%d",&n);
getch(); }while(n>0);
} printf("\n total no of even numbers is %d",ecount);
EXPERIMENT 15A:PROGRAM TO ACCEPT INTEGER printf("\n total no of odd numbers is %d",ocount);
VALUES AND TO FIND TOTAL EVEN AND VALUES printf("\n sum of even numbers is %d",esum);
ENTERED,EVEN SUM AND ODD SUM.THE PROGRAM printf("\n sum of odd numbers is %d",osum);
MUST EXIT IF NEGITIVE VALUE IS ENTERED. getch();
( USE DO WHILE LOOP) }
#include<stdio.h>
#include<conio.h> EXPERIMENT 15B:PROGRAM TO ACCEPT INTEGER
void main() VALUES AND TO FIND TOTAL EVEN AND VALUES
{ ENTERED,EVEN SUM AND ODD SUM. (USE FOR LOOP)
int ecount=0,ocount=0,esum=0,osum=0,n=0; #include<stdio.h>
clrscr(); #include<conio.h>
printf("\n enter the numbers"); void main()
scanf("%d",&n); {

13
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
int ecount=0,ocount=0,esum=0,osum=0,n=0,i; IV) 1+1/2+1/3-------1/N HARMONIC SERIES
clrscr(); V)
for(i=1;i<=20;i++)
{ #include<stdio.h>
printf("\n enter an integer\n"); #include<conio.h>
scanf("%d",&n); #include<math.h>
void main()
if(n%2==0) {
{ int n,sum=0,sqsum=0,cubsum=0;
ecount++; float hsum=0,hsqsum=0,i;
printf("\n%d is even no \n",n); clrscr();
esum=esum+n; printf("\n enter the value of n");
} scanf("%d",&n);
else for(i=1;i<=n;i++)
{ {
ocount++; sum=sum+i;
printf("\n %d is odd no \n",n); sqsum=sqsum+i*i;
osum=osum+n; cubsum=cubsum+pow(i,3);
} hsum=hsum+(1/i);
} hsqsum=hsqsum+1/pow(i,2);
printf("\n total no of even numbers is %d",ecount); }
printf("\n total no of odd numbers is %d",ocount); printf("\n sum of %d natural numbers=%d",n,sum);
printf("\n sum of even numbers is %d",esum); printf("\n sum of squares of n natural numbers =%d",sqsum);
printf("\n sum of odd numbers is %d",osum); printf("\n sum of cubes of n natural numbers=%d",cubsum);
getch(); printf("\n harmonic series sum=%f",hsum);
} printf("\n squares of harmonic serie sum=%f",hsqsum);
getch();
EXPERIMENT 16:PROGRAM TO FIND THE SERIES }
I) SUM OF N NATURAL NUMBERS EXPERIMENT 17A AND 17B:PROGRAM TO FIND
II) SUM OF SQUARES OF N NATURAL NUMBERS I) 1+X2/2!+X4/4!+X6/6!+-------
III) SUM OF CUBES OF N NATURAL NUMBERS II) X+X2/2!+X4/4!+X6/6!+-------

14
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
#include<stdio.h> int n,i,x,c=3,fact,j;
#include<math.h> float sum;
#include<conio.h> clrscr();
void main() printf("\n Enter the values of x and n");
{ scanf("%d%d",&x,&n);
int i,j,n,x; sum=x;
float sum,ssum,fact; for(i=3;i<=n;i=i+2)
clrscr(); {
printf("\n Enter the values of x and n"); fact=1;
scanf("%d%d",&x,&n); for(j=1;j<=i;j++)
sum=1; fact=fact*j;
ssum=x; if(c%2!=0)
for(i=2;i<=n;i=i+2) sum=sum-pow(x,i)/fact;
{ else
fact=1; sum=sum+pow(x,i)/fact;
for(j=1;j<=i;j++) c++;
fact=fact*j; }
sum=sum+pow(x,i)/fact; printf("\n sum of series numbers %f",sum);
ssum=ssum+pow(x,i)/fact; getch();
} }
printf("\n 1+x2/2!+x4/4!+_______n =%f",sum); EXPERIMENT 17D:Write a C program to read in two
printf("\n x+x2/2!+x4/4!+_______n =%f",ssum); numbers, x and n, and then compute the sum of this
getch(); geometric progression:
} 1+x+x2+x3+-----+xn
EXPERIMENT 17C:PROGRAM TO FIND THE SERIES For example: if n is 3 and x is 5,
X-X3/3!+X5/5!+------------ then the program computes 1+5+25+125.
#include<stdio.h> #include<stdio.h>
#include<math.h> #include<conio.h>
#include<conio.h> #include<math.h>
void main()
{ void main()

15
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
{ int i,j,fact,n,sum=0;
int s_sum,i,x,n; float hsum=0;
clrscr();
clrscr(); printf("\n Enter the value of n");
printf("Enter the values for x and n:"); scanf("%d",&n);
scanf("%d %d",&x,&n); for(i=1;i<=n;i++)
{
if(n<=0 || x<=0) fact=1;
{ for(j=1;j<=i;j++)
printf("Value is not valid\n"); fact=fact*j;
} sum=sum+fact;
else hsum=hsum+(float)1/fact;
{ }
printf("Value is valid\n"); printf("\n 1!+2!+3!+----------n! =%d",sum);
s_sum=1; printf("\n 1/1!+1/2!+1/3!+-------1/n! =%f",hsum);
for(i=1;i<=n;i++) getch();
{ }
s_sum=s_sum+pow(x,i); EXPERIMENT 17F: Write a C program to calculate the
} following Sum:
printf("Sum of series=%d\n",s_sum); Sum=1-x2/2! +x4/4!-x6/6!+x8/8!-x10/10!
}
getch();
} #include <stdio.h>
#include <math.h>
EXPERIMENT 17E: PROGRAM TO FIND THE SERIES
I) 1!+2!+3!+-------N! void main()
II) 1/1!+1/2!+1/3!+-----1/N! {
#include<stdio.h> int counter,f_coun;
#include<conio.h> float sum=0,x,power,fact;
void main() clrscr();
{

16
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
printf("<-----------------------PROGRAM FOR SUM OF EQ. #include<conio.h>
SERIES----------------------->");
printf("\n\n\tEQUATION SERIES : 1- X^2/2! + X^4/4! - void main()
X^6/6! + X^8/8! - X^10/10!"); {
int num, rem, sum=0,reverse=0,t,arm=0;
printf("\n\n\n\tENTER VALUE OF X : "); clrscr();
scanf("%f",&x); printf("Enter the number s:");
scanf("%d",&num);
for(counter=0, power=0; power<=10; t=num;
counter++,power=power+2) while(num!=0)
{ {
fact=1; rem=num%10;
//CALC FACTORIAL OF POWER VALUE reverse=reverse*10+rem;
for(f_coun=power; f_coun>=1; f_coun--) sum=sum+rem;
fact *= f_coun; num=num/10;
//EQ. FOR SUM SERIES arm=arm+rem*rem*rem;
sum=sum+(pow(-1,counter)*(pow(x,power)/fact)); }
} printf("\nSum of the digits:%d",sum);
printf("\nSum of the cubes of individual digits=%d",arm);
printf("SUM : %f",sum); printf("\nreverse of %d is %d",t,reverse);
getch(); if(t==reverse)
printf("\n%d is palindrome",t);
} else
EXPERIMENT 18: PROGRAM TO FIND printf("\n%d is not palindrome",t);
I)SUM OF INDIVIDUAL DIGITS OF A NUMBER if(t==arm)
II)REVERSE OF A NUMBER printf("\n%d is armstrong",t);
III)SUM OF CUBES OF INVIDUAL DIGITS OF A else
NUMBERS printf("\n%d is not armstrong",t);
IV)CHECKING THE NUMBER FOR PALINDROME
V)CHECKING THE NUMBER FOR ARMSTRONG getch();
#include<stdio.h> }

17
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
EXPERIMENT 19A:STORAGE CLASSES {
DEMONSTRATING THE WORKING OF AUTO/LOCAL register int i;
AND /* register variables are mostly used for loop control
EXTERN/GLOBAL VARIABLES variables
#include<stdio.h> for fast access*/
#include<conio.h> void display(void);
int a=10; /* external or global variable*/ clrscr();
void main() for(i=0;i<5;i++)
{ display();
void call1(void); printf("\n static variables values perists at each call");
void call2(void); getch();
clrscr(); }
call1(); void display()
call2(); {
printf("\n in main a=%d",a); static int a;
getch(); /* the default value of static int is zero */
} printf("\n a is now %d",a++);
void call1() }
{ EXPERIMENT 20A:DEMONSTRATING PASS BY VALUE
int a=20; /* auto are local variable */ #include<stdio.h>
printf("\n in call1() a=%d",a); #include<conio.h>
} void main()
void call2() {
{ int swap(int,int);
printf("\n in call2() a=%d",a); int a=10,b=20;
} clrscr();
EXPERIMENT 19B:STORAGE CLASSES printf("\n before swaping a=%d AND b=%d",a,b);
DEMONSTRATING REGISTER AND STATIC VARIABLES swap(a,b);
#include<stdio.h> printf("\n After swaping a=%d AND b=%d",a,b);
#include<conio.h> getch();
void main() }

18
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
int swap(int a,int b) EXPERIMENT 21 I: PROGRAM TO FIND FACTORIAL OF
{ A NUMBER
int temp; USING ITERATIVE LOOPS
temp=a; #include<stdio.h>
a=b; #include<conio.h>
b=temp; void main()
printf("\n here in function swap a=%d AND b=%d",a,b); {
} int i,n;
EXPERIMENT 20B:DEMONSTRATING PASS BY long fact;
REFERENCE clrscr();
#include<stdio.h> printf("\n Enter the number to find factorial");
#include<conio.h> scanf("%d",&n);
void main() fact=1;
{ for(i=1;i<=n;i++)
int swap(int*,int*); fact=fact*i;
int a=10,b=20; printf("\n factorial of %d is %ld",n,fact);
clrscr(); getch();
printf("\n before swaping a=%d AND b=%d",a,b); }
swap(&a,&b); EXPERIMENT 21 II: PROGRAM TO FIND FACTORIAL OF
printf("\n After swaping a=%d AND b=%d",a,b); A NUMBER
getch(); USING NON RECURSIVE FUNCTION
} #include<stdio.h>
int swap(int *a,int *b) #include<conio.h>
{ void main()
int temp; {
temp=*a; int i,n;
*a=*b; long fact(int);
*b=temp; long l;
printf("\n here in function swap a=%d AND b=%d",*a,*b); clrscr();
} printf("\n Enter the number to find factorial");
scanf("%d",&n);

19
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
l=fact(n); return 1;
printf("\n factorial of %d is %ld",n,l); else
getch(); return n*fact(n-1);
} }
long fact(int n) EXPERMENT 22 I: PROGRAM TO PRINT
{ FIBNOCCISERIES
int i,f=1; USING ITERATIVE LOOPS
for(i=1;i<=n;i++) #include<stdio.h>
f=f*i; #include<conio.h>
return f; void main()
} {
EXPERIMENT 21 III: PROGRAM TO FIND FACTORIAL int a=1,b=1,c,n,i;
OF A NUMBER clrscr();
USING RECURSION printf("\nEnter the value of n");
#include<stdio.h> scanf("%d",&n);
#include<conio.h> printf("%d\n",a);
void main() printf("%d\n",b);
{ c=a+b;
int i,n; i=0;
long fact(int); while(i<=n)
long l; {
clrscr(); printf("%d\n",c);
printf("\n Enter the number to find factorial"); a=b;
scanf("%d",&n); b=c;
l=fact(n); c=a+b;
printf("\n factorial of %d is %ld",n,l); i++;
getch(); }
} getch();
long fact(int n) }
{ EXPERIMENT 22 II: PROGRAM TO PRINT
if(n==0) FIBNOCCISERIES

20
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
USING NON RECURSIVE FUNCTION }
#include<stdio.h>
#include<conio.h> EXPERIMENT 22 III:PROGRAM TO PRINT FIBNOCCI
void main() SERIES USING RECURSION
{ #include<stdio.h>
void fib(int,int,int); #include<conio.h>
int a,b,n; void main()
clrscr(); {
printf("\n Enter the values of and b"); int fib(int);
scanf("%d%d",&a,&b); int i,n;
printf("\nEnter the value of n"); clrscr();
scanf("%d",&n); printf("\n Enter the number of terms");
printf("\n%d",a); scanf("%d",&n);
printf("\n%d",b); printf("\nthe fibnocci series is");
fib(a,b,n); for(i=1;i<=n;++i)
getch(); printf("\n %d",fib(i));
} getch();
}
void fib(int a,int b,int n)
{ int fib(int m)
int c,i; {
c=a+b; if(m<0)
i=3; exit(1);
while(i<=n) else if(m<=2)
{ return 1;
printf("%d\n",c); else
a=b; return (fib(m-1)+fib(m-2));
b=c; }
c=a+b;
i++; EXPERIMENT 23A I:PROGRAM TO FIND GCD OF TWO
} NUMBERS

21
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
USING NON RECURSIVE FUNCTION #include<stdio.h>
#include<stdio.h> #include<conio.h>
#include<conio.h> void main()
void main() {
{ int gcd(int,int);
int gcd(int,int); int x,y;
int x,y; clrscr();
clrscr(); printf("\n Enter two numbers");
printf("\n Enter two numbers"); scanf("%d%d",&x,&y);
scanf("%d%d",&x,&y); if(x<y)
if(x<y) printf("\nGCD of %d and %d is %d",x,y,gcd(y,x));
printf("\nGCD of %d and %d is %d",x,y,gcd(y,x)); else
else printf("\n Gcd of %d and %d is %d",x,y,gcd(x,y));
printf("\n Gcd of %d and %d is %d",x,y,gcd(x,y)); getch();
getch(); }
} int gcd(int a,int b)
int gcd(int a,int b) {
{ int rem;
int rem; rem=a%b;
rem=a%b; if(rem==0)
while(rem!=0) return b;
{ else
a=b; return gcd(b,rem);
b=rem; }
rem=a%b; EXPERIMENT 23B I: PROGRAM TO FIND BASE POWER
} EXPONENT
return b; (X POWER Y) USING NON RECURSIVE FUNCTION
} #include<stdio.h>
EXPERIMENT 23A II:PROGRAM TO FIND GCD OF TWO int power(int base,int exp)
NUMBERS {
USING RECURSION int p = 1;

22
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
while(exp>0) printf("\nEnter base & exponent");
{ scanf("%d%d",&b,&e);
p = p*base; l=power(b,e);
exp--; printf("%d^%d = %d",b,e,l);
} getch();
return(p); }
}
void main() EXPERIMENT 24: Write a C program to find both the largest
{ and smallest number in a list of integers
int b,e,l; void main( )
clrscr(); {
printf("\nEnter base & exponent"); float largest(float a[ ], int n);
scanf("%d%d",&b,&e); float smallest(float a[],int n);
l=power(b,e); float value[40];
printf("%d^%d = %d",b,e,l); int i,n;
getch(); printf("\n enter how many elements u
} want");
EXPERIMENT 23B II:PROGRAM TO FIND X POWER Y scanf("%d",&n);
USING RECURSION printf("\n enter the elements");
#include<stdio.h> for(i=0;i<n;i++)
int power(int base,int exp) scanf("%f",&value[i]);
{ printf("largest element=%f\n", largest(value,n));
if(exp==0) printf("smallest
return 1; element=%f\n",smallest(value,n));
else }
return base*power(base,exp-1); float largest(float a[], int n)
} {
void main() int i;
{ float max;
int b,e,l; max = a[0];
clrscr(); for(i = 1; i < n; i++)

23
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
if(max < a[i]) scanf("%d",&arr[i]);
max = a[i]; }
return(max); printf("\nArray before sorting:\n");
} for (i = 0; i < n; i++)
float smallest(float a[], int n) printf("[%i], ",arr[i]);
{ printf ("\n");
int i; bubblesort(arr, n);
float min; printf("\nArray after sorting:\n");
min = a[0]; for (i = 0; i < n; i++)
for(i = 1; i < n; i++) printf("[%i], ", arr[i]);
if(min > a[i]) getch();
min = a[i]; }
return(min); void bubblesort(int arr[], int n)
} {
EXPERIMENT 25:PROGRAM TO SORT LIST OF int i, j, temp;
INTEGERS for (i = 0; i < n - 1; i++)
USING BUBBLE SORT {
#include <stdlib.h> for (j = i; j < n; j++) /* for(j=i+1;j<n;j++) */
#include <stdio.h> {
#define MAXSIZE 500 if (arr[i] > arr[j])
void bubblesort(int arr[], int maxsize); {
int arr[100],n; temp = arr[i];
void main() arr[i] = arr[j];
{ arr[j] = temp;
int i; }
printf("\nHow many arr you want to sort: "); }
scanf("%d",&n); }
printf("\nEnter the values one by one: "); }
for (i = 0; i < n; i++) EXPERIMENT 26:PROGRAM TO SORT LIST OF
{ INTEGERS USING
printf ("\nEnter element %i :",i); SELECTION SORT

24
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
#include <stdlib.h> min = i;
#include <stdio.h> for (j = i+1; j < n; j++)
#define MAXSIZE 500 {
void selection(int elements[], int maxsize); if (elements[j] < elements[min])
void main() min = j;
{ }
int i,n,elements[100]; temp = elements[i];
printf("\nHow many elements you want to sort: "); elements[i] = elements[min];
scanf("%d",&n); elements[min] = temp;
printf("\nEnter the values one by one: "); }
for (i = 0; i < n; i++) }
{ EXPERIMENT 27: program To sort a given list of integers in
printf("\nEnter element %i :",i); ascending order
scanf("%d",&elements[i]); USING Insertion sort
}
printf("\nArray before sorting:\n"); #include<stdio.h>
for (i = 0; i < n; i++) #include<conio.h>
printf("[%i], ",elements[i]);
printf ("\n"); void inst_sort(int []);
selection(elements, n);
printf("\nArray after sorting:\n"); void main()
for (i = 0; i < n; i++) {
printf("[%i], ", elements[i]); int num[5],count;
getch(); clrscr();
} printf("\nEnter the Five Elements to sort:\n");
void selection(int elements[], int n)
{ for (count=0;count<5;count++)
int i, j, k; scanf("%d",&num[count]);
int min, temp; inst_sort(num);
for (i = 0; i < n-1; i++)
{ printf("\n\nElements after sorting: \n");

25
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
for(count=0;count<5;count++) printf("\nEnter the values one by one: ");
printf("%d\n",num[count]); for (i = 0; i < maxsize; i++)
getch(); {
} printf ("\nEnter element %i :",i);
scanf("%d",&elements[i]);
// Function for Insertion Sorting getch();
void inst_sort(int num[]) }
{ printf("\nArray before sorting:\n");
int i,j,k; for (i = 0; i < maxsize; i++)
for(j=1;j<5;j++) printf("[%i], ",elements[i]);
{ printf ("\n");
k=num[j]; quickSort(elements, maxsize);
for(i=j-1;i>=0 && k<num[i];i--) printf("\nArray after sorting:\n");
num[i+1]=num[i]; for (i = 0; i < maxsize; i++)
num[i+1]=k; printf("[%i], ", elements[i]);
} }
} void quickSort(int elements[], int maxsize)
EXPERIMENT 28:PROGRAM TO SORT LIST OF {
INTEGERS sort(elements, 0, maxsize - 1);
USING QUICK SORT }
#include <stdlib.h> void sort(int elements[], int left, int right)
#include <stdio.h> {
#define MAXSIZE 500 int pivot, l, r;
void quickSort(int elements[], int maxsize); l = left;
void sort(int elements[], int left, int right); r = right;
int elements[MAXSIZE]; pivot = elements[left];
void main() while (left < right)
{ {
int i, maxsize; while ((elements[right] >= pivot) && (left < right))
printf("\nHow many elements you want to sort: "); right--;
scanf("%d",&maxsize); if (left != right)

26
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
{ clrscr();
elements[left] = elements[right]; printf("\n Enter two sorted arrays\n");
left++; printf("\n Details of first array");
} printf("\n Enter the number of elemnts in 1st array");
while ((elements[left] <= pivot) && (left < right)) scanf("%d",&n1);
left++; printf("\nEnter elements");
if (left != right) for(i=0;i<n1;i++)
{ scanf("%d",&a[i]);
elements[right] = elements[left]; printf("\n Details of second array");
right--; printf("\n Enter the number of elemnts in 1st array");
} scanf("%d",&n2);
} printf("\nEnter elements");
elements[left] = pivot; for(i=0;i<n2;i++)
pivot = left; scanf("%d",&b[i]);
left = l; mergesort(a,b,c,n1,n2,&n);
right = r; printf("\n Resultant array after merge sort\n");
if (left < pivot) for(i=0;i<n;i++)
sort(elements, left, pivot - 1); printf("%d\t",c[i]);
if (right > pivot) getch();
sort(elements, pivot + 1, right); }
} void mergesort(int *a,int *b,int *c,int n1,int n2,int *n)
EXPERIMENT 29:PROGRAM TO SORT LIST OF {
INTEGERS int i=0,j=0,k=0;
USING MERGE SORT while(i<n1 && j<n2)
#include<stdio.h> {
#include<conio.h> if(a[i]<b[j])
void main() {
{ c[k]=a[i];
void mergesort(int *a,int *b,int *c,int n1,int n2,int *n); i++;
int n1=0,n2=0,n=0,i=0; }
int a[30],b[30],c[60]; else

27
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
{ scanf("%d",&n);
c[k]=a[i]; printf("\nEnter the elements to sort");
j++; for(i=0;i<n;i++)
} scanf("%d",&a[i]);
k++; printf("\nEnter an element to search");
} scanf("%d",&key);
while(i<n1) for(i=0;i<n;i++)
{ if(key==a[i])
c[k]=a[i]; printf("\n%d is found at %d location",key,(i+1));
i++; getch();
k++; }
}
while(j<n2) EXPERIMENT 31:SEARCHING AN ELEMENT IN A LIST
{ OF
c[k]=b[j]; INTEGERS USING BINARY SEARCH
j++; int binsearch(int a[100],int n,int key);
k++; void bubblesort(int a[100],int n);
} void main()
*n=k; {
} int i,pos,n,key,a[100];
clrscr();
EXPERIMENT 30: SEARCHING AN ELEMENT IN A LIST printf("\n how many elements you want");
OF scanf("%d",&n);
INTEGERS USING LINEAR SEARCH printf("\nEnter elements");
#include<stdio.h> for(i=0;i<n;i++)
#include<conio.h> scanf("%d",&a[i]);
void main() printf("\nEnter the elemnts to be searched");
{ scanf("%d",&key);
int i,a[100],n,key; bubblesort(a,n);
clrscr(); printf("\nElemnts after sorting");
printf("\n Enter the size of the array"); for(i=0;i<n;i++)

28
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
printf("%d\n",a[i]); if (arr[i] > arr[j])
pos=-1; {
pos=binsearch(a,n,key); temp = arr[i];
if(pos!=-1) arr[i] = arr[j];
printf("\n the key %d is found at %d",key,pos+1); arr[j] = temp;
else }
printf("\n the key %d is not found",key); }
getch(); }
} }
int binsearch(int a[],int n,int key)
{
int i,first=0,middle,last=n-1; EXPERIMENT 32:
while(last>=first) .#include<stdio.h>
{ #include<conio.h>
middle=(last+first)/2; void main()
if(key>a[middle]) {
first=middle+1; int i,ncon,nvow,nblank,nwords,ndigits,nsp;
else if(key<a[middle]) char str[100];
last=middle-1; clrscr();
else printf("\nEnter any string");
return middle; gets(str);
} i=ncon=nvow=nblank=ndigits=nsp=0;
return -1; nwords=1;
} while(str[i]!='\0')
void bubblesort(int arr[], int n) {
{ if((str[i]>64&&str[i]<91)||(str[i]>96&&str[i]<123))
int i, j, temp; {
for (i = 0; i < n - 1; i++) if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u'||
{ str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]=='U')
for (j = i; j < n; j++) /* for(j=i+1;j<n;j++) */ nvow++;
{ else

29
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
ncon++; gets(str);
} for(i=0;str[i]!='\0';i++)
else if(str[i]==32) {
{ if(str[i]<91)
nblank++; printf("%c",str[i]+32);
nwords++; if(str[i]>96)
} printf("%c",str[i]-32);
else if(str[i]>46&&str[i]<57) }
ndigits++; getch();
else }
nsp++; EXPERIMENT 34:
i++; #include<stdio.h>
} #include<conio.h>
printf("\n number of characters = length of the string=%d",i); void main()
printf("\n number of vowels=%d",nvow); {
printf("\n number of consonats=%d",ncon); int i,j,k;
printf("\n no of digits=%d",ndigits); char firstname[15];
printf("\n number of special characters=%d",nsp); char secondname[15];
printf("\n number of blank spaces=%d",nblank); char lastname[15];
printf("\n no of words=%d",nwords); char name[40];
getch(); clrscr();
} printf("\n enter first name");
EXPERIMENT 33: gets(firstname);
#include<stdio.h> printf("\n enter second name");
#include<conio.h> gets(secondname);
void main() printf("\n enter last name");
{ gets(lastname);
char str[100]; for(i=0;firstname[i]!='\0';i++) /* copy first name into name */
int i; name[i]=firstname[i];
clrscr(); name[i]=' '; /* end first name with a space */
printf("\nEnter string");

30
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
for(j=0;secondname[j]!='\0';j++) /*copy second name into }
name */ s2[j]='\0';
name[i+j+1]=secondname[j]; printf("\n extracted substring from %s is %s:",s1,s2);
name[i+j+1]=' '; /* end second name with a space */ getch();
for(k=0;lastname[k]!='\0';k++) }
name[i+j+k+2]=lastname[k]; EXPERIMENT 36:
name[i+j+k+2]='\0'; /* end string name with a null character /*accessing variables using pointers*/
*/ #include<stdio.h>
printf("\n%s",name); /* we can also use void main( )
printf("\n%s",&name[0]); */ {
getch(); int x,y;
} int *ptr;
EXPERIMENT 35: clrscr();
#include<stdio.h> x=10 ;
#include<conio.h> ptr=&x ;
void main() y=*ptr ;
{ printf("\n value of x is %d\n\n",x);
char s1[15]; printf("\n%d is stored at address %u\n",x,&x);
char s2[15]; printf("\n%d is stored at address %u\n",*&x,&x);
int pos1,pos2,i,j=0; printf("%d is stored at address %u\n",*ptr,ptr);
clrscr(); printf("%d is stored at address %u\n",y,&*ptr);
printf("\n Enter a string"); printf("%u is stored at address %u\n",ptr,&ptr);
gets(s1); printf("%d is stored at address %u\n",y,&y);
printf("\n Enter position 1"); *ptr=25;
scanf("%d",&pos1); printf("\n now x=%d\n",x);
printf("\n Enter pos2"); getch();
scanf("%d",&pos2); }
for(i=pos1;i<=pos2;i++) EXPERIMENT 37:
{ #include<stdio.h>
s2[j]=s1[i];; #include<conio.h>
j++; void main()

31
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
{ {
int n, factorial; if(*str=='a'||*str=='e'||*str=='i'||*str=='o'||*str=='u'||
clrscr(); *str=='A'||*str=='E'||*str=='I'||*str=='O'||*str=='U')
printf("\nEnter a number"); nvow++;
scanf("%d", &n); else
factcompute(n,&factorial); ncon++;
printf("\nThe factorial of %d is %d",n,factorial); }
getch(); else if(*str==32)
} {
factcompute(int a,int *b) nblank++;
{ nwords++;
int m; }
*b = 1; else if(*str>46&&*str<57)
for(m = 1; m <= a; m++) ndigits++;
*b = *b * m; else
} nsp++;
EXPERIMENT 38: str++;
#include<stdio.h> i++;
#include<conio.h> }
void main() printf("\n number of characters = length of the string=%d",i);
{ printf("\n number of vowels=%d",nvow);
int i,ncon,nvow,nblank,nwords,ndigits,nsp; printf("\n number of consonats=%d",ncon);
char *str; printf("\n no of digits=%d",ndigits);
clrscr(); printf("\n number of special characters=%d",nsp);
printf("\nEnter any string"); printf("\n number of blank spaces=%d",nblank);
gets(str); printf("\n no of words=%d",nwords);
i=ncon=nvow=nblank=ndigits=nsp=0; getch();
nwords=1; }
while(*str!='\0') EXPERIMENT 39:
{ #include <stdlib.h>
if((*str>64&&*str<91)||(*str>96&&*str<123)) #include <stdio.h>

32
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
#define MAXSIZE 500 printf("\nArray after sorting:\n");
void main() for (i = 0; i < n; i++)
{ printf("[%i], ", arr[i]);
int i,j,temp,n,*arr; printf("\n largest element in the array is %d",arr[i-1]);
printf("\nHow many arr you want to sort: "); printf("\n smallest element in the array is %d",arr[0]);
scanf("%d",&n); getch();
printf("\nEnter the values one by one: "); }
for (i = 0; i < n; i++) EXPERIMENT 40:
{ /*program to find the length of a char string */
printf ("\nEnter element %i :",i); #include<stdio.h>
scanf("%d",&arr[i]); #include<conio.h>
} #include<string.h>
printf("\nArray before sorting:\n"); void main()
for (i = 0; i < n; i++) {
printf("[%i], ",arr[i]); char str[20],*p;
printf ("\n"); int i=0;
printf("\nArray elements in reverse order"); printf("enter a string \n");
for(i=n;i>=0;i--) scanf ("%s",str);
printf("%d\t",arr[i]); p=str;
for (i = 0; i < n - 1; i++) while(*p!='\0')
{ {
for (j = i; j < n; j++) /* for(j=i+1;j<n;j++) */ i++;
{ p++;
if (arr[i] > arr[j]) }
{ printf("\nthe length of the given string is %d",i);
temp = arr[i]; getch();
arr[i] = arr[j]; }
arr[j] = temp; EXPERIMENT 41:
} #define COUNT 5
} void main()
} {

33
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
char *names[5], temp[20]; printf("\nEnter the string");
int m, n; gets(s1);
clrscr(); strcopy(s2,s1);
for (m = 0; m < COUNT; m++) puts("\n after copying");
{ printf("\nthe string s1 is");
printf("\nEnter name[%d] : ",m); puts(s1);
names[m] = (char *) malloc (20); printf("\nthe string s2 is");
scanf("%s",names[m]); puts(s2);
} getch();
for (m = 1; m <= COUNT; m++) }
for (n = 1; n <= COUNT - m; n++) int strcopy(char *s2,char *s1)
if (strcmp(names[n - 1], names[n]) > 0) {
{ while(*s1!=0)
strcpy(temp, names[n - 1]); {
strcpy(names[n - 1], names[n]); *s2=*s1;
strcpy(names[n], temp); s1++;
temp[0] = '\0'; s2++;
} }
printf("\nSorted list is "); *s2='\0';
for (m = 0; m < COUNT; m++) }
printf("\n%s", names[m]); EXPERIMENT 43:
getch(); #include<conio.h>
} #include<stdio.h>
EXPERIMENT 42: void main()
#include<stdio.h> {
#include<conio.h> int compare_function();
void main() int result;
{ char inputA[20],inputB[20];
int strcopy(char *s2,char *s1); printf("\nEnter string A : ");
char s1[20],s2[20]; gets(inputA);
clrscr(); printf("\nEnter string B : ");

34
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
gets(inputB); void main()
result = compare_function(inputA,inputB); {
if (result == 0) int ch,i,j,m,n,p,q,k,r1,c1,a[10][10],b[10][10],c[10][10];
printf("\nStrings are same"); clrscr();
else printf("************************************");
printf("\nStrings are different"); printf("\n\t\tMENU");
getch(); printf("\n**********************************");
} printf("\n[1]ADDITION OF TWO MATRICES");
int compare_function(char *a,char *b) printf("\n[2]MULTIPLICATION OF TWO MATRICES");
{ printf("\n[0]EXIT");
while (*a != '\0') printf("\n**********************************");
{ printf("\n\tEnter your choice:\n");
if (*a == *b) scanf("%d",&ch);
{
a++; if(ch<=2 & ch>0)
b++; {
} printf("Valid Choice\n");
else }
return 1;
} switch(ch)
return 0; {
} case 1:
EXPERIMENT 44: printf("Input rows and columns of A & B Matrix:");
/* Write a C program that uses functions to perform the scanf("%d%d",&r1,&c1);
following: printf("Enter elements of matrix A:\n");
i) Addition of Two Matrices for(i=0;i<r1;i++)
ii) Multiplication of Two Matrices {
*/ for(j=0;j<c1;j++)
scanf("%d",&a[i][j]);
#include<stdio.h> }
printf("Enter elements of matrix B:\n");

35
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
for(i=0;i<r1;i++) for(j=0;j<q;++j)
{ {
for(j=0;j<c1;j++) c[i][j]=0;
scanf("%d",&b[i][j]); for(k=0;k<n;++k)
} c[i][j]=c[i][j]+a[i][k]*b[k][j];
printf("\n =====Matrix Addition=====\n"); }
for(i=0;i<r1;i++)
{ printf("Resultant of two matrices:\n");
for(j=0;j<c1;j++) write_matrix(c,m,q);
printf("%5d",a[i][j]+b[i][j]); }
printf("\n"); /*end if*/
} else
break; {
printf("Matrices cannot be multiplied.");
case 2: }
printf("Input rows and columns of A matrix:"); /*end else*/
scanf("%d%d",&m,&n); break;
printf("Input rows and columns of B matrix:");
scanf("%d%d",&p,&q); case 0:
if(n==p) printf("\n Choice Terminated");
{ exit();
printf("matrices can be multiplied\n"); break;
printf("resultant matrix is %d*%d\n",m,q);
printf("Input A matrix\n"); default:
read_matrix(a,m,n); printf("\n Invalid Choice");
printf("Input B matrix\n"); }
/*Function call to read the matrix*/ getch();
read_matrix(b,p,q); }
/*Function for Multiplication of two matrices*/
printf("\n =====Matrix Multiplication=====\n"); /*Function read matrix*/
for(i=0;i<m;++i) int read_matrix(int a[10][10],int m,int n)

36
Record Manual 1-44 Programs for ECE-A & ECE-B

Visit us at : http://mritsece.blogspot.com
{
int i,j;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
return 0;
}

/*Function to write the matrix*/


int write_matrix(int a[10][10],int m,int n)
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%5d",a[i][j]);
printf("\n");
}
return 0;
}

37

You might also like