Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Thursday, March 21, 2024

"110 Crucial QBasic and C Programming Solutions for SEE and Grade 10 Students"


"110 Crucial QBasic and C Programming Solutions for SEE and Grade 10 Students"


"110 Crucial QBasic and C Programming Solutions for SEE and Grade 10 Students"



Writing a Program in QBASIC using Modular Programming

(It carries 4 marks)

1. New specification grid 2077

Write a program in QBASIC that asks length, breadth and height of room and calculates its area and volume. Create a user-defined function to calculate area and sub-program to calculate volume. Hint: [A =L×B], [V=L×B×H]

DECLARE FUNCTION area (l, b)

DECLARE SUB vol (l, b, h)

CLS

INPUT "Enter length, breadth and height"; l, b, h

PRINT "Area="; area(l, b)

CALL vol(l, b, h)

END

 

FUNCTION area (l, b)

area = l * b

END FUNCTION

 

SUB vol (l, b, h)

v = l * b * h

PRINT "volume"; v

END SUB

 

2.  SEE 2078

Write a program in QBASIC that asks length, breadth of a room and calculates its area and perimeter. Create a user define function to calculate area and sub program to calculate perimeter. [Hint: [Area=L×B], P=2(L+B)]]     

Ans:

DECLARE FUNCTION area(l,b)

DECLARE SUB perimeter(l,b)

CLS

INPUT “Enter length and breadth”;l,b

PRINT area(l,b)

CALL perimeter(l,b)

END

 

FUNCTION area(l,b)

Area=l*b

END FUNCTION

 

SUB perimeter(l,b)

P=2*(l+b)

PRINT p

END SUB

 

3.  SEE Grade Promotion Exam 2078(2022)

Write a program to calculate the area of a circle using the function procedure and use the SUB procedure to calculate its circumference in QBASIC. [Hints: (A=Ï€r2) , (C=2Ï€r)]

DECLARE FUNCTION area(r)

DECLARE SUB cirm(r)

CLS

INPUT "Enter radius";r

PRINT area(r)

CALL cirm(r)

END

 

FUNCTION area(r)

area=3.14*r2

END FUNCTION

 

SUB cirm(r)

c=3.14*2*r

PRINT c

END SUB

 

4.  PABSON SEE Pre Board Examination 2078

Write a program in QBASIC that allows user to enter radius of a circle. Create a user define function to find area of circle and sub procedure to find volume of cylinder. Hint: [A=Ï€r2, v=Ï€r2h] 

DECLARE FUNCTION area (r)

DECLARE SUB vol (r, h)

CLS

INPUT "Enter radius and height"; r, h

PRINT area(r)

CALL vol(r, h)

END

 

FUNCTION area (r)

a = 22 / 7 * r ^ 2

area = a

END FUNCTION

 

SUB vol (r, h)

v = 22 / 7 * r ^ 2 * h

PRINT v

END SUB

 

5.  Write a program in QBASIC to input radius of circle and calculate its area using function and circumference using sub procedure. [Area=pie×r2 and Circumference=2pie r] [4]

DECLARE FUNCTION area (r)

DECLARE SUB cir (r)

CLS

INPUT "enter radius"; r

PRINT "area"; area(r)

CALL cir(r)

END

 

FUNCTION area (r)

area = 22 / 7 * r * r

END FUNCTION

 

SUB cir (r)

c = 2 * 22 / 7 * r

PRINT "Circumference"; c

END SUB

 

6.         WAP in QBASIC to input radius of circle and calculate its area using FUNCTION…END FUNCTION and circumference using SUB…END SUB [Area=Ï€×r2 and Circumference=2Ï€r]      

DECLARE FUNCTION area (r)

DECLARE SUB cir (r)

CLS

INPUT "Enter radius"; r

PRINT area(r)

CALL cir(r)

END

 

FUNCTION area (r)

area = 22 / 7 * r ^ 2

END FUNCTION

 

SUB cir (r)

c = 2 * 22 / 7 * r

PRINT c

END SUB

 

7.         Write a program in QBASIC that allow user to enter the length and breadth of rectangle. Create a user define function to find the area of rectangle and sub procedure to find perimeter of rectangle.

DECLARE FUNCTION area (l, b)

DECLARE SUB per (l, b)

CLS

INPUT "enter length and breadth"; l, b

PRINT area(l, b)

CALL per(l, b)

END

 

FUNCTION area (l, b)

area = l * b

END FUNCTION

 

SUB per (l, b)

p = 2 * (l + b)

PRINT p

END SUB

 

8.         WAP to input any three numbers and calculate sum of three numbers by using FUNCTION procedure and average of three numbers by using SUB procedure.

DECLARE FUNCTION sum (a, b, c)

DECLARE SUB avg (a, b, c)

CLS

INPUT "Enter any three numbers"; a, b, c

PRINT "sum of two numbers"; sum(a, b, c)

CALL avg(a, b, c)

END

 

SUB avg (a, b, c)

av = (a + b + c) / 3

PRINT "Average of three numbers"; av

END SUB

 

FUNCTION sum (a, b, c)

sum = a + b + c

END FUNCTION

 

9. Papson Pre-board Exam 2079

