Important Qbasic AND C program problems for grade 10

 SUB PROCEDURE

WAP to find input number is palindrome or not using sub procedure

DECLARE SUB PALIN (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL PALIN (N)
END

SUB PALIN (N)
A = N
S = 0
WHILE N < > 0
R = N MOD 10
S = S * 10 + R
N = N \ 10
WEND
IF A = S THEN
PRINT A; "IS PALINDROME"
ELSE
PRINT A; "IS NOT PALINDROME"
END IF
END SUB

WAP to find input word is palindrome or not
DECLARE SUB PALIN$(N$)
CLS
INPUT "ENTER ANY WORD";W$
CALL PALIN$(W$)
END

SUB PALIN$(N$)
FOR I = 1 TO LEN(N$)
a$=mid$(n$,I,1)+a$
NEXT I
IF (N$=A$) THEN
PRINT "GIVEN WORD IS PALINDROME"
ELSE
PRINT "GIVEN WORD IS NOT PALINDROME"
END IF
END SUB

WAP to find given number is Armstrong or not using sub procedure

DECLARE SUB ARM (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL ARM (N)
END

SUB ARM (N)
A = N
S = 0
WHILE N < > 0
R = N MOD 10
S = S  + R ^ 3
N = N \ 10
WEND
IF A = S THEN
PRINT A; "IS ARMSTRONG NUMBER"
ELSE
PRINT A; "IS NOT ARMSTRONG NUMBER"
END IF
END SUB

WAP using sub procedure to display non-Armstrong between 150 and 200


DECLARE SUB ARM 
CLS
CALL ARM 
END

SUB ARM ( )
FOR I= 150 TO 200
A = I
S = 0
WHILE A < > 0
R = N MOD 10
S = S  + R ^ 3
A = A \ 10
WEND
IF I = S THEN
PRINT I; "IS ARMSTRONG NUMBER"
END IF
NEXT I
END SUB


WAP using sub procedure to find distance travelled by a body(s=ut+1/2*a*t^2)

DECLARE SUB DISTNCE(U,T,A)
CLS
INPUT "ENTER INITIAL VELOCITY";U
INPUT "TIME INTERVAL";T
INPUT "ENTER ACCLERATION";A
CALL DISTANCE(U,T,A)
END

SUB DISTANCE(U,T,A)
S=U*T+1/2*(A*T^2)
PRINT "DISTANCE TRAVELLED IS";S
END SUB

WAP TO FIND SUM OF EVEN NUMBER FROM 6 TO 20 USING SUB PROCEDURE

DECLARE SUB SUM
CLS
CALL SUM
END

SUB SUM()
FOR I= 6 TO 20 STEP 2
SUM=SUM+I
NEXT I
PRINT "SUM OF EVEN NUMBER FROM 6 TO 20 IS";SUM
END SUB


OR 

SUB SUM()
FOR I= 6 TO 20
IF I MOD 2 =0 THEN
SUM = SUM +I
END IF
PRINT "SUM OF EVEN NUMBER FROM 6 TO 20 IS";SUM
END SUB

WAP to input 2 points (x1,y1) and (x2,y2) and find distance between them using sub procedure(use distance formula)

DECLARE SUB DISTANCE(X1,Y1,X2,Y2)
CLS
INPUT "ENTER (X1,Y1)";X1,Y1
INPUT "ENTER (X2,Y2)";X2,Y2
CALL DISTANCE(X1,Y1,X2,Y2)
END

SUB DISTANCE(X1,Y1,X2,Y2)
d= ((x2-x1)^2 + (y2-y1)^2)^(1/2)
PRINT "DISTANCE BETWEEN GIVEN POINTS IS";d
END SUB


FUNCTION PROCEDURE


WAP to check input number is divisible by 5 and 15 or not using function procedure

DECLARE FUNCTION CHECK(N)
CLS
INPUT "ENTER NUMBER TO CHECK NUMBER IS DIVISIBLE BY 5 AND 15 OR NOT";N
A= CHECK(N)
IF A=1
PRINT N; " IS DIVISIBLE BY 5 AND 15"
ELSE
PRINT N; " IS NOT DIVISIBLE BY 5 AND 15"
END IF
END

FUNCTION CHECK(N)
IF N MOD 5=0 AND N MOD 15=10 THEN
CHECK = 1
ELSE 
CHECK =0
END IF
END FUNCTION

WAP to find greatest number among 3 number using function procedure

DECLARE FUNCTION BIG(A,B,C)
CLS
INPUT "ENTER ANY 3 NUMBER ";A,B,C
PRINT "GREATEST NUMBER AMONG THE NUMBER YOU ENTER IS";BIG(A,B,C)
END

FUNCTION BIG(A,B,C)
IF(A>B AND A>C) THEN
BIG=A
ELSE IF (B>A AND B>C)
BIG=B
ELSE
BIG=C
END IF
END FUNCTION


WAP to find sum of first 50 odd number using function procedure

DECLARE FUNCTION SODD( )
CLS
PRINT "SUM OF FIRST ODD NUMBER IS";SODD( )
END

FUNCTION SODD( )
FOR I= 1 TO 99 STEP 2
SUM= SUM+I
NEXT I
SODD=SUM
END FUNCTION

WAP to find sum of cube of 2 number using function procedure

DECLARE FUNCTION CUBE(A,B)
CLS
INPUT "ENTER 2 NUMBER";A,B
PRINT "SUM OF CUBE OF 2 NUMBER IS";CUBE(A,B)
END

FUNCTION CUBE(A,B)
SUM=A^3+B^3
CUBE=SUM
END FUNCTION

FLIE HANDLING


WAP to update rate by increasing 20% from sequential data file "item.dat" that store item , name ,rate and quality.

CLS
Open "Item.dat" For Input As #1
Open "Temp.dat" For Output As #2
While not EOF(1)
Input#1,N$,q,r
Write#2,N$,q,r+(20/100)*r
wend
close
kill "Item.dat"
Name "Temp.dat" As "Item.dat" 
CLOSE #1,#2
End

WAP to store  teacher's Name ,address and mobile number of teachers in sequential data file "teacher.dat". Program should allow user to input and write data till user wish.
OPEN "TEACHER.DAT" FOR OUTPUT AS #1
SEE:
INPUT "ENTER NAME";N$
INPUT "ENTER ADDRESS";A$
INPUT "ENTER NUMBER";N
WRITE #1,N$,A$,N
INPUT "DO YOU WANT TO CONTINUE:::";Y$
IF UCASE$(Y$)="Y" THEN GOTO SEE
CLOSE #1
END





WAP to display all record whose salary is greater than 50000 of "staff.dat". File has data like Name, Gender, age and salary.
OPEN "STAFF.DAT" FOR INPUT AS #1
CLS
PRINT "NAME", "GENDER", "AGE" , "SALARY"
WHLIE NOT EOF(1)
INPUT #1,N$,G$,A,S
IF S>50000 THEN
PRINT N$,G$,A,S
END IF
WEND
CLOSE #1
END

C Programming


WAP to input 2 number and find greater number among 2 number
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("enter any 2 number');
scanf(""%d%d",&a,&b);
if(a>b)
{
printf("%d is greater than $b",a,b);
}
else
{
printf("%d is greater than %d",b,a);
}
getch();
}

WAP to print first 50 odd number

#include<stdio.h>
#include<conio.h>

void main()
{
int i;
printf("odd number from 1 to 50 are");
for(i=1;i<=50;i=i+2)
{
printf("%d",i);
}

WAP to input number and print weather the input number is even or odd using C program

#include<stdio.h>
#include<conio.h>
void main() 
{
int a;
printf("enter any number ");
scanf("%d",&a);
if(a % 2 = 0)
{
printf("%d is even number" , a);
}
else
{
printf("%d is odd number",b);
}
}

WAP using C program to generate following series
1
121
12321
1234321
1234321

#include<stdio.h>
#include<conio.h>

void main()
{
int i,a=1;
for(i=1;i<=5;i++)
{
printf("%d\n",a*a);
a=a*10+1;
}
}


WAP to input 2 points (x1,y1) and (x2,y2)  and find distance between them.
[hints: d= root((x2-x1)^2+(y2-y1)^2)]

#include<stdio.h>
#include<conio.h>
void main()
{
int x1,x2,y1,y2;
float d;
printf("Enter 1st point");
scanf("%d%d",&x1,&y1);
printf("Enter 2nd point");
scanf("%d%d",&x2,y2);
d=((x2-xx1)^2+(y2-y1)^2)^(1/2);
printf("distance between (%d,%d) and (%d,%d) is %f",x1,y1,x2,y2,d);
}

Comments