0% found this document useful (0 votes)
6 views

Program Slices

Uploaded by

Minahil Ismail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Program Slices

Uploaded by

Minahil Ismail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

i.

Obtain slices separately on nw, nc, nl, inword, and c of the following word count
program.
[1.]#define YES 1
[2.]#define NO 0
[3.]main()
[4.]{
[5.]int c, nl, nw, nc, inword;
[6.]inword = NO;
[7.]nl = 0;
[8.]nw = 0;
[9.]nc = 0;
[10.] c = getchar();
[11.] while (c! = EOF) {
[12.] nc = nc + 1;
[13.] if (c == ′∖n′)
[14.] nl = nl + 1;
[15.] if (c == ′ ′||c == ′∖n′)||c == ′∖t′)
[16.] inword = NO;
[17.] else if (inword == NO) {
[18.] inword = YES;
[19.] nw = nw + 1;
[20.] }
[21.] c = getchar();
[22.] }
[23.] print f(“%d∖n”, nl);
[24.] print f(“%d∖n”, nw);
[25.] print f(“%d∖n”, nc);
[26.] }

nw slice
#define YES 1
#define NO 0

int c, nl, nw, nc, inword;


inword = NO;
nw = 0;
while (c != EOF) {
if (c == ' ' || c == '\n' || c == '\t')

Page 1 of 3
inword = NO;
else if (inword == NO) {
inword = YES;
nw = nw + 1;
}
c = getchar();
}
printf("%d\n", nw);

nc slice
int c, nc;
nc = 0;
while (c != EOF) {
nc = nc + 1;
}
printf("%d\n", nc);

nl slice
int c, nl;
nl = 0;
while (c != EOF) {
if (c == '\n')
nl = nl + 1;
c = getchar();
}
printf("%d\n", nl);

inword slice
#define YES 1
#define NO 0

int c, inword;
inword = NO;
while (c != EOF) {
if (c == ' ' || c == '\n' || c == '\t')
inword = NO;
else if (inword == NO)
inword = YES;
c = getchar();
}

Page 2 of 3
c slice
int c;
c = getchar();
while (c != EOF) {
c = getchar();
}

Page 3 of 3

You might also like