WAP to input any three numbers and display the greatest number by using FUNCTION procedure and smallest number by using SUB procedure. (P

DECLARE SUB sm (a, b, c)

DECLARE FUNCTION gr (a, b, c)

CLS

INPUT "Enter any three numbers="; a, b, c

CALL sm(a, b, c)

PRINT "Greatest no="; gr(a, b, c)

END

 

FUNCTION gr (a, b, c)

IF a > b AND a > c THEN

g = a

ELSEIF b > c THEN

g = b

ELSE

g = c

END IF

gr = g

END FUNCTION

 

SUB sm (a, b, c)

IF a < b AND a < c THEN

S = a

ELSEIF b < c THEN

S = b

ELSE

S = c

END IF

PRINT "Smallest no="; S

END SUB

 

10.  WAP to input any string and display string in reverse order using FUNCTION and check palindrome or not using SUB procedure.

DECLARE SUB pal (w$)

DECLARE FUNCTION rev$ (w$)

CLS

INPUT "Enter any string="; w$

CALL pal(w$)

PRINT rev$(w$)

END

 

SUB pal (w$)

FOR x = LEN(w$) TO 1 STEP -1

m$ = m$ + MID$(w$, x, 1)

NEXT x

IF w$ = m$ THEN

PRINT "Palindrome"

ELSE

PRINT "Not palindrome"

END IF

END SUB

 

FUNCTION rev$ (w$)

FOR x = LEN(w$) TO 1 STEP -1

m$ = m$ + MID$(w$, x, 1)

NEXT x

rev$ = m$

END FUNCTION

 

11. WAP to input any number and check whether input number is odd or even by using SUB and check positive and negative by using FUNCTION.

DECLARE SUB oe (n)

DECLARE FUNCTION po$ (n)

CLS

INPUT "Enter any number="; n

CALL oe(n)

PRINT po$(n)

END

 

SUB oe (n)

IF n MOD 2 = 0 THEN

PRINT "Even number"

ELSE

PRINT "Odd number"

END IF

END SUB

 

FUNCTION po$ (n)

IF n > 0 THEN po$ = "Positive number"

IF n < 0 THEN po$ = "Negative number"

IF n = 0 THEN po$ = "Netural number"

END FUNCTION

 

12. WAP to input any string and display vowel letters by using FUNCTION and consonant letters from using SUB procedure.

DECLARE FUNCTION vowel$ (w$)

DECLARE SUB cons (w$)

CLS

INPUT "Enter any string"; w$

PRINT vowel$(w$)

CALL cons(w$)

END

 

SUB cons (w$)

FOR x = 1 TO LEN(w$)

m$ = UCASE$(MID$(w$, x, 1))

SELECT CASE m$

CASE "A", "E", "I", "O", "U"

v = v + 1

CASE ELSE

PRINT m$;

END SELECT

NEXT

END SUB

 

FUNCTION vowel$ (w$)

FOR x = 1 TO LEN(w$)

m$ = UCASE$(MID$(w$, x, 1))

SELECT CASE m$

CASE "A", "E", "I", "O", "U"

v$ = v$ + m$

END SELECT

NEXT x

vowel$ = v$

END FUNCTION

 

13. WAP to input any string and count total number of vowel letters by using FUNCTION and count total consonant letters  by using SUB procedure.

DECLARE FUNCTION vowel (w$)

DECLARE SUB cons (w$)

CLS

INPUT "Enter any string"; w$

PRINT "Total vowel letters"; vowel(w$)

CALL cons(w$)

END

 

SUB cons (w$)

FOR x = 1 TO LEN(w$)

m$ = UCASE$(MID$(w$, x, 1))

SELECT CASE m$

CASE "A", "E", "I", "O", "U"

v = v + 1

CASE ELSE

c = c + 1

END SELECT

NEXT

PRINT "Total consonant letters"; c

END SUB

 

FUNCTION vowel (w$)

FOR x = 1 TO LEN(w$)

m$ = UCASE$(MID$(w$, x, 1))

SELECT CASE m$

CASE "A", "E", "I", "O", "U"

v$ = v$ + m$

END SELECT

NEXT x

vowel = LEN(v$)

END FUNCTION

 

14. WAP to calculate the sum of digit by using SUB procedure and display input digit in reverse order by using FUNCTION procedure.

DECLARE SUB sum (n)

DECLARE FUNCTION rev (n)

CLS

INPUT "Enter any number"; n

CALL sum(n)

PRINT rev(n)

END

 

FUNCTION rev (n)

s = 0

WHILE n <> 0

r = n MOD 10

s = s * 10 + r

n = n \ 10

WEND

rev = s

END FUNCTION

 

SUB sum (n)

WHILE n <> 0

r = n MOD 10

s = s + r

n = n \ 10

WEND

PRINT "Sum of digit="; s

END SUB

 

15)       Write a program in QBASIC that will asks the user to input length, breadth and height. Create a user defined function to calculate surface area of four walls and write sub program to calculate surface area of box. [Hint: surface area of for walls=2H(L+B), surface area of box=lh+bh+lb]

DECLARE FUNCTION wall (l, b, h)

DECLARE SUB box (l, b, h)

CLS

INPUT "Enter length, breadth and height="; l, b, h

PRINT "Surface area of wall="; wall(l, b, h)

CALL box(l, b, h)

END

 

SUB box (l, b, h)

area = l * h + b * h + l * b

PRINT "Surface area of box"; area

END SUB

 

FUNCTION wall (l, b, h)

wall = 2 * h * (l + b)

END FUNCTION

 

16) Write a program to define a function procedure to display area of sphere and sub procedure to display volume of sphere where user has to input the required data in the main module. [Hint: Area of sphere: 4*PI*R^2, Volume- V =4/3 * π * r3]

DECLARE FUNCTION area (r)

DECLARE SUB vol (r)

CLS

INPUT "Enter radius"; r

PRINT "Area of sphere"; area(r)

CALL vol(r)

END

 

FUNCTION area (r)

area = 4 * 22 / 7 * r ^ 2

END FUNCTION

 

SUB vol (r)

v = 4 / 3 * 22 / 7 * r ^ 3

PRINT "Volume of sphere"; v

END SUB

 

17) Write a program in QBasic that ask the radius of a circle to calculate its area and circumference. Create a user-defined function to calculate area and a sub-program to calculate circumference. [Hints: a=Ï€r2, C=2Ï€r]

DECLARE FUNCTION area (r)

DECLARE SUB cir (r)

CLS

INPUT "Enter radius: "; r

PRINT "Area: "; area(r)

CALL cir(r)

END

 

FUNCTION area (r)

area = 3.14 * r ^ 2

END FUNCTION

 

SUB cir (r)

c = 2 * 3.14 * r

PRINT "Circumference: "; c

END SUB

 

18) SEE 2079 (2023)

Write a program in QBasic that ask the radius of a circle to calculate its area and circumference. Create a user-defined function to calculate area and a sub-program to calculate circumference. [Hints: a=Ï€r2, C=2Ï€r] 4

DECLARE FUNCTION area (r)

DECLARE SUB cir (r)

CLS

INPUT "Enter radius: "; r

PRINT "Area: "; area(r)

CALL cir(r)

END

 

FUNCTION area (r)

area = 3.14 * r ^ 2

END FUNCTION

 

SUB cir (r)

c = 2 * 3.14 * r

PRINT "Circumference: "; c

END SUB

 

19)   SEE Grade Promotion Exam 2079(2023)

Write a program in QBASIC that asks length and breadth of a room and calculate its area and perimeter. Create a user-define FUNCTION to calculate area and SUB program to calculate perimeter. [Hint: A=L × B, P=(L+B)]

DECLARE FUNCTION area(L,B)

DECLARE SUB peri(L,B)

CLS

INPUT "Enter length:";l

INPUT "Enter breadth:";b

a=area(L,B)

PRINT "Area of a room:";a

END

 

FUNCTION area(L,B)

area=l*b

END FUNCTION

 

SUB area(L,B)

p=2*(l+b)

PRINT "Perimeter of rectangle:";p

END SUB

 

20)  Npabson Pre-board Exam 2080

