You are on page 1of 68

SUBJECT CODE: CSE-101-E

SYLLABUS FOR COMPUTER PROGRAMMING LAB

1. Program to find Largest of three Numbers.

2. Program to find largest out of ten numbers.

3. Program to find largest and second largest out of ten numbers.

4. Program to add two matrices.

5. Program to concatenate two Strings.

6. Program to check whether a string is palindrome or not.

7. Program to find factorial of a number entered through Keyboard.

8. Program to swap two numbers.

9. Program to reverse a number entered through keyboard.

10. Program to sum digits of a number entered through keyboard.

11. Program to reverse a string.

12. Program to check whether a number is prime or not.

13. Program to implement linear search.

14. Program to Draw Pyramid of stars.

15. Program to multiply two metrices.


RATIONAL BEHIND COMPUTER PROGRAMMING LAB

This course will show you how to use the C language to create useful programs.
Interactive exercises ranging from simple to challenging will illustrate all the
important features of the language.

The course is composed of sections. The first section will introduce the student
to the C programming language, as well as some general programming issues.
At the start of this section, the student can verify that he or she meets the
course prerequisites.

The second section presents the basic details of the C language as they differ
from those of C++. Following this section is a focus on some advanced language
issues involving functions and memory management. Another section presents
string manipulation and file I/O along with an overview of C's standard
libraries. Finally, the course concludes with a lesson on building projects from
several files, and a comprehensive look at creating useful data structures in C.

C was created by Dennis M. Ritchie, in 1971 as the successor to the language


