Lab Manual Focp

85
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.

Transcript of Lab Manual Focp

Page 1: Lab Manual Focp

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.

Page 2: Lab Manual Focp

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

Page 3: Lab Manual Focp

SOFTWARE AND HARDWARE REQUIREMENTS

SOFTWARE : C LANGUAGE

OPERATING SYSTEM : ANY

HARDWARE REQUIREMENT: 50MB RAM, 1GB

PROCESSOR: 386 AND ABOVE

Page 4: Lab Manual Focp

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

Page 5: Lab Manual Focp

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. else7. if((b>a)&&(b>c))8. print ‘Largest of three numbers:’, b;9. else10.print ‘Largest of three numbers:’, c;

Page 6: Lab Manual Focp

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); }elseif((b>a)&&(b>c)){printf(“Largest of three numbers: %f”,b); }else{printf(“Largest of three numbers: %f”,c); }getch( );}

Page 7: Lab Manual Focp

OUTPUT :

Enter any three numbers:501450123Largest of three numbers:501

Enter any three numbers:97.5281.2397.65Largest of three numbers:97.65

Page 8: Lab Manual Focp

FLOWCHART TO FIND LARGEST NUMBER OUT OF TEN NUMBERS

START

Yes

i=0 i<10

read a[i]

Noi++

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

Page 9: Lab Manual Focp

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. else9. t 0;10. break;11.if(t==1)12.print ‘Largest no.:’,a[i];13.break;

Page 10: Lab Manual Focp

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();}

Page 11: Lab Manual Focp

OUTPUT:

Enter ten numbers: 234591091356633997

Largest no.: 97

Page 12: Lab Manual Focp

stop

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

Page 13: Lab Manual Focp

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;

Page 14: Lab Manual Focp

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();}

Page 15: Lab Manual Focp

OUTPUT :

Enter any string: Twinkle

Reverse order of string: elkniwT

Enter any string: Arora

Reverse order of string: arorA

Page 16: Lab Manual Focp

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.

Page 17: Lab Manual Focp

1.

Yes m=0

No

Print m=1 String is Palindrome

Print String is not Palindrome

STOP

Page 18: Lab Manual Focp

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 palindrome9. if condition is not satisfied then the string is not palindrome

Page 19: Lab Manual Focp

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");}elseif(m==1){printf("String is not a Palindromes");}getch();}

Page 20: Lab Manual Focp

OUTPUT :

Enter any string: MadamString is not a Palindrome

Enter any string: ARORAString is a Palindrome

Page 21: Lab Manual Focp

stop

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

Page 22: Lab Manual Focp

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;

Page 23: Lab Manual Focp

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();}

Page 24: Lab Manual Focp

OUTPUT :

Enter first string: NetEnter second string: World

The concatenated string is: NetWorld

Page 25: Lab Manual Focp

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.

Page 26: Lab Manual Focp

1. i=0 j=0 i<m j<q Print ‘Product of matrix A and matrix B is’ print c[i][j]

STOP

Page 27: Lab Manual Focp

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. else10.print ‘Input matrix-A’;11.read the input by using two for loop, one for row and other for column of matrix12.print ‘Input matrix-B’;13.read the input by using two for loop, one for row and other for column of matrix14.multiplication is done by using three for loops incrementing ‘i’, ‘j’, ‘s’ where

‘i’is for row and ‘j’ is for column of array15.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

Page 28: Lab Manual Focp

#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];}

Page 29: Lab Manual Focp

}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();}

Page 30: Lab Manual Focp

OUTPUT:Input row and column of matrix-A

34Input row and column of matrix-B24Matrix cannot be multiplied

Input row and column of matrix-A22Input row and column of matrix-B24Input Matrix-A1234556Input Matrix-B7423147146263911534Product of matrix A and matrix B is:

702 681 579 1707840 690 1510 1946

Page 31: Lab Manual Focp

stop

FLOWCHART TO SOLVE QUADRATIC EQUATION

START

Read a,b,c

Quad(a,b,c);

A

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

Page 32: Lab Manual Focp

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. else10.if(d=0)11.print ‘Roots are real’12.r=-b/2*a;13.print ‘First and Second root of equation:’,r;14.else15.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;

Page 33: Lab Manual Focp

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);}}

Page 34: Lab Manual Focp

OUTPUT:

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

Value of Discriminant is negative

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

First root of equation: -2.9384Second root of equation: -7.0615

Enter values of a,b,c of a quadratic equation: 242Roots are realFirst and Second root of equation: -1

Page 35: Lab Manual Focp

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.

Page 36: Lab Manual Focp

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

Page 37: Lab Manual Focp

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 n4. values will be entered in array ‘a’ by using for loop5. 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 printed8. 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;

Page 38: Lab Manual Focp

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();}

Page 39: Lab Manual Focp

OUTPUT:How many no. will you enter:10 Enter numbers20411570903520552816Largest element is: 90Second Largest element is: 70

Page 40: Lab Manual Focp

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

Page 41: Lab Manual Focp

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();}

Page 42: Lab Manual Focp

OUTPUT :

Enter a number : 3Prime number

Enter a number : 9Not a Prime number

Page 43: Lab Manual Focp

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

Page 44: Lab Manual Focp

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();}

Page 45: Lab Manual Focp

OUTPUT:

enter the height of male

2022252423enter the height of female

2220212322

the average of male height is 22.8

the average of female height is 21.6

Page 46: Lab Manual Focp

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.

-

Page 47: Lab Manual Focp

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();

}

Page 48: Lab Manual Focp

OUTPUT:

Enter the number6

the factorial is720

Page 49: Lab Manual Focp

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.

-

Page 50: Lab Manual Focp

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();}

Page 51: Lab Manual Focp

OUTPUT:

Enter the number of series6

1 1 2 3 5 8

Page 52: Lab Manual Focp

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.

-

Page 53: Lab Manual Focp

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();}

Page 54: Lab Manual Focp

OUTPUT:

Enter the number 123

The reverse number is321

Page 55: Lab Manual Focp

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.

-

Page 56: Lab Manual Focp

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();}

Page 57: Lab Manual Focp

OUTPUT:

Enter the number of a&b48

the swapped values are84

Page 58: Lab Manual Focp

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.

-

Page 59: Lab Manual Focp

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();}

Page 60: Lab Manual Focp

OUTPUT:

enter the number of line5

****

************

*********

Page 61: Lab Manual Focp

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

Page 62: Lab Manual Focp

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");}}

Page 63: Lab Manual Focp

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();}

Page 64: Lab Manual Focp

OUTPUT:

input the order of matrix A:22input the order of matrix B:22

enter the element of matrix A(row wise)3679enter the element of matrix B(row wise)4628

the element of matrix A is

3 67 9

the element of matrix B is4 62 8

the addition of matrix is :

7 129 17

Page 65: Lab Manual Focp

New ideas/ experiments required for Computer programming lab behind university syllabus

Page 66: Lab Manual Focp

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?

Page 67: Lab Manual Focp

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''?

Page 68: Lab Manual Focp