Pascal programs

Post on 12-Nov-2014

2,435 views 1 download

description

lots of prepared pascal programs

transcript

{*Program 1*} (*FY B C A*)

{program: To find multiplication of two matrices}

program matrix(multi);uses crt;var a,b,c:array [1..3,1..3] of integer; i,j,k:integer;begin \\{beginning of the program}

clrscr;writeln('first matrix');

for i:=1 to 3 do \\{beginning of first for loop} begin for j:=1 to 3 do begin

read(a[i,j]); end; end;writeln('second matrix'); for i:=1 to 3 do begin \\{end of first for loop} for j:=1 to 3 do \\{beginning of second for loop} begin read(b[i,j]); end; end; \\{end of second for loop} for i:=1 to 3 do \\{beginning of third for loop} begin for j:=1 to 3 do begin c[i,j]:=0; for k:=1 to 3 do begin c[i,j]:=c[i,j]+a[i,k]*b[k,j]; end; end; end; \\{end of third for loop}writeln('Sum of Matrices')for i:=1 to 3 dobeginfor j:=1 to 3 dobegin write(c[i,j]:3);end;writeln;end;end. \\{end of the program} Output:first matrix1 1 1

1 1 11 1 1second matrix2 2 22 2 22 2 2Multiplication of Matrices6 6 66 6 6 6 6 6

{*Program 2*} (*FY B C A*)

{program:To find larger and smaller no in a matrix}

program matrix(max,min);uses crt;var a:array [1..3,1..3] of integer; i,j,min,max:integer;begin \\{beginning of the program}

clrscr; max:=0; \\{assigning value of max to 0}

writeln('enter the elements for the matrix')for i:=1 to 3 do \\{beginning of for loop}beginfor j:=1 to 3 dobegin read(a[i,j]);end;end; \\{end of for loop} min:=a[i,j];for i:=1 to 3 do \\{beginning of for loop}beginfor j:=1 to 3 do \\{end of for loop}begin if(max<a[i,j]) then max:=a[i,j]; if(min>a[i,j]) then min:=a[i,j];end;end;writeln('max ',max); \\{displaying the max value}writeln('min ',min); \\{displaying the min value}readkey;end. \\{end of the program}

Output:

Ener the elements for the matrix1 2 36 5 47 8 9Max 9Min 1

{*Program 3*} (*FY B C A*)

{program: To arrange no’s in ascending order from the array}

program arrassending;uses crt;var a:array [1..10] of integer; i,j,temp:integer;begin \\{beginning of the program}

clrscr;writeln('insert the elements for the array');

for i:=1 to 10 do \\{taking the elements in an array} read(a[i]);for i:=1 to 9 do \\{beginning of for loop}beginfor j:=i+1 to 10 dobegin if(a[i]>a[j]) then begin temp:=a[i]; a[i]:=a[j]; a[j]:=temp;end;end;end; \\{end of for loop}writeln(‘Ascending Arrangement of array’);for i:=1 to 10 dowrite(a[i]:3);readkey;end. \\{end of the program}

Output: Insert The elements for the array1 2 36 5 47 8 9Ascending Arrangement of array1 2 3 4 5 6 7 8 9

{*Program 4*} (*FY B C A*)

{program: To find the sum of rows and columns of matrix}

program matrix;uses crt;var a:array [1..3,1..3] of integer; i,j,r,c:integer;begin \\{beginning of the program}

clrscr;writeln('enter the elements for the matrix');

for i:=1 to 3 do \\{reading matrix}beginfor j:=1 to 3 dobegin

read(a[i,j]);end;end;for i:=1 to 3 dobeginfor j:=1 to 3 dobegin r:=r+a[i,j] \\{applying logic}end; writeln(r); r:=0;end;writeln(‘Sum of Row and Column’);for j:=1 to 3 dobeginfor i:=1 to 3 dobegin c:=c+a[i,j] end; writeln(c); c:=0;end;readkey;end. \\{end of the program}

Output:

enter the elements for the matrix5 6 54 3 25 7 8Sum of Row and Column 16920141615