`B'. The first dialect of C is now called `common C' or `classic C' and differs
slightly from the new ANSI (American National Standards Institute) C standard
which was adopted in 1983. C is a very fast and efficient yet flexible language
often used for programs where speed and developer control are vital. In 1973,
the UNIX OS was written almost entirely in C and the language remains closely
linked to this OS. The flexibility of C comes with a price since it does not
enforce good style and type checking the way that other high level languages like
Pascal, BASIC of Java. This means that C is more error prone and more difficult
to `debug'. Despite these drawbacks, C was the most widely used programming
language during the past three decades and is only now losing favour to object
oriented languages such as C++ and Java
SOFTWARE AND HARDWARE REQUIREMENTS

SOFTWARE : C LANGUAGE

OPERATING SYSTEM : ANY

HARDWARE REQUIREMENT: 50MB RAM, 1GB

PROCESSOR: 386 AND ABOVE


FLOWCHART TO FIND LARGEST OF THREE NUMBERS

START

read a , b , c

No Yes
is a>b and a>c is b>a and b>c

Yes
No

print
Largest of three numbers: a print
Largest of three numbers: b

print
Largest of three numbers: c

STOP
ALGORITHM TO FIND LARGEST OF THREE NUMBERS
1. float a,b,c;
2. print ‘Enter any three numbers:’;
3. read a,b,c;
4. if((a>b)&&(a>c))
5. print ‘Largest of three numbers:’, a;
6. else
7. if((b>a)&&(b>c))
8. print ‘Largest of three numbers:’, b;
9. else
10.print ‘Largest of three numbers:’, c;
PROGRAM TO FIND LARGEST OF THREE NUMBERS

#include<stdio.h>
#include<conio.h>
void main( )
{
float a,b,c;
printf(“Enter any three numbers:”);
scanf(“%f%f%f”,&a,&b,&c);
if((a>b)&&(a>c))
{
printf(“Largest of three numbers: %f”,a);
}
else
if((b>a)&&(b>c))
{
printf(“Largest of three numbers: %f”,b);
}
else
{
printf(“Largest of three numbers: %f”,c);
}
getch( );
}
OUTPUT :

Enter any three numbers:


501
450
123
Largest of three numbers:501

Enter any three numbers:


97.52
81.23
97.65
Largest of three numbers:97.65
FLOWCHART TO FIND LARGEST NUMBER OUT OF TEN
NUMBERS

START

Yes
i=0 i<10

read a[i]

No
i++
i=0

i<10 Yes
is a[i]>a[j] t=1

j=i+1
No

t=0 is t==1
j<10

j++ No Yes
i++

Print Largest no.:a[i]

STOP
ALGORITHM TO FIND LARGEST NUMBER OUT OF TEN
NUMBERS

1. integer a[10],i , s=0,j,t;


2. print ‘Enter ten numbers:’
3. Value of ‘i’ will be incremented by using for loop;
4. read a[i];
5. Value of ‘i’and ‘j’ will be incremented by using for loop;
6. if(a[i]>a[j])
7. t 1;
8. else
9. t 0;
10. break;
11.if(t==1)
12.print ‘Largest no.:’,a[i];
13.break;
PROGRAM TO FIND LARGEST NUMBER OUT OF TEN NUMBERS

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,s=0,j,t;
clrscr();
printf(“Enter ten numbers:”);
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<10;i++)
{
for(j=i+1;j<10;j++)
{
if(a[i]>a[j])
{
t=1;
}
else
{
t=0;
break;
}
}
if(t==1)
{
printf("\nLargest no.:%d",a[i]);
break;
}
}
getch();
}
OUTPUT:
Enter ten numbers: 23
4
59
10
91
35
66
33
9
97

Largest no.: 97
FLOWCHART TO READ A STRING AND WRITE IT IN REVERSE
ORDER
START

Read array a

i=0
i=0

No
a[i]!= ‘\0’ j=g-1 No
i<g

Yes
Yes
g++
b[j]=a[i]

i++
j—
i++

print
Reverse order of string: b

stop
ALGORITHM TO READ A STRING AND WRITE IT IN REVERSE
ORDER
1. character a[20],i , b[20],g=0,j;
2. print ‘Enter any string:’
3. read array a;
4. Length of the string in the array is calculated by using for loop in ‘g’;
5. string in array ‘a’ is reversed in array ‘b’ by incrementing value of ‘i’ and
decrementing value of ‘j’ by for loop;
6. print ‘Reverse order of string:’,b;
PROGRAM TO READ A STRING AND WRITE IT IN REVERSE
ORDER

#include<stdio.h>
#include<conio.h>
void main()
{
char a[20],i , b[20],g=0,j;
clrscr();
printf("Enter any string: ");
scanf("%s",a);
for(i=0;a[i]!='\0';i++)
{
g++;
}
j=g-1;
for(i=0;i<g;i++)
{
b[j]=a[i];
j--;
}
printf("Reverse order of string: %s",b);
getch();
}
OUTPUT :
Enter any string: Twinkle

Reverse order of string: elkniwT

Enter any string: Arora

Reverse order of string: arorA


FLOWCHART TOCHECK THAT THE INPUT STRING IS A
PALINDROME OR NOT

START

Read array a

i=0
i=0

No
a[i]!= ‘\0’ j=g-1 No
i<g

Yes
Yes
g++
b[j]=a[i]

i++ i=0
j—
i++

Yes Yes No
a[i]==b[i] i<g

No
m=1 i++

m=0

1.
1.

Yes
m=0

No

Print m=1
String is Palindrome

Print
String is not Palindrome

STOP
ALGORITHM TOCHECK THAT THE INPUT STRING IS A
PALINDROME OR NOT

1. character a[20],i , b[20],g=0,j,m;


2. print ‘Enter any string:’
3. read array a;
4. Length of the string in the array is calculated by using for loop in ‘g’;
5. string in array ‘a’ is reversed in array ‘b’ by incrementing value of ‘i’ and
decrementing value of ‘j’ by for loop;
6. print ‘Reverse order of string:’,b;
7. condition of equality of array a and b is checked by for loop;
8. if condition is satisfied then the string is palindrome
9. if condition is not satisfied then the string is not palindrome
PROGRAM TOCHECK THAT THE INPUT STRING IS A
PALINDROME OR NOT
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
char a[20],i,b[20],g=0,j,m;
clrscr();
printf("Enter any string: ");
scanf("%s",a);
for(i=0;a[i]!='\0';i++)
{
g++;
}
j=g-1;
for(i=0;i<g;i++)
{
b[j]=a[i];
j--;
}
for(i=0;i<g;i++)
{
if(b[i]==a[i])
m=0;
else
{
m=1;
break;
}
}
if(m==0)
{
printf("String is a Palindrome");
}
else
if(m==1)
{
printf("String is not a Palindromes");
}
getch();
}
OUTPUT :

Enter any string: Madam


String is not a Palindrome

Enter any string: ARORA


String is a Palindrome
FLOWCHART TO CONCATINATE TWO STRINGS
START

Print Enter first string


Read a;
Print Enter second string
Read b

i=0

j=0

No
a[i]!= ‘\0’

b[j]!= ‘\0’
Yes

c[i]=a[i]

c[i+j]=b[j]

i++

j++

print
The Concatenated string is: c

stop
ALGORITHM TO CONCATINATE TWO STRINGS
1. character array a[25],b[25],c[25];
2. integer i,j;
3. print ‘Enter first string:”;
4. read a;
5. print ‘Enter second string:”;
6. read b;
7. string ‘a’ is copied to array ‘c’ by using for loop;
8. string ‘b’ is copied to array ‘c’next to the first string by using for loop;
9. print ‘The concatenated string is:’,c;
WRITE A PROGRAM TO CONCATINATE TWO STRINGS
#include<stdio.h>
#include<conio.h>
void main()
{
char a[25],b[25],c[25];
int i.j;
clrscr();
printf(“Enter first string:”);
scanf(“%s”,a);
printf(“Enter second string:”);
scanf(“%s”,b);
for(i=0;a[i]!=’\0’;i++)
c[i]=a[i];
for(j=0; b[j]!=’\0’; j++)
c[i+j]=b[j];
c[i+j]=’\0’;
printf(“The concatenated string is:\n%s,c”);
getch();
}
OUTPUT :

Enter first string: Net


Enter second string: World

The concatenated string is: NetWorld


FLOWCHART TO MULTIPLY TWO MATRICES

START

read m,n,p,q;

n=p i=0 i=0


j=0 j=0

No No
Print i<m i<p
‘Matrix cannot be multiplied’
Yes
Yes
No No
i=0 j<n j<q
j=0
s=0
Yes Yes

read a[i][j] read b[i][j]

i<m

j<q s++
j++
c[i][j]=c[i][j]+a[i][s]*b[s][j] I++

s=0 1.
1.

i=0
j=0

i<m

j<q

Print
‘Product of matrix A and matrix B is’
print c[i][j]

STOP
ALGORITHM TO MULTIPLY TWO MATRICES

1. integer array a[10][10],b[10][10],c[10][10];


2. integer i, j, m, n, p, q, s;
3. print ‘Input row and column of matrix-A’;
4. read m, n;
5. print ‘Input row and column of matrix-B’;
6. read p, q;
7. if ‘n’ not equals to ‘p’
8. print ‘Matrix cannot be multiplied’;
9. else
10.print ‘Input matrix-A’;
11.read the input by using two for loop, one for row and other for column of matrix
12.print ‘Input matrix-B’;
13.read the input by using two for loop, one for row and other for column of matrix
14.multiplication is done by using three for loops incrementing ‘i’, ‘j’, ‘s’ where
‘i’is for row and ‘j’ is for column of array
15.c[i][j]=c[i][j]+a[i][s]*b[s][j];
16.print ‘Product of matrix A and matrix B is:
17.print array ‘c’ in which multiplication of two arrays are stored using for loops

WRITE A PROGRAM TO MULTIPLY TWO MATRICES


#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
int a[10][10],b[10][10],c[10][10];
int i,j,m,n,p,q,s;
clrscr();
printf("Input row and column of matrix-A\n");
scanf("%d%d",&m,&n);
printf("Input row and column of matrix-B\n");
scanf("%d%d",&p,&q);
if(n!=p)
{
printf("Matrix cannot be multiplied\n");
getch();
exit(0);
}
printf("Input Matrix-A\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Input Matrix-B\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=0;
for(s=0;s<n;s++)

c[i][j]=c[i][j]+a[i][s]*b[s][j];
}
}
printf("\nProduct of matrix A and matrix B is:\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf("\t%d",c[i][j]);
}
printf("\n");
}
getch();
}
OUTPUT:
Input row and column of matrix-A
3
4
Input row and column of matrix-B
2
4
Matrix cannot be multiplied

Input row and column of matrix-A


2
2
Input row and column of matrix-B
24
Input Matrix-A
12
3
45
56
Input Matrix-B
7
4
23
14
71
46
26
3
9
11
5
34
Product of matrix A and matrix B is:

702 681 579 1707


840 690 1510 1946
FLOWCHART TO SOLVE QUADRATIC EQUATION

START

Read a,b,c

Quad(a,b,c);

d=(b2)-(4*a*c)

Yes Is No is Yes
d<0 d=0
No r=-b/2*a

Print “Value of r1=-b+sqrt(d),


Discriminant is negative” r2=2*a,
r=r1/r2,
r3=-b-sqrt(d),
r4=r3/r2 print Frst and
Second root of
Equation: r

print First root of equation: r


print Second root of equation: r4

stop
ALGORITHM TO SOLVE QUADRATIC EQUATION
1. integer a,b,c;
2. float d,r1,r2,r3,r4,r;
3. print ‘Enter values of a,b,c of a quadratic equation:’;
4. read a,b,c;
5. value of a,b,c is transferred to function ‘quad’and body of function is:
6. d b x b-4 x a x c;
7. if(d<0)
8. print ‘Value of Discriminant is negative’;
9. else
10.if(d=0)
11.print ‘Roots are real’
12.r=-b/2*a;
13.print ‘First and Second root of equation:’,r;
14.else
15.r1 -b+sqrt(d);
16.r2 2*a;
17.r r1/r2;
18.r3 -b-sqrt(d);
19.r4 r3/r2;
20.print ‘First root of equation: ’, r;
21.print ‘Second root of equation: ’, r4;
WRITE A PROGRAM TO SOLVE QUADRATIC EQUATION
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
void quad(int a, int b ,int c);
int a,b,c;
float r;
clrscr();
printf(“Enter values of a,b,c of a quadratic equation:\n” );
scanf(“%d%d%d”,&a,&b,&c);
quad(a,b,c);
getch();
}

void quad(int a, int b ,int c)


{
float d,r1,r2,r3,r4,r;
d=(b*b)-(4*a*c);
switch(d)
{
case <0:
printf(“Value of Discriminant is negative” );
break;
case 0:
printf(“ Roots are real” );
r=-b/2*a;
printf(“ First and Second root of equation:%d,r” );
break;
default:
r1=-b+sqrt(d);
r2=2*a;
r=r1/r2;
r3=-b-sqrt(d);
r4=r3/r2;
break;
printf(“First root of equation: %d”,r);
printf(“/n Second root of equation: %d”,r4);
}
}
OUTPUT:
Enter values of a,b,c of a quadratic equation: 2
2
4

Value of Discriminant is negative

Enter values of a,b,c of a quadratic equation: 1


5
2

First root of equation: -2.9384


Second root of equation: -7.0615

Enter values of a,b,c of a quadratic equation: 2


4
2
Roots are real
First and Second root of equation: -1
FLOWCHART TO FIND LARGEST AND SECOND LARGEST
NUMBER OUT OF GIVEN NUMBER

START

print
How many no. will you enter:

Read n
i=0

No
i<n l=a[1] i=0

Yes

read a[i] No
i<n

i++ Yes

a[i]>l

i++ l=a[i]

print
‘ Largest no. is:’,l

1.
1

sl=a[1] i=0

i<n

a[i]>sl

a[i]=l

i++ sl=a[i]

print
‘Second largest no. is:’sl

STOP
ALGORITHM TO FIND LARGEST AND SECOND LARGEST
NUMBER OUT OF GIVEN NUMBER

1. integer i,a[55],n,l=0,sl;
2. print"How many no. will you enter: ";
3. read n
4. values will be entered in array ‘a’ by using for loop
5. l=a[1]
6. by using for loop and incrementing value of ‘i’ a[i] is checked for largest no. with
‘l’(a[i]>l)
7. the largest value is stored in ‘l’ and printed
8. print "Largest element is:",l;
9. again the above process is continued but if a[i]equals to largest value ‘l’ then
value of ‘i’ is incremented and second largest value is stored in ‘sl’
10.print "Second Largest element is:",sl;
WRITE A PROGRAM TO FIND LARGEST AND SECOND
LARGEST NUMBER OUT OF GIVEN NUMBER

#include<stdio.h>
#include<conio.h>
void main()
{
int i,a[55],n,l=0,sl;
clrscr();
printf("How many no. will you enter: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
l=a[1];
for(i=0;i<n;i++)
{
if(a[i]>l)
{
l=a[i];
}
}
printf("Largest element is:%d",l);
sl=a[1];
for(i=0;i<n;i++)
{
if(a[i]>sl)
{
sl=a[i];
}
}
printf("Second Largest element is:%d",sl);
getch();
}
OUTPUT:
How many no. will you enter:
10
Enter numbers
20
41
15
70
90
35
20
55
28
16
Largest element is: 90
Second Largest element is: 70
ALGORITHM TO FIND WHETHER A NUMBER IS PRIME OR NOT

1. Declare two integer values I & n and initialize third integer value.

2. Initialize I as zero and give condition as I = n/2

3. If n%2 = 0 then f = 1.

4. Now if f = = 1 the number is not a prime number else it is prime


WRITE A PROGRAM TO CHECK THAT INPUT NUMBER IS
PRIME OR NOT

#include<stdio.h>
#include<conio.h>
void main( )
{
int num, i;
clrscr( ) ;
printf(“”\n enter a no.”) ;
scanf(“%d”, & num) ;
i=2 ;
While(I<=(num-1))
{
if(num % I= =0)
{
printf(“not a prime no.”);
break ;
}
I++ ;
}
if(i = = num)
printf(“prime number”);
getch();
}
OUTPUT :
Enter a number : 3
Prime number

Enter a number : 9
Not a Prime number
ALGORITHM TO FIND THE MALE AND FEMALE
AVERAGE HEIGHT

STEP 1 : Declare the variable i,mh,fh as integer value and mavg,favg,msum,fsum as float
value.

STEP 2: Input height of male.

STEP 3: Calculate sum and then average of height of females.

STEP 4: Input height of female.

STEP 5:. Calculate sum and then average of height of females.

STEP 6: Stop
WRITE A PROGRAM TO FIND AVERAGE OF MALE &
FEMALE HEIGHT IN THE CLASS

#include<stdio.h>
#include<conio.h>
void main()
{
int mh[5],fh[5],i;
float mavg,favg,msum=0,fsum=0;
clrscr();
printf(“enter the height of male\n”);
for(i=0;i<5;i++)
{
scanf(“%d”,&mh[i]);
msum=msum+mh[i];
}
mavg=msum/5;

printf(“enter the height of female\n”);


for(i=0;i<5;i++)
{
scanf(“%d”,&fh[i]);
fsum=fsum+fh[i];
}
favg=fsum/5;
printf(“the average of male height is %f \n”,mavg);
printf(“the average of female height is %f \n”,favg);
getch();
}
OUTPUT:

enter the height of male

20
22
25
24
23
enter the height of female

22
20
21
23
22

the average of male height is 22.8

the average of female height is 21.6


ALGORITHM TO FIND THE FACTORIAL OF A
PARTICULAR NUMBER

STEP 1 : Declare the int variable a,i,fact=1.

STEP 2: input the number in a.

STEP 3: After for loop fact =fact*i

STEP 4 : print the factorial number in fact.

STEP 5. Stop.

-
WRITE A PROGRAM TO FIND FACTORIAL OF A NUMBER

#include<stdio.h>
#include<conio.h>
void main()
{
int a,i.fact=1;
clrscr();
printf(“Enter the number \n”);
scanf(“%d%”,&a);
for(i=1;i<=a;i++)
{
fact=fact*i;
}
printf(“the factorial is %d”,fact);
getch();

}
OUTPUT:
Enter the number
6

the factorial is
720
ALGORITHM TO PRINT THE FIBONACCI SERIES

STEP 1 : Declare the int variable f,s,n,c,t.

STEP 2: declare f=1,s=1.

STEP 3: After for loop t=f+s.

STEP 4 :print the result in t.

STEP 5 : f=s, s=t.

STEP 6. Stop.

-
WRITE A PROGRAM TO PRINT FIBONACCI SERIES
#include<stdio.h>
#include<conio.h>
void main()
{
int f,s,n,c,t;
clrscr();
printf(“Enter the number of series \n”);
scanf(“%d”,&n);
f=1;
s=1;
printf(“%d\t”,f);
printf(“%d\t”,s);
for(c=1;c<=n-2;c++)
{
t=f+s;
printf(“%d\t”,t);
f=s;
s=t;
}
getch();
}
OUTPUT:
Enter the number of series
6

1 1 2 3 5 8
ALGORITHM TO FIND THE REVERSE OF A NUMBER

STEP 1 : Declare the int variable n,b,s=0

STEP 2: enter the number in n (which can be reverse).

STEP 3: using while loop(n!=0)

STEP 4 : b=n%10
s=(s*10)+b
n=n/10
STEP 5 : print the reverse number in s.

STEP 6. Stop.

-
WRITE A PROGRAM TO REVERSE OF NUMBER
#include<stdio.h>
#include<conio.h>
void main()
{
int n,b,s=0;
clrscr();
printf(“Enter the number \n”);
scanf(“%d”,&n);
while(n!=0)
{
b=n%10;
s=(s*10)+b;
n=n/10;
}
printf(“The reverse number is %d”,s);
getch();
}
OUTPUT:
Enter the number
123

The reverse number is


321
ALGORITEM TO SWAP TWO NUMBERS

STEP 1 : Declare the int variable a,b,temp.

STEP 2: enter the number in a &b.

STEP 3: temp=a
a=b
b=temp

STEP 4 : print the swapped value in a,b.

STEP 5. Stop.

-
WRITE A PROGRAM TO SWAP OF TWO NUMBER

#include<stdio.h>
#include<conio.h>
void main()
{
int a,,b,temp;
clrscr();
printf(“Enter the number of a&b \n”);
scanf(“%d\n%d\n”,&a,&b);
temp=a;
a=b;
b=temp;
printf(“the swapped values are \n”);
printf(“%d\n%d\n”,a,b);
getch();
}
OUTPUT:
Enter the number of a&b
4
8

the swapped values are


8
4
ALGORITHM TO PRINT PYRAMIND OF STARS

STEP 1 : Declare the int variable i.a.j.k

STEP 2: enter the number of line in a.

STEP 3: using for loop i is compare when it is not equal to and less than a.
j is initialize for blank space.
k is initialize to print the star.

STEP 4. Stop.

-
WRITE A PROGRAM TO PRINT PYRAMID STAR
#include<stdio.h>
#include<conio.h>
void main()
{
int i,a,j,k;
clrscr();
printf(“enter the number of line \n”);
scanf(“%d”,&a);
for(i=0;i<a;i++)
{
printf(“\n”);
for(j=0;j<10-i;j++)
{
printf(“ ”);
}
for(k=0;k<=2*i;k++)
{
printf(“*”);
}
}
getch();
}
OUTPUT:

enter the number of line


5

*
***
*****
*******
*********
ALGORITHM TO PRINT THE SUM OF TWO MATRICES
STEP 1 : Declare two dimensional array a,b,c and int variable i,j,k,r1,r2,c1,c2.

STEP 2: Input the order of matrix a& b.

STEP 3: using for loop i,j, enter the element of matrix a in a[i][j]
using for loop i,j, enter the element of matrix b in b[i][j].

STEP 4 : c[i][j]=a[i][j]+b[i][j]

STEP 5 : print the addition of two matrices in c[i][j].

STEP 6. Stop
WRITE A PROGRAM TO SUM OF TWO MATRICES

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10];
int i,j,k,r1,r2,c1,c2;
clrscr();
printf("input the order of matrix A:");
scanf("%d%d",&r1,&c1);
printf("input the order of matrix B:");
scanf("%d%d",&r2,&c2);
printf("enter the element of matrix A(row wise) \n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}}
printf("enter the element of matrix B(row wise) \n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&b[i][j]);
}}
printf("the element of matrix A is \n");
for(i=0;i<r1;i++)
{
printf("\n");
for(j=0;j<c1;j++)
{
printf("%d",a[i][j]);
printf("\t");
}}
printf("the element of matrix B is \n");
for(i=0;i<r2;i++)
{
printf("\n");
for(j=0;j<c2;j++)
{
printf("%d",b[i][j]);
printf("\t");
}}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
c[i][j]=a[i][j]+b[i][j];
}}
printf("the addition of matrix is :");
for(i=0;i<r1;i++)
{
printf("\n");
for(j=0;j<c2;j++)
{
printf("%d",c[i][j]);
printf("\t");
}}
getch();
}
OUTPUT:
input the order of matrix A:
2
2
input the order of matrix B:
2
2

enter the element of matrix A(row wise)


3
6
7
9
enter the element of matrix B(row wise)
4
6
2
8

the element of matrix A is

3 6
7 9

the element of matrix B is


4 6
2 8

the addition of matrix is :

7 12
9 17
New ideas/ experiments required for Computer programming lab
behind university syllabus
1. LIST OF FREQUENTLY ASKED QUESTIONS

• How do you decide which integer type to use?

• What should the 64-bit type on new, 64-bit machines be?

• What can I safely assume about the initial values of variables which
are not explicitly initialized? If global variables start out as ``zero,''
is that good enough for null pointers and floating-point zeroes?

• How can I read a single character from the keyboard without


waiting for a newline

• How can I copy a float into a string?

• Why doesn't C have an exponentiation operator?

• Why does everyone say not to use gets()?

• Why doesn't the code a[i] = i++; work?

• How does struct passing and returning work?

• Why can't you compare structs?

• How do I enter values using hexadecimal?

• What does extern mean in a function declaration?

• How do I ``get'' a null statement in my programs?

• Is there more than one null statement?

• Is a null statement a null pointer?


• I had the definition char a[6] in one source file, and in another I
declared extern char a[]. Why did it work?

• why are array and pointer declarations interchangeable as function


formal parameters?
• what is the difference between arrays and pointers?

• How does free() know how many bytes to free?

• How can I get the numeric (character set) value corresponding to a


character, or vice versa?

• What is the right type to use for boolean values in C? Why isn't it a
standard type? Should #defines or enums be used for the true and false
values?

• What is the ``ANSI C Standard?''

• What's the difference between ``char const *p'' and ``char * const
p''?

• What's wrong with this code:

• char c;
• while((c = getchar()) != EOF)...

• How can I print a ``%'' character in a printf format string?

• Which is larger, ``2'' or ``2.0''?

You might also like