Write a program in QBASIC to find out the sum of three numbers using the SUB procedure and the average of three numbers using the FUNCTION procedure.

DECLARE SUB sum (a, b, c)
DECLARE FUNCTION average (a, b, c)
CLS
INPUT "Enter three numbers: "; a, b, c
CALL sum(a, b, c)
PRINT average(a, b, c)
END

FUNCTION average (a, b, c)
average = (a + b + c) / 3
END FUNCTION

SUB sum (a, b, c)
s = a + b + c
PRINT "sum"; s
END SUB

 

21)  Pabson  Pre-board Exam 2080

Write a program in QBASIC to input a radius, and create a user-defined function to calculate the volume of the hemisphere and total surface area (TSA) of the sphere using the SUB procedure.    DECLARE FUNCTION volume (r)

DECLARE SUB tsa (r)

CLS

INPUT "Enter radius:"; r

PRINT volume(r)

CALL tsa(r)

END

SUB tsa (r)

t = 4 * 22 / 7 * r ^ 2

PRINT "Total surface area: "; t

END SUB

FUNCTION volume (r)

volume = 2 / 3 * 22 / 7 * r ^ 3

END FUNCTION

 

 

Writing a Program in QBASIC using File Handling

(It carries 4 marks)

 

1) SLC 2063

Write a program to store the book's name, writers name and the price of the book in a sequential data file “STORE.DAT”. The program provides the facility to enter more records as long as the user wants.

OPEN “STORE.DAT” FOR OUTPUT AS #2

TOP:

INPUT “Enter book’s name=”;b$

INPUT “Enter Writer’s name=”;w$

INPUT “Enter price of book=”;p

WRITE #2, b$, w$, p

INPUT “Do you want to add more records (Y/N)”;Ans$

IF Ans$=”Y” or Ans$=”y” THEN GOTO top

CLOSE #2

END

 

2) SLC 2064

Write a program in QBASIC to open a sequential data file “WMP.DAT” which contains the employee records, name, address and phone number and display all the records as well as total number of records stored in the file.

OPEN “EMP.DAT” FOR INPUT AS # 1

CLS

P=0

PRINT "Name", "Address", "Phone"

WHILE NOT EOF(1)

INPUT #1, n$, a$, p$

PRINT n$, a$, p$

P=p+1

WEND

PRINT “Total number of records=”;p

CLOSE #1

END

3) Specification Grid 2065

Create a sequential data file "STD.DAT" to store name and marks obtained in Engish, Maths and Science subjects for few students.

OPEN "STD.DAT" FOR OUTPUT AS #2

Top:

CLS

INPUT "Enter name=";n$

INPUT "Enter marks of English=";e

INPUT "Enter marks of Maths=";m

INPUT "Enter marks of Science=";s

WRITE #2, n$, e,m,s

INPUT "Do you want to continue(Y/N)?";Ans$

IF Ans$="y" OR Ans$="Y" THEN GOTO top

CLOSE #2

END

 

4) SLC 2065

Write a program to store records regarding the information of book number, book's name writer's name in a sequential data file called "Library.dat".

OPEN "Library.dat" FOR OUTPUT AS #1

Avn:

INPUT "Enter book number=";n

INPUT "Enter books name=";b$

INPUT "Enter authors name=";a$

WRITE #1,n,b$,a$

INPUT "Store more records?";Ans$

IF Ans$="Y" OR Ans$="y" THEN goto avn

CLOSE #1

END

 

5) SLC supplementary 2065

A sequential data file "MARKS.DAT" contains Roll.no, Name, English, Nepali and Maths fields. Write a program to display all the contents of the data file.

OPEN "MARKS.DAT" FOR INPUT AS #1

CLS

PRINT "Roll no", "Name", "English", "Nepali", "Maths"

DO WHILE NOT EOF(1)

INPUT #1, r, n$, e, n, m

PRINT r, n$, e,n,m

LOOP

CLOSE #1

END

 

6) SLC 2066

WAP to create a sequential data file “employee.dat” to store employee’s name, address, age, gender and salary.

OPEN “employee.dat” FOR OUTPUT AS # 1

DO

INPUT “Enter name”;name$

INPUT “Enter address=”;add$

INPUT “Enter age=”;age

INPUT “Enter gender=”;g$

INPUT “Enter salary=”;sal

WRITE #!, name$, add$, age, g$, sal

INPUT “Do you want to continue..?”;Ans$

LOOP WHILE UCASE$(Ans$) =”y”

CLOSE #!

END

7) SLC supplementary 2066

A data file "LIB.TXT" consists of Book's name, Author's name and price of books. Write a program to count and display the total number of records present in the file.

OPEN "LIB.TXT" FOR INPUT AS #1

CLS

c=0

PRINT "Books name", "Authors name", "Price"

DO WHILE NOT EOF(1)

INPUT #1, b$,a$,p

c=c+1

LOOP

PRINT "Total number of records=";c

CLOSE #1

END

 

8) SLC 2067

A sequential data file "EMP.DAT" contains name, post and salary fields of information about employees. Write a program to display all the information of employees along with tax amount also. (tax is 15% of salary)

OPEN "EMP.DAT" FOR INPUT AS #1

CLS

PRINT "Name", "post", "salary", "tax"

DO WHILE NOT EOF(1)

INPUT #1, n$, p$, s

t = (s * 15) / 100

PRINT n$, p$, s, t

LOOP

CLOSE #1

END

 

 9) A sequential data file "information. dat" have contains name, address and phone no. WAP to display all the information whose address is Hasanpur or Taranagar.

CLS

OPEN "information.dat" FOR INPUT AS #1

DO WHILE NOT EOF(1)

INPUT #1,n$,a$,p

IF a$="Hasanpur" or a$="Taranagar" THEN

PRINT "Name=";n$

PRINT "Address=";a$

PRINT "Phone no=";p

ENDIF

LOOP

CLOSE #1

END

 

10) A data file named "salary.dat" contains name, designation and salary of employees. WAP to display all the employees record whose salary is between 10000 to 15000.

CLS

OPEN "salary.dat" FOR INPUT as #3

DO WHILE NOT EOF(3)

INPUT #3, n$,d$,s

IF s>=10000 and s<=15000 THEN

PRINT "Name="n$

PRINT "Designation=";d$

PRINT "Salary=";s

ENDIF

LOOP

CLOSE #3

END

11) A sequential data file "result.dat" contains name and marks secured by students in 3 subjects. Assuming that pass marks of each subjects is 40, write a program to count the number of passed students.

OPEN "result.dat" FOR INPUT AS #2

DO WHILE NOT EOF(2)

INPUT #2, n$,e,m,c

