Showing posts with label Computer Science. Show all posts
Showing posts with label Computer Science. Show all posts

Friday, December 28, 2018

9. Write a program to count the number of words in a sentence.

CLS
INPUT "ENTER ANY STRING"; S$
WC = 1
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
IF B$ = " " THEN
WC = WC + 1
END IF
NEXT I
PRINT "TOTAL NO. OF WORDS= "; WC
END
Read more

11. Write a progra to find whether the supplied word is palindrome or not. A word is called palindrome, if it reads the same from both the sides. (e.g. MADAM)

CLS
 INPUT "Enter a word:"; w$
 FOR i = LEN(w$) TO 1 STEP -1
     m$ = MID$(w$, i, 1)
     rev$ = rev$ + m$
 NEXT i
 PRINT
 PRINT "The original word is "; w$
 PRINT "The reverse wod is "; rev$
 PRINT
 IF w$ = rev$ THEN
     PRINT "The given word is palindrome"
 ELSE
     PRINT "The given word is not palindrome"
 END IF
 END
Read more

Sunday, February 25, 2018

What is the output of the following program?

Soln:
Suruma n=2 ra c=1 xa
Ani while c<=10 bhaneko c chai 10 wa 10 bhanda kam huda samma loop bhairahanxa. Bhanepaxi looping sakkina c=11 hunuparxa.
Suruma "Print n" bhanya xa tesaile 2 print hunxa............(i)

tespaxi, n=n+c xa bhanepaxi n=2+1=3 hunebhayo
c=c+1 xa tesaile c=1+1=2 hune bhayo

(c=2) chai 11 bhanda kam xa tesaile feri looping hunxa
Wend le feri while ma pathauxa;
Ani print n xa bhanepaxi agi n=3 bhako thiyo tesaile second looping ma 3 print hunxa.....................(ii)
feri n=n+c xa, n=3+2=5 hunxa 
c=c+1 xa c=2+1=3 hunxa

(c=3) feri 11 bhanda kam bhayera feri looping hunxa
mathi n=5 bhako thiyo tesaile 5 print hunxa................(iii)
n=5+3=8 hunxa
c=3+1=4 hunxa

c feri 11 bhanda kam xa, feri looping hunxa
ani n=8 bhayekale 8 print hunxa...............(iv)
n=8+c=8+4=12 hunxa
c=c+1=4+1=5

c=5 xa ra yo feri while ma bhako condition satisfy garxa
yesari c=5 huda kheri 12 print hunxa...........(v)
c=6 huda kheri 17 print hunxa...........(vi)
c=7 huda kheri 23 print hunxa...........(vii)
c=8 huda kheri 30 print hunxa...........(viii)
c=9 huda kheri 38 print hunxa...........(ix)
c=10 ko condition pani satisfy hunxa ra 47 print hunxa........(x)
Aba c=c+1 bhayera c=11 hunxa ra condition satisfy gardaina ra looping stop hunxa
Ani output chai
2
3
5
8
12
17
23
30
38
47
Read more