{*Program 5*} (*FY B C A*)

{program : To find addition of two matrices}

program matrix(add);uses crt;var a,b,c:array [1..3,1..3] of integer; \\{variable declarations} i,j:integer;begin

clrscr;writeln (‘Enter 1st matrix’);for i:=1 to 3 do \\{beginning of for loop matrix 1}beginfor j:=1 to 3 dobegin

read(a[i,j]);end;end;writeln (‘Enter 2nd matrix’);for i:=1 to 3 dobegin \\{beginning of for loop matrix 2}for j:=1 to 3 dobegin read(b[i,j]);end;end;for i:=1 to 3 do \\{adding 2 matrix}beginfor j:=1 to 3 dobegin c[i,j]:=a[i,j]+b[i,j];end;end;writeln(‘Addition of Matrices ‘);for i:=1 to 3 dobeginfor j:=1 to 3 dobegin \\{display}

write(c[i,j]:3);end;

writeln;end;readkey;end. \\{end of program}

Output:Enter 1st matrix1 1 12 2 23 3 3Enter 2nd matrix1 1 12 2 23 3 3Addition of Matrices 2 2 24 4 46 6 6

{*Program 6*} (*FY B C A*)

program matrixdiago;uses crt;var a:array [1..5,1..5] of integer; \\{variable declaration} i,j:integer;begin

clrscr; \\{beginning of for loop for reading}for i:=1 to 5 dobeginfor j:=1 to 5 dobegin read(a[i,j]);end;end;writeln(‘Diagonal Elements are’);for i:=1 to 5 do \\{beginning of for loop for displaying}beginfor j:=1 to 5 dobegin

if(i=j) thenwriteln(a[i,j]);

end;end;readkey; \\ {end of program}

end.

Output:1 1 1 1 12 2 2 2 23 3 3 3 34 4 4 4 45 5 5 5 5Diagonal Elements are 12345

{*Program 7*} (*FY B C A*)

{program : To Display even numbers in an array}

program arrayeven;uses crt;var a:array [1..10] of integer; \\{variable description} i,j:integer;begin

clrscr;writeln(‘Enter array elements’);for i:=1 to 10 do \\{beginning of for loop for reading matrix}

read(a[i]);writeln(‘Even Elements from Array are’);for i:=1 to 10 dobegin

if(a[i] mod 2 = 0) then \\{writing of condition}writeln(a[i]);

end;readkey;end. \\{end of program}

Output:

Enter array elements12345678910Even Elements from Array are246810

{*Program 8*} (*FY B C A*)

{program : To display upper triangular elements of matrix 3*3 order}program matrix;uses crt;var \\{Variable declaration} a:array [1..3,1..3] of integer; i,j:integer;begin

clrscr; \\{Beginning of for loop for reading}for i:=1 to 3 dobeginfor j:=1 to 3 dobegin

read(a[i,j]);end;end;writeln ('Upper Triangular Matrix is');for i:=1 to 3 dobegin \\{ Beginning of for loop for writing }for j:=1 to 3 dobegin

if(j>i) thenwriteln(a[i,j]);

end;end;readkey; \\{End of Program}end.

Output:1 2 34 5 67 8 9Upper Triangular Matrix is 236

{*Program 9*} (*FY B C A*)

{program : To Display the sum of diagonal elements of matrix 3*3 order}program matrixdisum;uses crt;var a:array [1..3,1..3] of integer; \\{variable declaration} i,j,sum:integer;begin

clrscr; \\{for loop for reading matrix}for i:=1 to 3 dobeginfor j:=1 to 3 dobegin

read(a[i,j]);end;end;for i:=1 to 3 do \\{for loop for writing matrix}beginfor j:=1 to 3 dobegin

if(i=j) thensum:=sum+a[i,j];

end;end;writeln(‘Sum of Diagonal Elements is ’,sum);readkey; \\ {end of program}end.

Output:1 2 31 2 31 2 3

Sum of Diagonal Elements 6

{*Program 10*} (*FY B C A*)