IF e>=40 and m>=40 and c>=40 THEN

p=p+1

ENDIF

LOOP

CLOSE #2

PRINT "Total number of passed students=";p

END

 

12)  WAP to create a data file "result.dat" and store name, class, roll noand any 3 subjects marks of five students.

CLS

OPEN "result.dat" FOR OUTPUT AS #2

FOR x= 1 to 5

INPUT "Enter name=";n$

INPUT "Enter Roll no.=";r

INPUT "Enter Class=";c$

INPUT "Enter Marks of English=";e

INPUT "Enter Marks of Maths=";m

INPUT "Enter Marks of Computer=";c

WRITE #2, n$,r,c$,e,m,c

NEXT x

CLOSE #2

END

13)    WAP to create a sequential file "store.dat" and store item code, item name, rate. The program should prompt the user to enter more data.

OPEN "store.dat" FOR OUTPUT AS #4

DO

INPUT "Enter item code=";c

INPUT "Enter Item name=";n$

INPUT "enter rate=";r

WRITE #4, c, n$,r

PRINT

INPUT "Do you want to conti……(y/n)";Ans$

LOOP WHILE UCASE$(Ans$)="Y"

CLOSE #4

END

 

14)    SLC 2068

      A sequential data file called ‘student.dat’ contains some records under the fields name, English, Nepali and Computer. Write a 3 program to add some more records in the same sequential data file.

OPEN “student.dat” FOR APPEND AS #1

TOP:

INPUT “Enter name=”;n$

INPUT “Enter English =”;e

INPUT “Enter Nepali=”;n

INPUT “Enter computer=”;c

WRITE #1, n$,E,N,C

INPUT “Do you want more data=”;Ans$

IF Ans$=”Y” OR Ans$= “y” THEN GOTO top

CLOSE #1

END

15) WAP to delete some records from data file "AVN.DAT" which has contents name, class, roll no, and address.

CLS

OPEN "avn.dat" FOR INPUT AS #1

OPEN "abc.dat" FOR OUTPUT AS #2

ab:

DO WHILE NOT EOF(1)

INPUT #1, r,n$,c$,a$

PRINT "Name=";n$

PRINT "Class=";c$

PRINT "Roll no=";r

PRINT "Address=";a$

INPUT "Do you want to delete this record (y/n)";y$

IF y$="Y" or y$="y" THEN GOTO ab

ELSE

WRITE #2, r, n$, c$, a$

GOTO ab

ENDIF

LOOP

CLOSE #1, #2

KILL "avn.dat"

NAME "abc.dat" AS "avn.dat"

END

 

16) Write a program to create a data file "record.dat" to add and display the records with the help of a menu base structure.

CLS

PRINT "MAIN MENU"

PRINT "1. Add records"

PRINT "2. Display records"

PRINT : PRINT

INPUT "Enter your choice: (1/2)";ch

SELECT CASE ch

CASE 1

CALL addrecord

CASE 2

CALL disprecord

END SELECT

END

SUB addrecord

CLS

OPEN "record.dat" FOR APPEND AS #1

DO

INPUT "Enter name=";n$

INPUT "Enter class=";c$

INPUT "Enter Roll no=";r

WRITE #1,n$,c$,r

INPUT "Do you need more records to add=";Ans$

LOOP WHILE UCASE$(Ans$)="Y"

CLOSE #1

END SUB

SUB disprecord

CLS

OPEN "record.dat" FOR INPUT AS # 1

PRINT "Students Name","Class", "Roll no"

DO WHILE NOT EOF(1)

INPUT #1,n$,c$,r

PRINT n$,c$,r

LOOP

CLOSE #1

END SUB

17)    A sequential data file “STUDENT.DAT” contains the details of students such as Name, roll no, class, joining date etc. WAP to update the details of the data file “student.dat”.

CLS

OPEN “student.dat” FOR INPUT AS#1

OPEN “temp.dat” FOR OUTPUT AS #2

WHILE NOT EOF(1)

INPUT #1, name$, roll, class, date$

PRINT:PRINT

PRINT “Name of the student=”;name$

PRINT “Roll number”;roll

PRINT “Class=”;class

PRINT “Joining date=”;date$

PRINT:PRINT

PRINT “Do you want to Update this record(Y/N)”

INPUT ch$

IF ch$=”Y” OR ch$=”y” THEN

INPUT “New name=”;name$

INPUT “New roll number=”;roll

INPUT “New class=”;class

INPUT New date=”;date$

ENDIF

WRITE #2, name$, roll, class, date$

WEND

CLOSE #1, #2

KILL “student.dat”

NAME “temp.dat” AS “student.dat”

END

 

18) A sequential data file “information.dat” contains name, address and phone number of the students. WAP to enter a telephone number from the keyboard, match the telephone number with the telephone number stored in the file. If the telephone number matched then display “Record found” otherwise display “Record not found”

OPEN “information.dat” FOR INPUT AS#1

CLS

INPUT “Enter telephone number=”;tel$

WHILE NOT EOF(1)

INPUT #1, n$, a$, ph$

IF(ph$=tel$) THEN

PRINT “Record found”

ELSE

PRINT “Record not found”

ENDIF

PRINT “Name=”;n$

PRINT “Address=”;a$

PRINT “Telephone number”;ph$

WEND

CLOSE #!

END

 

19)    SLC 2069

Write a program to create a data file ‘teldir.dat’ to store Name, Address and Telephone number of employee according to the need of the user.

            OPEN “teldir.dat” FOR OUTPUT AS #1

            DO

            INPUT “Enter Name:”n$

            INPUT “Enter address:”;a$

            INPUT “Enter telephone no:”;t$

            WRITE #1, n$,a$,t$

            INPUT “Do you want to add more records (Y/N)?”;ch$

            LOOP WHILE UCASE$(ch$)= “Y”

            CLOSE #!

            END

 

20)    SLC 2070

A sequential data file called “marks.dat” contains name, English, Nepali, Math's and Science fields. Write a program to display all the contents of that data file.     

            OPEN “marks.dat” FOR INPUT AS #1

            CLS

            PRINT “Name”, “English”, “Maths”, “Science”, “Nepali”

            WHILE NOT EOF(1)

            INPUT #1, n$, eng, math, sci, nep

            PRINT n$, eng, math, sci, nep

            WEND

            CLOSE #1

            END

21)    SLC 2067 Supp.

A sequential data file called “Marks.dat” contains Roll no, Name, English, Nepali, and Maths fields. Write a program to display all the contents of the data file.

            OPEN “marks.dat” FOR INPUT AS #1

            CLS

            PRINT “Roll no”,“Name”, “English”, “Maths”, “Science”, “Nepali”

            DO WHILE NOT EOF(1)

            INPUT #1, r, n$, eng, math, sci, nep

            PRINT r, n$, eng, math, sci, nep

            LOOP

            CLOSE #1

            END

 

