a. Write a program to input base and height of the triangle from user. The program should calculate and display the area of triangle using SUB – END SUB statement.(Hint: A=1/2bh)Modular ProgrammingPerform using sub procedure:
DECLARE SUB Triangle( )
CLS
CALL Triangle
END
SUB Triangle
INPUT "Enter a base of triangle"; b
INPUT "Enter a height of triangle"; h
LET Area = (1/2) *b*h
PRINT "Area of triangle is", Area
END SUB
b. Write a sub program to print area of a cylinder, radius and height of cylinder are given by the user in main module and pass them as parameter list when sub program is called.DECLARE SUB cyl(r, h)CLSINPUT "Enter a radius"; rINPUT "Enter a height"; hCALL cyl(r, h)ENDSUB TriangleLET Area = (22/7)*r^2*hPRINT "Area of triangle is", AreaEND SUBc. Write a sub-procedure to find the solution of quadratic equation ax2 +bx +c=0. The program should ask the value of a, b, and c from user in main module and pass them as parameter list when a sub program is called.DECLARE SUB value(a, b, c)CLSPRINT "Calculate ax^2+bx+c=0"INPUT "Enter a value of a"; aINPUT "Enter a value of b"; bINPUT "Enter a value of c"; cCALL value(a, b, c)ENDSUB TriangleLET d=(b*b-4*a*c)^1/2LET x = (-b+d)/2*aLET y = (-b-d)/2*aPRINT "Result of quadratic equation are x, y"; x, yEND SUBd. Write a sub program to display the acceleration of car. The program should ask initial velocity, final velocity and time taken by the car from user in main module and pass them as parameter list when a sub program is called.DECLARE SUB accel(u, uf, t)CLSPRINT "Acceleration of Car"INPUT "Enter initial velocity of a car"; aINPUT "Enter final velocity of a car"; bINPUT "Enter time taken by of a car"; cCALL accel(a, b, c)ENDSUB accel(u, uf, t)LET ac = (uf-u)/tPRINT "Acceleration of car is:::::"; acEND SUBe. Write a sub program to check whether an input number is “Positive” or “Negative” or “Zero”. The program should ask a number from user in main module and pass it as parameter list when a program is called.DECLARE SUB PONE (A)CLSINPUT "Enter a number"; PBRCALL PONE(PBR)ENDSUB PONE (B)C= SGN(B)IF C= -1 THEN` PRINT "Negative"ELSEIF C=1 THENPRINT "Positive"ELSEPRINT "Zero"END IFEND SUBf. Write a program to decide whether an input number is even or odd. The program should ask a number from user in the main module and pass them as parameter list.DECLARE SUB OE(N)CLSINPUT "Enter a Number"; PKRPRINT OE(PKR)ENDSUB OE(M)R=M mod 2IF R=0 THENPRINT"Even"ELSEPRINT "Odd"END IFEND SUBg. Write a program to declare a sub-procedure module to decide whether a triangle can be formed or not if there sides of a triangle are keyed by the user.DECLARE SUB triangle(a, b, c)CLSINPUT "Enter first side"; aINPUT "Enter second side"; bINPUT "Enter third side"; cCALL triangle(a, b, c)ENDSUB triangle(a, b, c)IF (a+b)>c and (b+c)>a and (a+c)>b thenPRINT "Triangle can be formed by given sides"END SUBh. Write a sub program to print first 10 natural numbers followed by its square and cube.DECLARE SUB NSC( )CLSCALL NSCENDSUB NSCPRINT "Number", "Square", "Cube"FOR I = 1 to 10PRINT I, I^2, I^3NEXT IEND SUBi. Write a sub program using SUB .... END SUB statement to calculate and display the geometric series. The program should ask first term, common ratio and numbers of terms in main module and call the sub program to get the result.DECLARE SUB NSC(a, b, c)CLSINPUT "Enter a first term", aINPUT "Enter a common ratio"; bINPUT "Enter a number of terms"; cCALL NSC(a, b, c)ENDSUB NSC (a, b, c)FOR I = 1 to cPRINT a;a=a^bb=b+1NEXT IEND SUBj. Write a sub-procedure to display the sum of first 20 even numbers.DECLARE SUB SUM( )CLSCALL SUMENDSUB SUMFOR I = 2 to 20 STEP 2S=S+INEXT IPRINT "Sum of first 20 even numbers is :"; SEND SUBk. Write a sub-procedure to display the sum of first 30 odd numbers.DECLARE SUB SUM( )CLSCALL SUMENDSUB SUMFOR I = 1 to 30 STEP 2S=S+INEXT IPRINT "Sum of first 30 odd numbers is :"; SEND SUBl. Write a sub-procedure to display the numbers which are multiples of 5 and 6 from 5 to 100.DECLARE SUB multiple( )CLSCALL multipleENDSUB multipleFOR I = 5 to 100IF I MOD 5 =0 and I MOD 6 =0 THENPRINT I;END IFNEXT IEND SUBm. Write a sub program to decide whether an input year is leap year or not.DECLARE FUNCTION leap( )CLSCALL leapENDSUB leapINPUT "Enter a year"; yIF y MOD 4 = 0 and y mod 100= 0 thenPRINT "Leap year"ELSEPRINT "Not leap year"END IFEND SUBn. Write a program to input a number and check whether the number is Armstrong or not using SUB - END SUB.DECLARE SUB arm( )CLSCALL armENDSUB armINPUT "Enter a number"; NM=NWHILE N<>0R=N MOD 10S= S+R^3N=N\10WENDIF M=S THENPRINT "Armstrong"ELSEPRINT " Not Armstrong"END IFEND SUBo. Write a program to input and check whether the number is prime or not using SUB - END SUB.DECLARE SUB prime( )CLSCALL primeENDSUB primeINPUT "Enter a number"; NFOR C = 1 to NIF N MOD C = 0 then S=S+1NEXT CIF S=2 THEN PRINT "Prime Number"END SUBp. Write a sub procedure program using SUB..... END SUB statement to display the prime number from 2 to 100.DECLARE SUB prime( )CLSCALL primeENDSUB primeFOR P = 2 to 100FOR C = 1 to PIF P MOD C = 0 then S=S+1NEXT CIF S=2 THEN PRINT P;NEXT PEND SUBq. Write a sub program using SUB......END SUB statement to find sum from 1 to p given number. For example: sum = 1+2+3+4+ ……+N.DECLARE SUB SUM( )CLSCALL SUMENDSUB SUMINPUT "Enter a number"; BFOR I = 1 to BS=S+INEXT IPRINT "Sum of all numbers up to";B;"is="; SEND SUBr. Write a sub-program using SUB....END SUB statement to display factorial of an input number. Note: The product from 1 to given number is called factorial of number. For Example: The factorial of 5 is 120. That is 1*2*3**5=120.DECLARE SUB fact( )CLSCALL factENDSUB factP=1INPUT "Enter a number"; BFOR I = 1 to BP=P*INEXT IPRINT "Factorial of ";B;"is="; PEND SUBs. Write a sub-program using SUB.....END SUB statement to check whether input string is palindrome or not. For example, LIRIL is a palindrome word. Because the word pronounced same forward and backward.DECLARE SUB palin( )CLSCALL palinENDSUB palinINPUT "Enter a word"; B$FOR I = 1 to len(B$)P$=MID$(B$, I, 1)PAL$=P$+PAL$NEXT IIF UCASE$(B$)=UCASE$(PAL$) THENPRINT "Palindrome"ELSEPRINT "Not Palindrome"END IFEND SUBt. Write a Sub Program to check whether an input character is alphabet or digit or symbol. The program should ask a character from user in main module and pass is as parameter list when a sub program is called.DECLARE SUB ADS(CH$)CLSINPUT "Enter a character"; PBR$CALL ADS(PBR$)ENDSUB ADS(RPG$)S=ASC(RPG$)IF S>=48 and S<=57 TNENPRINT "Entered character is Number"ELSEIF S>=65 AND S<=90 OR S>=97 AND S<=122 THENPRINT "Entered character is Alphabet"ELSEPRINT "Entered character is Symbol"END IFEND SUBu. Write a sub program to enter a multi digits number and print sum of even digits and products of odd digits.DECLARE SUB SP( )CLSCALL SPENDSUB SPP = 1INPUT "Enter a multi digit number"; NWHILE N<>0R = N MOD 10IF R MOD 2 =0 THENS= S+ RELSEP = P*REND IFN=N\10WENDPRINT "Sum of Even digit is:::"; SPRINT " Product of Odd digit is ::::"; PEND SUBv. Write a sub program to print the series 7,22,11,34 …. Up to 10th times.DECLARE SUB FUL( )CLSCALL FULENDSUB FULA = 7FOR P = 1 to 10PRINT A;IF A MOD 2 = 0 thenA=A\2ELSEA=A*3+1END IFNEXT PEND SUBw. Write a sub.... end sub program to enter 10 different numbers and find the smallest one using array variable.DECLARE SUB SMALL (S( ))CLSDIM S(10)FOR K = 1 to 10INPUT "Enter the numbers"; S(K)NEXT KCALL SMALL (S( ))ENDSUB SMALL (S( ))SM=S(1)FOR C = 2 to 10IF S(C)>SM THEN SM=S(C)NEXT CPRINT "The smallest number is:::", SMEND SUBPerform by using User defined Function:a. Write a function procedure to print the distance travelled by a car. The program should ask initial velocity, final velocity and time taken by the car and the program should pass them as parameter list when a function procedure is called.DECLARE FUNCTION dis(u, uf, t)CLSPRINT "Distance travelled by a Car"INPUT "Enter initial velocity of a car"; aINPUT "Enter final velocity of a car"; bINPUT "Enter time taken by of a car"; cPRINT dis(a, b, c)ENDFUNCTION dis(u, uf, t)LET a = (uf-u)/tLET s =u*t+(1/2)*a*t^2dis=sEND FUNCTIONb. Write a function program to check whether an input number is “Positive” or “Negative” or “Zero”. The program should ask a number from user in main module and pass it as parameter list when a function program is called.DECLARE FUNCTION PONEZ$ (A)CLSINPUT "Enter a number"; PBRPRINT PONEZ$(PBR)ENDSUB FUNCTION PONEZ$ (B)C= SGN(B)IF C= -1 THEN` P$= "Negative"ELSEIF C=1 THENP$= "Positive"ELSEP$="Zero"END IFPONEZ$=P$END FUNCTIONc. Write a function program to decide whether an input number is even or odd. The program should ask a number from user in main module and pass it as parameter list.DECLARE FUNCTION OE$(N)CLSINPUT "Enter a Number"; FULPRINT OE$(FUL)ENDFUNCTION OE$(M)R=M mod 2IF R=0 THENH$="Even"ELSEH$= "Odd"END IFOE$=H$END FUNCTIONd. Write a function procedure to print square of first 10 natural numbers.DECLARE FUCTION SUM(I)CLSFOR I = 1 to 10PRINT SUM(I)NEXT IENDFUNCTION SUM(I)SUM=I^2END FUNCTIONe. Write a function procedure to display the sum of digits in an input number. The program should ask a number from user in main module and pass it as parameter list when a function is called.DECLARE FUNCTION sumdi (N)CLSINPUT "Enter a multi digit number"; NPRINT sumdi (N)ENDFUNCTION sumdi (N)WHILE N<>0R = N MOD 10S=S+RN=N\10WENDsumdi = SEND FUNCTIONf. Write a function procedure to display the sum of even digits in an input number. The program should ask a number from user in main module and pass it as parameter list when a function is called.DECLARE FUNCTION even (N)CLSINPUT "Enter a multi digit number"; NPRINT even (N)ENDFUNCTION even (N)WHILE N<>0R = N MOD 10IF R MOD 2=0 THEN S=S+RN=N\10WENDeven = SEND FUNCTIONg. Write a function procedure to display the total number of digits in an input number. The program should ask a number from user in the main module and pass it as parameter list when a function is called.DECLARE FUNCTION sumdi (N)CLSINPUT "Enter a multi digit number"; NPRINT "Total number of digits are ";sumdi (N)ENDFUNCTION sumdi (N)WHILE N<>0R = N MOD 10S=S+1N=N\10WENDsumdi = SEND FUNCTIONh. Write a function procedure to display the product of digits in an input number. The program should ask a number from user in the main module and pass it as parameter list when a function is called.DECLARE FUNCTION product (R)CLSINPUT "Enter a multi digit number"; NPRINT "Total number of digits are "; product (N)ENDFUNCTION product (N)LET P=1WHILE N<>0LET R = N MOD 10LET P=P*RLET N=N\10WENDproduct = PEND FUNCTIONi. Write a function procedure to return the sum ASCII value of each character of a word. The program should ask a word from user in main module and pass it as parameter list.DECLARE FUNCTION asi (CH$)CLSINPUT "Enter a multi digit number"; N$PRINT "Total number of digits are ";asi (N$)ENDFUNCTION asi (N$)FOR I = 1 to LEN(N$)R$ = MID$(N$, I, 1)A=ASC(R$)S=S+ANEXT Iasi = SEND FUNCTIONj. Write a function procedure to check whether an input string is palindrome or not. The program should ask a string from user in main module and pass it as parameter list when a function is called.DECLARE FUNCTION palin$(W$)CLSINPUT "Enter a String"; ST$PRINT palin$(ST$)ENDFUNCTION palin$(B$)FOR I = 1 to len(B$)P$=MID$(B$, I, 1)PAL$=P$+PAL$NEXT IIF UCASE$(B$)=UCASE$(PAL$) THENp$= "Palindrome"ELSEp$= "Not Palindrome"END IFpalin$=p$END FUNCTIONk. Write a function procedure to print an input word into alternate capital. For example, if input word is "SCIENCE”, the output should be “ScIeNcE”. The program should pass a string as a parameter list when a function is called.DECLARE FUNCTION alter$(W$)CLSINPUT "Enter a String"; ST$PRINT alter$(ST$)ENDFUNCTION alter$(B$)FOR I = 1 to len (B$)P$=MID$(B$, I, 1)IF I mod 2 <>0 THENPAL$=PAL$ + UCASE$(P$)ELSEPAL$=PAL$ + LCASE$(P$)NEXT Ialter$=PAL$END FUNCTIONl. Write a function procedure to print an input name of a person in abbreviated form. For example, if you input a name “Sachin Kumar Malla”, the output given by the function should be SKM.DECLARE FUNCTION abb$(W$)CLSINPUT "Enter a Full Name"; ST$PRINT abb$(ST$)ENDFUNCTION abb$(B$)B$=UCASE$(B$)P$=LEFT$(B$,1)FOR I = 1 to len (B$)R$=MID$(B$, I, 1)IF R$=" " THENB$=B$+"."+MID$(B$, I+1,1)END IFNEXT Iabb$=B$END FUNCTIONm. Write a function procedure to return the value of total number of consonants in a sequence. The program should ask a sentence from user in main module and pass it as parameter list when a function is called.DECLARE FUNCTION conso(W$)CLSINPUT "Enter a string"; ST$PRINT "Total Number of consonants are ";conso(ST$)ENDFUNCTION conso(B$)B$=UCASE$(B$)FOR I = 1 to len (B$)R$=MID$(B$, I, 1)SELECT CASE R$CASE "A", "E", "I", "O", "U"V=V+1CASE ELSEC=C+1END SELECTNEXT Iconso=CEND FUNCTIONn. Write a function procedure to check whether an input number is palindrome or not. The program should ask a number from user in main module and pass it as parameter list when a function is called without using string function like LEN and MID$.DECLARE FUNCTION palin$(W)CLSINPUT "Enter a string"; STPRINT "Total Number of consonants are ";palin$(ST)ENDFUNCTION palin$(B)B$=STR$(B)FOR I = 1 to len (B$)P$=MID$(B$, I, 1)PAL$=P$+PAL$NEXT IIF UCASE$(B$)=UCASE$(PAL$) THENC$ ="Palindrome"ELSEC$= "Not Palindrome"END IFNEXT Ipalin$=C$END FUNCTIONo. Write a program to define user defined function to find the HCF of any two numbers.DECLARE FUNCTION HCF ( )CLSPRINT "HCF of given numbers is "; HCFENDFUNCTION HCFINPUT "Enter a numbers "; P, QWHILE P MOD Q <> 0S = P MOD QP = QQ = SWENDHCF = QEND FUNCTION
No comments:
Post a Comment