{program : To program arrayoddsum;uses crt;var {variable declaration} a:array [1..100] of integer; i,j,n,sum:integer;begin

clrscr;sum:=0;

writeln('How many elements do you want to enter in array');readln(n); {for loop for reading elements in array}for i:=1 to n do

read(a[i]); {for loop for writing elements in array}read(a[i]);

for i:=1 to n dobegin

if(a[i] mod 2 <> 0) thensum:=sum+a[i];

end;writeln('Sum of all odd elements in array',sum);readkey; {end of program}end.

Output:

How many elements do you want to enter in array10

12345678910Sum of all odd elements in array 25

{*Program 11*} (*FY B C A*)

{program : To check whether the given no is Armstrong no. or not}

program armstrong;uses crt;var

a,b,c,temp:integer; \\{variable declaration}begin

clrscr; c:=0; writeln(Enter a no:’); \\{entering a no for checking} read(a); temp:=a;while(a>0) dobegin b:=(a mod 10); a:=(a div 10); c:= c+(b*b*b);end;if(c=temp) then \\{if condition matches then is Armstrong no}begin

writeln('Its Armstrong Number');endelse \\{if condition doesn’t matches then it isn't Armstrong no}begin writeln('Not Armstrong Number');end;end;readkey;end. \\ {end of program}

Output:

Enter a no :153Its Armstrong number

{*Program 12*} (*FY B C A*)

{program : To find Fibonacci series up to given no.}

program fibonacci;uses crt;var

a,f0,f1,f2,temp:integer; \\{variable declaration}begin

clrscr; f0:=0; f1:=1; temp:=3;writeln('enter a no of terms required');read(a);writeln('The Fibonacci series is ');writeln(f0);writeln(f1);while(temp<=a) do \\{using while do command}begin

f2:=f0+f1;writeln(f2);f0:=f1;f1:=f2;temp:=temp+1;

end;readkey;end. \\{end of program}

Output:

Enter a no of terms required5The Fibonacci series is01123

{*Program 13*} (*FY B C A*)

{program : To convert a binary no into its decimal equivalent}

program binartod;uses crt;var

no,rem,i:integer; \\{variable declaration}a:array[1..10] of integer;

beginclrscr;

writeln('ENTER THE NUMBER');read(no);

i:=0;while no<>0 do \\{logic block}begin

rem:=no mod 2; a[i]:=rem; i:=i+1; no:=no div 2;end;

i:=i-1;writeln(‘Binary form of entered no is’);while i>0 dobegin

write(a[i]);i:=i-1;

end;readkey;end. \\{end of program} Output:

ENTER THE NUMBER36Binary form of entered no is10010

{*Program 14*} (*FY B C A*)

{program : To add the series of given no.}

program series;uses crt;var

i,x,r:integer; \\{variable declaration}sum,y:real;

beginclrscr;sum:=0;y:=1;

writeln('enter range of series');readln(r);writeln('enter value for series');readln(x);for i:=1 to r do \\{beginning of for loop}begin

y:=y*x;sum:=sum+1/y;

end;writeln(‘Sum of Series’);writeln(sum:3:3);readkey;end. \\{end of program}

Output:

enter range of series12enter value for series5Sum of Series0.250

{*Program 15*} (*FY B C A*)

{program : To add the series of given no.}

program series;uses crt;var

i,x,r:integer; \\{variable declaration} sum,f:real;begin

clrscr;sum:=0;f:=1;

writeln('Enter range of series');readln(r);for i:=1 to r do \\{beginning of for loop}begin

f:=f*i;sum:=sum+i/f;end;

writeln(‘Sum of Series’);writeln(sum:3:3);readkey;end. \\{end of program}

Output:

Enter range of series23Sum of Series2.718

{*Program 16*} (*FY B C A*)

{program : To convert a binary no. into its decimal equivalent }

program bitode;var

p,m,d,no:integer; \\ {variable declaration}begin

p:=1;d:=0;writeln('Enter a binary no'); \\ {reading from user}readln(no);while(no>0) do \\ {logic block}begin

m:=no mod 10;d:=d+m*p;no:=no div 10;p:=p*2;

end;writeln(‘Decimal form of entered binary ’,d); \\ {display result}end.

Output:Enter a binary no10010Decimal form of entered binary 18

{*Program 17*} (*FY B C A*)

{program : To check whether a given no. is prime or not} program prime;uses crt;var

i,no:integer;p:boolean; \\{variable declaration}

beginclrscr;

writeln('Enter a no');read(no);

i:=2;while(i<=no div 2) do \\{using while do command}begin

if(no mod i=0) then \\{using if then command}p:=true;i:=i+1;

end;if (p=true) thenbegin

writeln('NOT prime'); \\{displaying no is prime}endelsebegin

writeln('IT IS A PRIME NO'); \\{displaying number is not prime}end;readkey;end. \\{end of program}

Output:

Enter a no23IT IS A PRIME NO

{*Program 18*} (*FY B C A*)

{program : To display the largest among the three given no’s}

program larger;uses crt;var

p,q,r,max:integer; \\{variable declaration}begin

clrscr;writeln('enter three nos ');read(p,q,r);if (p>q)then \\{using if else command}

max:=pelse

max:=q;if (max>r) then

max:=maxelse

max:=r;writeln('The largest of these three nos is ',max); \\{displaying largest in matrix}readkey;end. \\{end of program}

Output:enter three nos639The largest of these three no is 9

{*Program 19*} (*FY B C A*)

{program : To program series;uses crt;var i,x,r,j:integer; {variable declaration} sum,f:real;begin

clrscr;sum:=0;f:=1;

writeln('Enter range of series'); {entering range of series}readln(r);for i:=1 to r do {calculating series}beginfor j:=1 to i dobegin

f:=f*i;end;sum:=sum+f;

end;writeln(sum:3:3); {display of sum}readkey;end. {end of program}

OutputEnter range of series2Sum5

{*Program 20*} (*FY B C A*)

(*write a program to display all prime numbers between 100 to 500.*)

program san;uses crt;var

i,j,k:integer; \\{declaration of variables}a:integer;

beginclrscr;

for i:=100 to 500 do \\{logic block}begin

a:=1;for j:=2 to i-1 dobegin

if (i mod j)=0 thenbegin

j:=i-1;a:=0;

end;end;

if a=1 thenwrite(i,' '); \\{display}

end;end.

OUTPUT SCREEN:

101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 197 199 211 223 227 224 233 239 241 251 257 263 369 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499

{*Program 21*} (*FY B C A*)

{program : To display table between two accepted no. in proper format} program table;var i,j,no1,no2,res:integer; \\{variable declaration}beginwriteln('enter no1'); \\{input from user of range}readln(no1);writeln('enter no2');readln(no2);writeln(‘Tables’);for i:=no1 to no2 dobeginfor j:=1 to 10 do \\{calculation of each table}begin

res:=i*j; writeln(i,'*',j,'=',res); \\{displaying each term} end;readln;end;end.

Output:

Enter Starting No1Enter Ending No2Tables 1*1 = 11*2 = 21*3 = 31*4 = 4 1*5 = 51*6 = 61*7 = 71*8 = 81*9 = 91*10 = 10

2*1 = 22*2 = 42*3 = 62*4 = 8 2*5 = 102*6 = 122*7 = 142*8 = 162*9 = 182*10 = 20

{*Program 22*} (*FY B C A*) {program : To copy the contet of one file to another}

program copyfile;uses

crt;var s,d : text; \\{variable declaration} x:char;

begin \\ {identifying file}assign(s,'source.txt');assign(d,'dest.txt');reset(s); \\ {opening the s file}rewrite(d); \\ {read till end of file}

while NOT eof(s) dobegin \\{read till end of each line}

while NOT eoln(s) dobegin

read(s,x); \\ {read from s & store in x} write(d,x); \\ {write in d from x}

end;readln(s);writeln(d); \\{display Output:}end; close(s); \\ {close file s & d}close(d);end. Output:

source.txtmy name is Vivek kumar.dest.txtmy name is Vivek kumar.

{*Program 23*} (*FY B C A*)

{program : To find no. of “a” in a text file } program findchar_count;uses crt;var \\{variable identification}

s: text; x:char; i:integer;begin

clrscr;assign(s,'source.txt'); \\{identifying file}reset(s); \\{opening file}i:=0;

while NOT eof(s) dobegin while NOT eoln(s) do begin read(s,x); if(x='a') then begin i:=i+1; end;end;readln(s);end;writeln('No of As in File is',i);close(s); \\{closing file}readkey;end. \\{end of program}\

Output:

source.txtMy name is Vivek kumar..

No of A’s in File is 2

{*Program 24*}(*FY B C A*)

{program : To display tabs,char,lines in a text file}

{program copyfile;Uses crt;var \\{declaration of variable} s: text; x:char; i,j,k:integer;begin

clrscr;assign(s,'source.txt');reset(s);i:=0;j:=0;k:=0;

while NOT eof(s) do \\{reading file and using conditions}begin

while NOT eoln(s) do begin read(s,x); if(((ord(x)>123) and (ord(x)<96)) or ((ord(x)<91) and (ord(x)>64)))then begin i:=i+1; end; if(ord(x)=10) then begin j:=j+1; end; if(ord(x)=9) then begin k:=k+1; end;

end;readln(s);end;writeln('No of lines in File is',k); \\{display Output:}writeln('No of Tabs in file is ',j);writeln('No of characters in file is',i);close(s);readkey;end. \\{end of program}

Output:

No of lines in File is 3No of Tabs in file is 3No of characters in file is 100

{*Program 25*} (*FY B C A*)program : To display the content of a file in reverse order}

program reverse;uses crt;var \\{variable declaration} f:text; s:file of char; x:char; size:longint;begin

clrscr;assign(s,'source.txt'); \\{assigning file variables}assign(f,'file1.txt');reset(s);reset(f);size:=filesize(s);seek (s,size);

while NOT eof(s) do \\{read and applying logic over files}begin while NOT eoln(s) do begin while size>0 do begin read(s,x); write(s,x); size:=size-1; end; end;readln(f);end;close(f);close(s);end.

Output:Source.txtMy name is indira.File1.txt.aridni si eman yM

{*Program 26*} (*FY B C A*)

{program : To accept 10 natural no’s in a file & create two files as “oddtext” & “eventext” to store odd 7even no’s respectively}

program oddevenfile;uses crt;var s,o,e:text; \\{variable declaration} x:char;begin

clrscr;assign(s,'source.txt'); \\{assigning file variables}assign(o,'odd.txt');assign(e,'even.txt');reset(s);rewrite(e);rewrite(o);

while NOT eof(s) do \\{read and apply logic for prog}begin while NOT eoln(s) do begin read(s,x); if(odd(ord(x))) then begin write(o,x); end else begin write(e,x); end;

end;readln(s);writeln(e);writeln(o);end;close(e);close(o);close(s);end. \\{end of program}

Output:

Source.txt1 2 3 4 5 6 7 8 9 Odd.txt 13579Even.txt2468

{*Program 27*}(*FY B C A*)

{program:To concantenate two text files}

program concatenate;uses crt;var f:text; \\{variable declaration} s:file of char; x:char; size:longint;begin

clrscr;assign(s,'source.txt'); \\{assigning file variables}assign(f,'file1.txt');reset(s);reset(f);size:=filesize(s);seek (s,size);

while NOT eof(f) do \\{read and apply logic for prog}begin while NOT eoln(f) do begin read(f,x); write(s,x) end;readln(f);end;close(f);close(s);end. \\{end of program}

Output:

Source.txtMy name is Rohit.File1.txtI am from India.Source.txt after execution of programMy name is RohitI am from India.

{*Program 28*} (*FY B C A*)

{Program : To accept 10 integers in a file and create two files as “positive text “ & “negative text” to store positive & negative numbers respectively}

program positive_negative_file;uses crt;var s,o,e:text; \\{variable declaration} x:char;begin

clrscr;assign(s,'source.txt'); \\{assigning file variables}assign(p,'positive.txt');assign(n,'negative.txt');reset(s);rewrite(p);rewrite(n);

while NOT eof(s) do \\{read and apply logic for prog}begin while NOT eoln(s) do begin read(s,x); if((ord(x)>=-1)) then begin write(p,x:3); end else begin write(n,x:3); end; end;readln(s);writeln(n);writeln(p);end;close(s);close(n);close(p);end. \\{end of program}

Output:

Source.txt1 -3 4 5 -6 7 9Negative.txt-3-6Positive.txt145798

{*Program 29*} (*FY B C A*)

program toupper;uses crt;var s,o:text; {variable declaration} x:char;begin

clrscr;assign(s,'source.txt'); {assigning file variables}assign(o,'upper.txt');reset(s);rewrite(o);

while NOT eof(s) do { read and apply logic for prog }begin

while NOT eoln(s) do begin read(s,x); write(o,UpCase(x)); end;readln(s);writeln(o);end;close(o);close(s);end. {end of program}

Output:Source.txtmy name is rohitUpper.txtMY NAME IS ROHIT

{*Program 30*} (*FY B C A*)

program rename;uses crt;var s,d : text; \{variable declearation} x:char; name,new:string;begin

clrscr;writeln('Enter File name with path to rename');readln(name);writeln('Enter new name with path for this file');readln(new); {new name of file}assign(s,name);rename(s,new);writeln(name,' is renamed to ',new);readln;

end. {end of program}

Output:Enter File name with path to renameC:\rohit.txtEnter new name with path for this fileC:\bca.txtC:\rohit.txt is renamed to C:\bca.txt

{*Program 31*} (*FY B C A*)

{Program : To accept information of five employees & display the employee whose age is above 35 }

program records;uses crt;

typeemployee=record \\{defining record}

codeno:integer; name:string[25]; age:integer;end;var

s:array[1..5] of employee;i:integer;

beginclrscr;writeln('Enter Name, Code, Age of 5 employees');

for i:=1 to 5 dobegin

read(s[i].name,s[i].codeno,s[i].age); \\{reading records}end;writeln(‘Employees whose ages are more than 35’);for i:=1 to 5 do \\{applying logic}begin

if( s[i].age>35) thenbeginwriteln(s[i].name,' ',s[i].codeno,' ' , s[i].age); \\{displaying req records}end;

end;readkey;end. \\{end of program

Output:

Enter Name, Code, Age of 5 employeesRohit 123 33Aditya 135 50Avadhoot 134 36Vinayak 140 40Rajesh 130 40

Employees whose ages are more than 35Aditya 135 50Avadhoot 134 36Vinayak 140 40

{*Program 32*} (*FY B C A*){Program : To accept information of 5 employees & display whose name = Satish}program records;uses crt;type employee=record \\{defining record} codeno:integer; name:string[25]; age:integer;end;var

s:array[1..5] of employee;i:integer;

beginclrscr;writeln('enter Name, Code, Age of 5 employees');

for i:=1 to 5 dobegin

read(s[i].name,s[i].codeno,s[i].age); \\{reading records}end;

writeln('Employee whose name is Satish');for i:=1 to 5 do \\{applying logic}begin

if( s[i].name='Satish') thenbeginwriteln(s[i].name,' ',s[i].codeno,' ' , s[i].age); \\{displaying req records}

end;readkey;end;end. \\{end of program}

Output:

Enter Name, Code, Age of 5 employeesSatish 65 40Sammer 66 42Sunil 67 46Swapnil 68 48Rajesh 130 40

Employee whose name is SatishSatish 65 40

{*Program 33*} (*FY B C A*)

{Program : To accept information of 5 students & display the details of top three students}

program records;uses crt;type student=record \\{defining records} roll:integer; name:string[25]; m1,m2,tot:longint; percent:real;end;var

s:array[1..5] of student;i,j,max:integer;temp:student;

beginwriteln('Enter Name, Roll no, Marks of 2 sub of 5 student');

for i:=1 to 5o dobegin

read(s[i].name,s[i].roll,s[i].m1,s[i].m2); \\{reading records}end;for i:=1 to 5 dobegin

s[i].tot:=s[i].m1+s[i].m2;s[i].percent:=s[i].tot/2;

end;for i:=1 to 5 do \\{applying logic}begin for j:=i+1 to 5 do begin if(s[i].tot>s[j].tot) then begin temp:=s[i]; s[i]:=s[j]; s[j]:=temp; end; end;end;writeln('Top 3 students are');for i:=3 downto 1 do \\{displaying records}beginwriteln(s[i].name,' ', s[i].roll,' ' , s[i].tot:2,' ',s[i].percent:2); {toppers are}end;end. \\{end of program}

Output:

Rohit 1 60 65Ram 2 65 55Sanket 3 56 67Sayali 4 67 66Shamal 5 56 67Top 3 students areSayali 4 133 6.7E+01Rohit 1 125 6.3E+01Shamal 5 123 6.2E+01

{*Program 34*} (*FY B C A*)

program records;uses

crt;type

student=record {defining records} roll:integer; name:string[25]; m1,m2,tot:longint; percent:real;end;var

s:array[1..50] of student;i,j,max:integer;temp:student;

beginclrscr;writeln('Enter Name,Roll no,Marks of 2 sub of 50 student');

for i:=1 to 50 dobegin

readln(s[i].name,s[i].roll,s[i].m1,s[i].m2); {reading records}end;for i:=1 to 50 dobegin

s[i].tot:=s [i].m1+s[i].m2;end;writeln('Students Records Are as Follows');for i:=1 to 50 do {displaying records}beginwriteln(s[i].name,' ', s[i].roll,' ' , s [i].tot:2,' ',s [i].percent:2); end;readkey;end.

{*Program 35*} (*FY B C A*)

(*write a program to swap two numbers using function*)

program swap2;uses crt;var n1,n2:integer; function swap(a,b:integer):integer; var temp:integer; begin \\{beginning of the function} writeln('Enter two numbers'); readln(a,b); temp:=a; a:=b; b:=temp; writeln('The numbers after swaping are'); writeln(a); writeln(b);end; \\{end of the function}begin \\{beginning of program}clrscr; swap(n1,n2); \\{displaying the result}readkey;end. \\{end of program}

Output:

Enter two numbers956The numbers after swaping are569

{*Program 36*} (*FY B C A*)

{*write a program to x to the power n using parameter passing in procedure*}

program powerx;uses crt;var x,y,i,pow:integer; function power(x,y:integer):integer; begin \\{beginning of the function} pow:=1; for i:=1 to y do begin pow:=pow*x; \\{calculating result} end; power:=pow; end; \\{end of the function}begin \\{beginning of main program}clrscr; writeln('Enter base and power'); readln(x,y); writeln(x,' to power ' ,y ,' is '); writeln(power(x,y)); \\{displaying the result}readkey;end. \\{end of program}

Output:

Enter base and power242 to power 4 is16

{*Program 37*} (*FY B C A*)

program factfuncion;uses

crt;var

i,j:integer; {declaring global variables}function f(k :integer):integer; {declaring function}begin if(k=1)then f:=1 else begin f:=k*f(k-1); end;end;begin

clrscr; writeln('Enter the number:'); read(i); writeln('The factorial of a number is:',f(i)); {calling function}end.

OUTPUT: SCREEN:Enter the number:5The factorial of a number is:120

{*Program 38*} (*FY B C A*)

{Program : To find sum of digits of given no.’s using recursive function}program digsum;uses crt;var no:integer; function sum(n:integer):integer; begin \\{beginning of the function} if(n<=0) then begin sum:=0; end else begin sum:=n mod 10 + sum(n div 10); \\{calculating result} end; end; \\{end of the function}begin \\{beginning of main program}clrscr; writeln('Enter a number'); readln(no); writeln('The digit sum is'); writeln(sum(no)); \\{displaying the result}readkey;end. \\{end of program} Output:Enter a number963The digit sum is18