22)    SLC 2068 Supp.

WAP to view those records from “employee.dat” sequential data file having employee’s name, department, appointment data and salary whose salary is more than Rs 5000.

OPEN “employee.dat” FOR INPUT AS #2

CLS

WHILE NOT EOF(2)

INPUT #2, n$,d$,a$,s

IF s>=5000 THEN PRINT n$,d$,a$,s

WEND

CLOSE #2

END

 

23)    SLC 2069 Supp.

A sequential data file “staff.dat” contains the name, address, post and salary of employees. Write a program to read and display all the records in the above data file.

OPEN “staff.dat” FOR INPUT AS #1

CLS

PRINT “Name”, “Address”, “Post”, “Salary”

DO WHILE NOT EOF(1)

INPUT #1, n$,a$,p$,s

PRINT n$,a$,p$,s

LOOP

CLOSE #1

END

 

24)    SLC 2071

A data file “salary.dat” contains the information of employee regarding their name, post and salary. Write a program to display all the information of employee whose salasy is greater than 15000 and less than 40000

OPEN “salary.dat” FOR INPUT AS #1

CLS

DO WHILE NOT EOF(1)

INPUT #1 n$,p$,sa

IF sa>15000 AND sa<40000 THEN

PRINT “Name”;n$

PRINT “Post”;p$

PRINT “Salary”;sa

ENDIF

LOOP

CLOSE #1

END

25) SLC 2070 Supp.

      A sequential data file “record.dat” has records with field name, address, age and salary. Write a program to display only those records whose age is greater than 26.

OPEN "record.dat" FOR INPUT AS #1

PRINT "Name", "Address", "Age", "Salary"

DO WHILE NOT EOF(1)

INPUT #1, n$, a$,age, sal

IF age>26 THEN PRINT n$,a$,age,sal

LOOP

CLOSE #1

END

 

26) A sequential data file “Employee.rec” consists of numerous records of employees of a company on the following fields: employee’s name, post, salary and status (i.e. permanent or temporary) Write a program to read records of the “Employee.rec” file and display the records of permanent employees whose post is manager.

 OPEN “Employee.rec” FOR INPUT AS #1

CLS

WHILE NOT EOF(1)

INPUT #1, N$, P$, S, S$

IF UCASE$(P$)= “MANAGER” AND UCASE$(S$)= “PERMANENT” THEN PRINT N$, P$, S, S$

WEND

CLOSE #1

END

27) Data file named “RECORD.DAT” contains name, age and salary for ‘n’ number of persons. Write a program to input a name to search data from data file. If the data is not found, then display the message “Data not found in the list.”

 OPEN “RECORD.DAT” FOR INPUT AS #1

CLS

INPUT “Enter name to search data”; S$

FLAG=0

WHILE NOT EOF(1)

INPUT #1, N$, A, S

IF UCASE$(S$)=UCASE$(N$) THEN

PRINT N$, A, S

FLAG=1

END IF

WEND

IF FLAG=0 THEN PRINT “DATA NOT FOUND”

CLOSE #1

END

 

28)    SEE 2072

A sequential data file called “Marks.dat” contains NAME, AGE, CITY, and TELEPHONE fields. Write a program to display all the contents of the data file.

OPEN “Marks.dat” FOR INPUT AS #1

CLS

DO WHILE NOT EOF(1)

INPUT #1, N$, A, C$, T#

PRINT N$, A, C$, T#

LOOP

CLOSE #1

END

 

29)    SEE 2073

Create a data file to store the records of few employees having Name, Address, Post, Gender and Salary fields.

OPEN “std.rec” FOR OUTPUT AS #1

DO

CLS

INPUT “Enter Name”; N$

INPUT “Enter Address”; A$

INPUT “Enter Post”; P$

INPUT “Enter gender”; G$

INPUT “Enter Salary”; S

WRITE #1, N$, A$, P$, G$, S

INPUT “Do you want to continue”; CH$

LOOP WHILE UCASE$(CH$)=”Y”

CLOSE #1

END

 

30) SEE 2073 Supp.

     A sequential data file called "ADDRESS.DAT" contains NAME, AGE, CITY and TELEPHONE fields. Write a program to display all the contents of the data file.

OPEN "ADDRESS.DAT" FOR INPUT AS #1

DO WHILE NOT EOF(1)

INPUT #1, n$,a,c$,t$

PRINT n$,a,c$,t$

LOOP

CLOSE #1

END

 

31. SEE 2074

Write a program to store Roll no., Name, Class and Address of any five students.

OPEN "Student.dat" FOR OUTPUT AS #1

FOR I = 1 TO 5

INPUT "Enter Roll No.", r

INPUT "Enter Name", n$

INPUT "Enter Class", c

INPUT "Enter Address", a$

WRITE #1, r, n$, c, a$

NEXT I

CLOSE #1

END

 

32. SEE 2075

     A data file “STAFF.dat” has stored records of few employees with EMPID, First name, Last name, post and salary. Write a program to display all the records of the employees whose salary is more than 40,000.

OPEN “SALARY.dat” FOR INPUT AS #1

CLS

WHILE NOT EOF(1)

INPUT #1, A, B$, C$, D$, E

IF E > 40000 THEN PRINT A, B$, C$, D$, E

WEND

CLOSE #1

END

33. SEE 2075(state 2)

      Write a program to create a sequential data file “salary.data” to store programmer’s Name, salary and post according to the need of the user.

OPEN “SALARY.dat” FOR OUTPUT AS #1

DO

CLS

INPUT “Enter Name”; N$

INPUT “Enter salary”; S

INPUT “Enter Post”; P$

WRITE #1, N$, S, P$

INPUT “Do you want to continue(Y/N)”; CH$

LOOP WHILE UCASE$(CH$)=”Y”

CLOSE #1

END

 

34. SEE 2079

A sequential data file called "record.dat" has stored data under the field heading:  Roll no, name, gender, English, Nepali, Math's, and Computer. Write a program to display all the information of those students whose marks in English is more than 40. 

OPEN "record.dat" FOR INPUT AS #1
DO WHILE NOT EOF(1)
INPUT #1, rn, n$, g$, eng, nep, math, comp
IF eng > 40 THEN PRINT rn, n$, g$, eng, nep, math, comp
LOOP
CLOSE #1
END

35) SEE 2078 Grade Promotion

Student name, class, section, and address are stored in a data file called "student.dat". Write a program to print all the records of students.

OPEN "student,dat" FOR INPUT AS #5

CLS

DO WHILE NOT EOF(5)

INPUT #5, name$,cl,s$,add$

PRINT name$,cl,s$,add$

LOOP

CLOSE #5

END

 

36) SEE 2078

Write a program to create a sequential data file “salary.dat” to store programmer’s name, salary and post according to the need of the user.      

OPEN “salary.dat” FOR OUTPUT AS #1

top:

INPUT “Enter programmers name”;n$

INPUT “Enter salary”;s

INPUT “Enter post”;p$

INPUT “Do you need more records”;ch$

IF UCASE$(ch$)=”Y” then GOTO top

CLOSE #1

END

 

37) A sequential data file "employee.dat" contains name, address, age and salary of employee. Write a program to display all the information whose address is "Kathmandu" and salary is greater than 50000.

OPEN "employee.dat" FOR INPUT AS #2
CLS
DO WHILE NOT EOF(2)
INPUT #1,name$, add$, age, sal
IF UCASE$(add$)="KATHMANDU" AND s > 50000 THEN
PRINT name$, add$, age, sal
ENDIF
WEND
CLOSE #1
END

 

38) SEE grade promotion 2079

Student name, class, section and address are stored in a data file called "student.dat". Write a program to print all the records of students.

OPEN "student.dat" FOR INPUT AS #1

CLS

DO WHILE NOT EOF(1)

INPUT #1, n$,c,s$,a$

PRINT n$,c,s$,a$

LOOP

CLOSE #1

END

 

39) Npabson SEE Pre-Qualifying exam-2080

A sequential data file, "record.dat" contains several records with data items name, address, age, and phone number. Write a program to display all the records of students whose age is greater than or equal to 18. 

Ans:
OPEN "record.dat" FOR INPUT AS #1
CLS
DO WHILE NOT EOF(1)
INPUT 31, n$,a$,age,ph
IF age>=18 THEN PRINT n$, a$, age, ph
LOOP
CLOSE #1
END

40. Pabson SEE pre-board examination 2080

A sequential data file "record.dat" contains the name, address, salary of employee, and display the records of those whose salary is more than 37000 and whose name ends with "DHA"   

CLS

OPEN "record.dat" for INPUT AS #1

DO WHILE NOT EOF(1)

INPUT #1, n$,a$,s

IF s>37000 AND RIGHT$(a$,3)="DHA" THEN

PRINT "Name:";n$

PRINT "Address: ";a$

PRINT "Salary:";s

ENDIF

LOOP

CLOSE #1

END                       

 

Writing a Program in 'C using Conditional statements

(It carries 4 marks)

 1. (Specification Grid 2077)

To check whether input number is odd or even.

#include<stdio.h>

int main()

{

          int n;

          printf("Enter any number=");

          scanf("%d",&n);

          if(n%2==0)

          printf("The entered number is even");

          else

          printf("The entered number is odd");

          return 0;

}

 

2.  (SEE 2078)  (Npabson pre-board exam 2080)

To check whether input number is positive, negative or neutral.

#include<stdio.h>

int main()

{

int n;

printf("Enter any number\n");

scanf("%d",&n);

if(n>0)

printf("\Positive no");

if(n<0)

printf("\n Negative no");

if(n==0)

printf("\n Netural no");

return 0;

}

 

3. To display the greatest number among the input three numbers.

#include<stdio.h>

    main()

    {

      int num1,num2,num3;

      printf("Enter three numbers\n");

      scanf("%d%d%d",&num1,&num2,&num3);

      if(num1>num2&&num1>num3)

          printf("%d is Grestest",num1);

      else if(num2>num1&&num2>num3)

          printf("%d is Greatest",num2);

      else

          printf("%d is Greatest",num3);

    }

 

4. To input any number and check whether the entered number is divisible by 5 but not by 11.

#include<stdio.h>

int main()

{

int a;

printf("Enter an integar=")

scan("%d",&a);

if(a%5==0&&a%11!=0)

printf("Divisible by 5 but not by 11");

else

print("Not required number")'

return 0;

}

 

 

5. To display the name of day on the basis of entered number 1 to 7. For example, 1 for Sunday.

#include<stdio.h>

int main()

{

int day;

printf (“Enter the number :”);

scanf (“%d”, &day);

switch (day)

{

          case 1:

                   printf (“Sunday\n”);

                    break;

          case 2:

                   printf (“Monday\n”);break;

          case 3:

                   printf (“Tuesday\n”);

                   break;

          case 4:

                   printf (“Wednesday\n”);

                   break;

          case 5:

                   printf (“Thursday\n”);

                   break;

          case 6:

                   printf (“Friday\n”);

                   break;

          case 7:

                   printf (“Saturday\n”);break;

          default:

                   printf (“Entered not match”);

}

return 0;

}

 

6. To input any two numbers and display their addition, subtraction, multiplication and division with the help of menu structure.

#include<stdio.h>

int main()

{

int a,b,ch,s;

printf("\n Enter any two numbers=");

scanf("%d,%d",&a,&b);

printf("\n 1. Addition");

printf("\n 2. Subtraction");

printf("\n 3. Multiplication");

printf("\n 4. Division");

printf("\n Enter your choice (1-4)");

scanf("%d",&ch);

switch(ch)

{

case 1:

s=a+b;

printf("\n Sum of two numbers=%d",s);

break;

case 2:

s=a-b;

printf("\n The difference of two numbers = %d",s);

break;

case 3:

s=a*b;

printf("\n The multiplication of two numbers=%d",s);

break;

case 4:

s=a/b;

printf("\n The division of two numbers=%d",s);

break;

default:

printf("\n Invalid choice try again");

}

return 0;

}

 

7. To input cost of price(cp) and selling price(sp) and determine whether there is gain or loss.

#include<stdio.h>

#include<conio.h>

void main()

{

int CP,SP,loss,gain;

print("Enter value of CP and SP;"):

scanf("%d%d,&CP,&SP);

if(SP>CP)

{

gain=SP-CP;

print("Gain=Rs%d",gain);

}

else

{

loss=CP-SP;

printf("Loss=Rs%d",loss);

}

getch();

}

 

8. To find the commission amount on the basis of sales amount as the following conditions:

          Sales amount (Rs)                    Commission

                   0 -1000                                         5%

                   1001-2000                                    10%

                   >2000                                           12%

#include<stdio.h>

int main()

{

int sm,r,cm;

printf("\Enter sales amount\n");

scanf("%d",&sm);

if(sm>2000)

r=12;

else if(sm<2000 && sm>1000)

r=10;

else

r=5;

cm=(sm*r)/100;

printf("commission amount=%d",cm);

return 0;

}

 

9.WAP to check whether input number is prefect square or not

#include<stdio.h>

#include<math.h>

int main()

{

          int b,n;

          float a;

          printf("Enter any no");

          scanf("%d",&n);

          a=sqrt(n);

          b=a;

          if (a==b)

          printf("prefect square");

          else

          printf("not prefect square");

          return 0;

}

 

10 WAP to display the smallest number among the input three numbers.

#include<stdio.h>

   int main()

    {

      int num1,num2,num3;

      printf("Enter three numbers\n");

      scanf("%d%d%d",&num1,&num2,&num3);

      if(num1<num2&&num1<num3)

          printf("%d is smallest",num1);

      else if(num2<num1&&num2<num3)

          printf("%d is smallest",num2);

      else

          printf("%d is smallest",num3);

      return 0;

    }

 

11. WAP to input any three numbers and display the middle number among them.

#include<stdio.h>

   int main()

    {

      int num1,num2,num3;

      printf("Enter three numbers\n");

      scanf("%d%d%d",&num1,&num2,&num3);

      if(num1>num2 && num1<num3||num1<num2 && num1>num3)

          printf("%d is middle",num1);

      else if(num2>num1&&num2<num3||num2<num1&&num2>num3)

          printf("%d is middle",num2);

      else

          printf("%d is middle",num3);

      return 0;

    }

 

12. WAP to input percentage and display the result. (Assume pass percentage is 40 )

#include<stdio.h>

int main()

{

 float per;

printf(" Enter your percentage ");

scanf("%f",&per);

if(per>=40)

printf("Pass");

else

printf("Fail");

return 0;

}

 

13. To input a number and then print whether number is fully divisible by 5 or not.

#include<stdio.h>

int main()

{

int n,r;

printf(" Enter any number ");

scanf("%d",&n);

r=n%5;

if (r==0)

 printf("%d is divisible by 5",n);

else

printf("%d is not divisible by 5",n);

return 0;

}

 

14. WAP to input age display whether you can vote or not. (Assume 18 is the age for casting vote)

#include<stdio.h>

    int main()

    {

      int a;

      printf("enter age");

      scanf("%d",&a);

      if(a>=18)

      printf("You can vote");

      else

      printf("you cant vote");

return 0;

  }

15. WAP to display the greatest number among input two numbers.

#include<stdio.h>

int main()

{

            int a,b;

            printf("Enter two numbers\n");

            scanf("%d%d",&a,&b);

            if(a>b)

            printf("Greatest no=%d",a);

            else

            printf("Greatest no=%d",b);

            return 0;

}

 

16. WAP to check whether input year is leap year or not.

#include<stdio.h>

int main()

{

           int y;

           printf("Enter the year\n");

           scanf("%d",&y);

           if((y%2==0)&&(y%100!=0)||(y%400==0))

           printf("%d is leap year",y);

           else

           printf("%d is not leap year",y);

           return 0;

}

17. To input a number and check whether the number is full divisible by 5 or not.

#include<stdio.h>

int main()

{

int num;

printf("Enter any number");

scanf("%d",&num);

if(num%5==0)

printf("Fully divisible by 5);

else

printf("Not fully divisible by 5);

return 0;

}

 

 

18. To input a number and then print whether number is fully divisible by 2 and 3 or not.

#include<stdio.h>

int main()

{

int n,r1,r2;

printf("Enter a number : ");

scanf("%d",&n);

r1=n%2;

r2=n%3;

if(r1==0&&r2==0)

printf(" %d is divisible by 2 and 3 ",n);

else

printf(" %d is not divisible by 2 and 3 ",n);

return 0;

}

 

19.  (SEE 2079)

Write a program in C-language that asks any two numbers and displays the greatest among them.

#include<stdio.h>

int main()

{

            int a,b;

            printf("Enter any two numbers: ");

            scanf("%d%d",&a,&b);

            if(a>b)

            printf("greatest no: %d",a);

            else

            printf("Greaest no: %d",b);

            return 0;

}

 

20. PABSON SEE PRE-QUALIFING EXAMINATION-2080

 Write a 'C' program to input a character and check whether it is a vowel or consonant.

#include<stdio.h>

int main()

{

                char c;

                printf("Enter any character");

                scanf("%c",&c);

                if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')

                printf("vowel character");

                else

                printf("consonent character");

                return 0;

}

21. To input any three subject marks and display the result. (Assume pass marks is 35 in each subject)

#include<stdio.h>

int main()

{

            int x,y,z;

            printf("Enter three subject marks\n");

            scanf("%d%d%d",&x,&y,&z);

            if(x>=35 && y>=35 && z>=35)

            printf("Pass");

            else

            printf("Fail");

            return 0;

}

22. Write a c program to input any number and print the year, months, and days in the appropriate format.

#include <stdio.h>

int main() {

    int totaldays, years, months, days;

 

    // Asking for input

    printf("Enter the number of days: ");

    scanf("%d", &totaldays);

     // Calculating years, months, and days

    years = totaldays / 360;                    // A year has 360 days

    months = (totaldays % 360) / 30;    // A month has 30 days

    days = (totaldays % 360) % 30;      // Remaining days

     // Printing the result

    printf("%d days is equivalent to %d year(s), %d month(s), and %d day(s).\n", totaldays, years, months, days);

    return 0;

}


Writing a Program in 'C using Looping

(It carries 4 marks)

1. (Specification Grid 2077)

WAP to print the series with their sum. 1,2,3,4,….., up to 10th  terms.

#include<stdio.h>

int main()

{

            int x,sum=0;

            for(x=1;x<=10;x++)

            {

                        printf("%d\n",x);

                        sum=sum+x;

            }

            printf("sum=%d",sum);

            return 0;

}

 

2.  (SEE 2078)

To display the first 10 odd numbers.

#include<stdio.h>

int main()

{

          int x,a=1;

          for(x=1;x<=10;x++)

          {

            printf("%d\t",a);

            a=a+2;

          }

          return 0;

}

 

3. (SEE Promotion Grade Exam 2078)

To display the series 2,4,6,8 upto 10th term.

#include<stdio.h>

int main()

{

          int x,a=2;

          for(x=1;x<=10;x++)

          {

                   printf("%d\t",a);

                   a=a+2;

          }

         return 0;

}

 

4. (SEE 2079)

 Write a program in C-language to display the series with their sum.  1,2,3,4,.....up to 10th term.
#include<stdio.h>

int main()

{

            int x, sum=0;

            for(x=1;x<=10;x++)

            {

                        printf("%d\t",x);

                        sum=sum+x;

            }

            printf("\nsum=%d",sum);

         return 0;

}

 

5. Pabson Pre-Board exam 2079

Write a program in ‘C’ language to display first 10 natural numbers.         

Ans:

#include <stdio.h>

int main() 

{

   int i;

   for (i = 1; i <= 10; i++) {

      printf("%d ", i);

   }

      return 0;

}

 

6. To display the first 10 natural numbers (1 to 10) horizontally.

#include< stdio.h>

int main()

{

int x;

for(x=1;x<=10;x++)

{

printf("%d\t",x);

}

return 0;

}


7. To display the numbers 10 to 1 reverse order in vertical form.

#include< stdio.h>

int main()

{

int x;

for(x=1;x<=10;x++)

{

printf("%d\n",x);

}

return 0;

}

 

8. To display the numeric series 1 3 5 7 9......49.

#include<stdio.h>

int main()

{

int x=1;

do

{

printf("%d\n",x);

x=x+2;

}while(x<=50);

return 0;

}


9. To display the sum of first 10 natural numbers.

#include<stdio.h>

#include<conio.h>

void main()

{

int x=1,s=0;

while(x<=10)

{

s=s+x;

x=x+1;

}

printf("sum=%d",s);

getch();

}

 

10. Write a program in C language to display the first 10 odd numbers.

#include<stdio.h>

int main()

{

            int x,a=1;

            for(x=1;x<=10;x++)

            {

                        printf("%d\t",a);

                        a=a+2;

            }

       return 0;

}

 

11, To display the series of even number upto 100.

#include<stdio.h>

int main()

{

int i;

printf("The series of even number is");

for(i=2;i<=100;i=i+2)

{

printf("%d\t",i);

}

return 0;

}

 

12. To display the series of number 4  16 36 64.......10th term.

 #include<stdio.h>

int main()

{

int i, a=2;

for(i=1;i<=10;i++)

{

printf("%d\t",a*a);

a=a+2;

}

return 0;

}


13. To input any number and display its multiplication table.

#include<stdio.h>

int main()

{

int i, n;

printf("Enter which number table\n");

scanf("%d",&n);

for(i=1;i<=10;i++)

{

printf("%d\n",n*i);

}

return 0

}

 

14. WAP to display Fibonacci series upto 10 terms

[ e.g. 1,1,2,3,5,8,13,21.......].

#include<stdio.h>

int main()

{

int a=1,b=1,i;

for(i=1;i<=5;i++)

{

printf("%d\t%d\t",a,b);

a=a+b ;

b=a+b;

}

return 0;

}


15.  To display the series 1   11   111   1111 11111.

#include<stdio.h>

int main()

{

int x=1,a=1;

while(x<=5)

{

printf("%d\t",a);

a=a*10+1;

x=x+1;

}

return 0;

}

 

16.  To display the series 22222  2222   222  22  2

#include<stdio.h>

int main()

{

int x=1; a=22222;

while(x<=5)

{

printf("%d\t",a);

a=(a-2)/10;

x=x+1;

}

return 0;

}


17. To display the series 5 10 15 20 ………50

#include<stdio.h>

int main()

{

          int x;

          for(x=5;x<=50;x=x+5)

          {

                   printf("%d\t",x);

          }

          return 0;

}

 

18. WAP to print the numbers from 1 to 100 using a while loop.

#include<stdio.h>

int main()

{

            int x=1;

            while(x<=100)

            {

                        printf("%d\t",x);

                        x=x+1;

            }

            return 0;

}

 

19. To display the first 20 even numbers.

#include<stdio.h>

int main()

{

          int x=1,a=2;

          while(x<=20)

          {

                   printf("%d\t",a);

                   a=a+2;

                   x=x+1;

          }

          return 0;

}


20. WAP to input any number and display its factorial number.

Note: A factorial number is the product of all the positive integers less than or equal to a given number. For example, 5 = 5 x 4 x 3 x 2 x 1 = 120.

#include<stdio.h>

int main()

{

    int number, i;

            long f = 1;

    printf("Enter a non-negative integer: ");

    scanf("%d", &number);

        for (i = 1; i <= number; i++) {

        f= f*i;

    }

    printf("The factorial of %d is %lld.\n", number, f);

    return 0;

}

 

21. WAP to check whether input number is prime or composite.

#include <stdio.h>

int main()

{

    int num, i, t=0;

    printf("Enter any number: \n");

    scanf("%d",&num);

    for(i=2;i<=num-1;i++)

    {

            if(num%i==0)

            t++;

    }

            if(t==0)

            printf("prime no");

            else

            printf("composite no");

}

 

22. WAP to input any digit and display its sum.

#include <stdio.h>

int main()

{

    int num, sum = 0, digit;

   

    printf("Enter a number: ");

    scanf("%d", &num);

        // Calculate the sum of the digits in the input number

    while (num > 0)

{

        digit = num % 10;

        sum= sum+digit;

        num=num/10;

    }

     // Display the result

    printf("The sum of the digits is %d.", sum);

     return 0;

}


23. WAP to find the reverse of an input digit.

#include<stdio.h>

int main()

{

            int num,r,s=0;

            printf("Enter any number ");

            scanf("%d",&num);

            while(num!=0)

            {

                        r=num%10;

                        s=s*10+r;

                        num=num/10;

            }

            printf("Reverse number = %d",s);

            return 0;

}

 

24) C program to display 100,98,94,88,80,..... up to 10th terms

#include <stdio.h>

int main()

{

    int i,b=100,c=2;

    for(i=0;i<10;i++)

    {

                        printf("%d\n",b);

        b=b-c;

        c=c+2;

    }  

    return 0;

}

 

25) C program to display 2,8,18,32,..... up to 10th terms

#include <stdio.h>

int main()

{

    int x,a;

   for(x=1;x<=10;x++)

    {

             a=x*x*2;

        printf("%d\n",a);

    }      

    return 0;

}

 

26) To display 1,2,4,8,16,..... up to 10th terms

#include <stdio.h>

int main()

{

   int x,a=1;

   for(x=0;x<10;x++)

    {

        printf("%d\n",a);

        a=a*2;

    }       

    return 0;

}

 

27) PABSON SEE PRE-QUALIFING EXAMINATION-2080
Write a program in 'C' language to input number and check whether it is a palindrome or not.

#include<stdio.h>

int main()

{

int n,r,t,a;

printf("Enter any number:");

scanf("%d",&n);

a=n;

while (n>0)

{

r=n%10;

t=t*10+r;

n=n/10;

}

if(a==t)

printf("number is palindrome");

else

printf("number is not palindorme");

return 0;

}

 

 You may also Read:

SUB procedure in QBASIC


 


No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages