1638699417_Computer-Programming-Lab (2)
1638699417_Computer-Programming-Lab (2)
LAB MANUAL
ON
Institute Mission:
To produce quality engineers by providing state-of-the-art engineering education.
To attract and retain knowledgeable, creative, motivated and highly skilled individuals whose
leadership and contributions uphold the college tenets of education, creativity, research and
responsible public service.
To develop faculty and resources to impart and disseminate knowledge and information to
students and also to society that will enhance educational level, which in turn, will contribute
to social and economic betterment of society.
To provide an environment that values and encourages knowledge acquisition and academic
freedom, making this a preferred institution for knowledge seekers.
To provide quality assurance.
To partner and collaborate with industry, government, and R&D institutes to develop new
knowledge and sustainable technologies and serve as an engine for facilitating the nation’s
economic development.
To impart personality development skills to students that will help them to succeed and lead.
To instil in students the attitude, values and vision that will prepare them to lead lives of
personal integrity and civic responsibility.
To promote a campus environment that welcomes and makes students of all races, cultures
and civilizations feel at home.
Putting students face to face with industrial, governmental and societal challenges.
VISION
To be a Centre of Excellence in computer science and engineering education and training to meet
the challenging needs of the industry and society
MISSION
To impart quality education through well-designed curriculum in tune with the growing software
needs of the industry.
To serve our students by inculcating in them problem solving, leadership, teamwork skills and
the value of commitment to quality, ethical behavior & respect for others.
PEO2: Manage software projects with significant technical, legal, ethical, social, environmental and
economic considerations.
PSO1: Design, develop, test and maintain reliable software systems and intelligent systems.
PSO2: Design and develop web sites, web apps and mobile apps.
Students must use the equipment including PCs, Keyboard and Mouse with care. Any damage
is caused is punishable.
Students are required to carry their observation and record books with completed exercises
while entering the lab.
Students are supposed to occupy the machines allotted to them and are not supposed to talk or
make noise in the lab.
Lab can be used in free time / lunch hours by the students. Students who need to use the
systems should take prior permission from the lab in-charge.
Students are not supposed to use floppy disks/CDs/Pen drivesetc during the Lab session.
9. Repeat this process for each of the existing partitions that you want to move (or remove) in order
to create your new partition.
10. When all necessary partitions are deleted, you can then select the remaining un-partitioned space
and then press C to create new partitions.
15. Setup will start formatting the disk and will then start copying files from the CD-ROM to the disk
Aim: Write a leave letter to the Principal by using different alignments, correct formats in MS-
Word.
Description:
Microsoft word is a powerful text editor which supports different font types, styles, image
operations etc. It is widely used for detailed documentation in various sectors like educational
institutes, business documentation, academic projects etc.
Procedure:
Step 1: Open MS-Word by click on START button; go to All Programs, then select Microsoft
Office Word2007.
Step 2: To open a new document, Click on Office Button then select New - > Blank
Documentthen click on create option.
Step 3: Then select TEXT AREA, and then write Leave Letter as a heading, Select the text, click on
bold
Then Select the text and make it right by clicking on right alignment button
Step 5: Then write To address as follows and select this text and make it left by clicking on left
alignment
The Principal,
College of Engineering,
Guntur.
Step 6: Then write Subject according to your letter. And select this text and press tab button for two
times. Step 7: Then write the body of the letter according to your letter. And select this text and make it
justification
button
Step 9: Now write the “From address”
as followsYours Faithfully, xxxxx.
D:15/9/2018,
Respected Sir,
Yours Faithfully,
XXXXX,
B.Tech I year,
CSE Branch.
Viva Questions:
Method1: Method2:
1. Click on start button 1. Click on Start button
2. Click on programs 2. click run
3. Click on Ms-office 3. type the Excel
4. Click on Excel 4. After click ok button
5 Write S.no’s from 1-10 in A4 - A13 cell addresses and H.T.No’s from B4- B13.
6 Now enter the marks in C4 – M13 cell addresses.
7 Now in the G.Totalcell,select N4 cell and apply the formula for adding the marks
contained in C4 – M4 cell addresses in the formula bar as
fx= C4+D4+E4+F4+G4+H4+I4+J4+K4+L4+M4 then press ENTER key.
8 Select the N4 cell and drag towards down for further students calculations.
9 Now calculate the Percentage.For that select O4 cell and type % calculation
formula in Formula bar as
fx=N4/1000*100
10 Select the O4 cell and drag towards down for further students results.
11 Now the % appears in decimal values,now in order to appear the values as rounded
values,select the O4 cell then right click the mouse button , select Format cells then
Numbers and now make decimal places to 0(zero) then click OK.Now again drag
for other cell values to be rounded.
12 Now for keeping the borders,select cells from A1 – O13 and select All Borders on
the home Menu.
13 Now for saving click on OFFICE button and click on Save and type file name as
“Marks Sheet”,then click OK.
Viva Questions:
and the menu bar that you see on your right here will drop down giving you various
options, including saving.
When you save a workbook in MS Excel 2007, it automatically saves with “.pptx”as its
extension.
However, you can also save your presentation so that it’s readable by earlier versions of
MS PowerPoint (97 – 2003) by simply selecting “PowerPoint 97‐2003 Presentation”when
choosing what file type to save as (please see the screenshot below).
Inserting a Slide:
To insert a new slide…
–From the Hometab, select “New Slide”
‐As well, you can right‐click between any 2 slides in the preview frame located on the
left‐hand side of the Normal view and select “New Slide”
Deleting a Slide:
To delete a slide…
–Select the slide you’d like to delete (eg. by highlighting it) and selecting “Delete
“from the Hometab –As well, you can right‐click on any slide in the preview frame
located on the left‐hand side of the Normal view and select “Delete Slide”
Inserting Pictures:
To insert pictures…
–From the Inserttab you can insert pictures from your computer, clip art, shapes, etc…
–Also, when you have a blank slide (or parts of a blank slide), you can also click on
options within these blank compartments to insert pictures.
Inserting Charts:
Department of Computer Science and Engineering GEC Page 26
To insert charts…
–From the Inserttab you can insert pictures from your computer, clip art, shapes, etc…
–Also, when you have a blank slide (or parts of a blank slide), you can also click on options
within these blank compartments to insert charts
•Once you’ve selected to insert a chart, it will ask you choose what kind of chart you’d like
to insert.
•After you’ve picked a type, the screen will split in half with the chart on one side and an
excel spreadsheet on the other
–To modify the chart, make changes in the data presented in the spreadsheet
– Charts from Excel can also be copied and pasted into PowerPoint
Inserting Tables:
To insert a table…
–From the Insert tab, select “Table “and a box will drop down giving you more options
for inserting a table. –Also, when you have a blank slide (or parts of a blank slide), you
can also click on options w/n these blank compartments to insert tables
Viva Questions:
Description: The area of a triangle depends on the size of all the three sides of the triangle.
We use the mathematical function “sqrt” for performing the square root operation using the
mathematical header file <math.h>
Algorithm
1. Start.
2. Read three sides of a triangle a,b,c.
3. Calculate s= (a+b+c)/2.
4. Display Area=sqrt(s*(s-a)*(s-b)*(s-c)).
5. Display area of triangle.
6. Stop.
Flowchart
start
calculate s= (a+b+c)/2
Display Area=sqrt(s*(s-a)*(s-b)*(s-c))
Display area of
triangle Area
Stop
Program
Output
1. Enter size of each sides of triangle 4.5 2.5 5
Area of triangle is: 5.612
2. Enter size of each sides of triangle 5 6 3
Area of triangle is: 7.483
Viva questions:
Description: A ternary operator is a special operator that can check for two conditions in a
single statement. If the condition is true, a sequence of instructions is executed. Else,
another sequence is executed.
Algorithm
1. Start.
2. Read three numbers a,b,c .
3. If a>b goto step 3.1 otherwise goto step 4
3.1.If a>c goto step 3.2 otherwise goto step 3.3
3.2.Display a is largest of three numbers ,goto step 5
3.3.Display c is largest of three numbers ,goto step 5
4. If b>c goto step 4.1 otherwise gotobstep 4.2
4.1.Display b is largest of three numbers goto step 5
4.2.Display c is largest of three numbers
5. Stop.
Flowchart start
T F
a>b ?
TT a>c ? F b>c ?
F
Stop
Viva questions:
Description:
Nature of roots of quadratic equation can be known from the determinant d = b 2-4ac
if b2-4ac >0 then roots are real and unequal
if b2-4ac =0 then roots are real and equal
if b2-4ac <0 then roots are imaginary
Algorithm:
Step 1: start
Step 2: read the a,b,c value
Step3: assign pow((b*b-4*a*c),0.5) value to d
Step4: if d==0 compute r1=-b/(2*a) , r2=-b/(2*a) go to step 7 otherwise go to step5
Step5: if d<0 print roots are imaginaryand compute real and imaginary parts for r1 and r2
goto step 8 otherwise go to step6
Step6: compute r1 = ((-b+d) / (2*a)) r2 = ((-b-d) / (2*a)) go to step 7
Step7: print r1, r2
Step8: stop
Start
Read a,b,c
d = pow((b*b-4*a*c),0.5)
F T
d= = 0 d< 0
T F
r1 = ((-b+d) / (2*a)) Display
r1=r2= r2 = ((-b-d) / (2*a)) roots are
-b / (2 * a ) imaginary
Display
r1, r2
Stop
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
inta,b,c;
double r1,r2,d;
clrscr();
printf("Enter the values of a,b,c:");
scanf("%d%d%d",&a,&b,&c);
d=((b*b)-(4*a*c));
if(d==0)
{
r1=r2=(-b/(2*a));
printf("Roots are Equal:%lf,%lf",r1,r2);
}
else if(d<0)
printf("Roots are Imaginary");
else
{
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
printf("Roots are:%lf,%lf",r1,r2);
}
getch();
}
Output:
Viva Questions:
1) What are various types of loop statements?
2) What is the difference between while and do-while statements?
3) List out the C features?
Description:
Take two integer operands and one operator from user and perform some arithmetic
operations by using the following operators like +,-,*, /, %
Ex: 2+3=5
Algorithm:
Step 1: Start
start
op?
‘-’
‘+’‘*‘ ‘/’ ‘%’
display display display display displaya% display
a+b a-b a*b a/b value b value “Invalid
value value value operato
r”
start
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int op1,op2;
char op;
clrscr();
printf("\nOperations Performed are: + - * / %");
printf("\nEnter 2 Integers & an Operator:");
scanf("%d %d %c",&op1,&op2,&op);
switch(op)
{
case '+': printf("ADDITION -- Sum is %d",op1+op2);
break;
case '-': printf("SUBTRACTION -- Difference is %d",op1-op2);
break;
case '*': printf("MULTIPLICATION -- Product is %d",op1*op2);
break;
case '/': printf("DIVISION -- Quotient is %d",op1/op2);
break;
case '%': printf("MODULUS -- Remainder is %d",op1%op2);
break;
default: printf("Invalid operation");
break;
}
getch();
}
VIVA QUESTIONS:
Description:
A natural number is a number that occurs commonly and obviously in nature. As
such, it is a whole, non-negative number. The set of natural numbers, denoted N, can be
defined in either of two ways: N = {0, 1, 2, 3,}
Algorithm
1. Start.
2. Read the value of n.
3. Initialize the variable i=1.
4. Repeat.
4.1.Display i value.
4.2. i is incremented by 1 in each case
Until the condition is failed i.e. i<=n.
5. stop.
Flowchart
start
i=1
F
i<=n
Display i value
i+=1
Stop
Viva Questions:
1) What is a natural number?
2) Any program execution in C language starts from which function?
3) How does the printf and scanf functions work?
Description:
A prime number is the one which has only the factors 1 and itself. We check for
the total number of factors for the given number. If the given number has only two factors,
it’s a prime number. Else, it’s not a prime number.
Algorithm:
Step 1: Start
Step 2: initialize c=0
Step 3: Read input ‘n’ from user
Step 4: initialize i=1
Step 5: check whether n%i==0 if true increment c
Step 6: increment i
Step 7: repeat steps 4 and 5 until n>i
Step 8:check c=2 if true print number is prime
Step 9: else print number not prime
Step 10: stop
READ INPUT
‘n’FROM USER
Initialize i=1
F i<=n
?
T
If(n%i
F
=0)
T
Increment count
c
Increment i
c= =2
? Number is
prime
#include<stdio.h>
void main()
{
int c=0,n,i;
printf("enter a number");
scanf("%d",&n);
i=1;
do
{
if(n%i==0)
c++;
}while(i<=n);
if(c==2)
printf("given number %d is prime",n);
else
printf("given number %d is not prime",n);
getch();
}
Output
1. enter a number21
given number 21 is not prime
2. enter a number251
given number 251 is prime
Viva Questions:
1) What is a composite number?
2) How does a for loop work?
3) State the skeleton for simple if-else statement?
4) What is meant by access specifier?
Algorithm
1. Start.
2. Read number of elements in an array (n)
3. Read n array elements
4. Read search key
5. Initialize i=0
6. If i<n do as follows if not goto step 7
6.1.check if array element equal to key then goto step 6.2 otherwise goto 6.3
6.2.Display search key is available in the array ,goto step 8
6.3.Increment i
7. if i=n display key is not found
8. Stop
start
Read number
ofelementsin an array(n)
Initialize i=0
i<n ?
?
T F
Read array elementsa[i]
i++
i<n
i=0
i++
F T F
a[i]==
k
T
key is available
F i==n
?
T
Stop
Department of Computer Science and Engineering GEC Page 45
Program:
main()
{
int a[20],i,n,key;
clrscr();
printf("Enter no of elements\n");
scanf("%d",&n);
printf("Enter %d elements",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter key");
scanf("%d",&key);
for(i=0;i<n;i++)
{
if(a[i]==key)
{
printf("element is found at %d thlocation",i);
break;
}
}
if(i==n)
printf("key not found");
Output:
1) Enter no of elements 5
Enter 5 elements5
4
3
2
1
Enter key2
element is found at 3 th location
2) Enter no of elements 8
Enter 8 elements14 2 54 896 47 25 14 7
Enter key100
key not found
Viva Questions:
1) How an array is efficient in storing and organizing of data?
2) If the total elements of an array are n, then the maximum possible value of index is?
Why?
3) How the search operation does takes place in an array?
Department of Computer Science and Engineering GEC Page 46
Program 11: Implement a C Program to Perform Addition and multiplication of two
matrices.
Algorithm:
Step 1: start
Step 2: read the size of matrices A,B – m,n
Step 3: read the elements of matrix A
Step 4: read the elements of matrix B
Step 5: perform the additionoperation place the result in C matrix
Step 6: print the elements of matrix C
Step 7: Stop
If r1!=r2 T
and c1!=c2
F
Display
Read matrices A and B invalid order
of matrices
F i=0 i++
i<r1
j=0 j<c1 F
j++
c[i][j]=a[i][j]+b[i][j];
Print result
matrix
stop
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10];
int r1,c1,r2,c2,i,j,k;
clrscr();
printf("Enter Number of rows & columns for Matrix1:");
scanf("%d %d",&r1,&c1);
printf("Enter Number of rows & columns for Matrix2:");
scanf("%d %d",&r2,&c2);
if(r1==r2 && c1==c2)
{
printf("Enter elements for Mat1:");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&a[i][j]);
}
printf("Enter elements for Mat2:");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&b[i][j]);
}
for(i=0;i<r1;i++)
{
printf("\n");
for(j=0;j<c1;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf("%d\t",c[i][j]);
}
}
}
else
printf("Matrix addition is not possible");
getch();
4 4
4 4
2)
Enter Number of rows & columns for Matrix1:2
3
Enter Number of rows & columns for Matrix2:3
2
Matrix addition is not possible
Algorithm:
Step 1: start
Step 2: read the size of matrices A,B
Step 3: check compatibility of matrices for multiplicationi.e, number of columns
in the first matrix should be equal to number of rows in the second matrix.
Step 4: read the elements of matrix A
Step 5: read the elements of matrix B
Step 6: perform the multiplication operation by storing the resulting values into
matrix C.
Step 7: print the resultant matrix C.
Step 8: Stop
If c1!=r2 T
F
Read matrices A and B
Display
i=0 i++ invalid order
F i<r1 of matrices
j=0 j<c2
j++
c[i][j]=0
F
k=0 k<c1
k++
T
c[i][j]=c[i][j]+(a[i][k]*b[k
stop
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10];
int r1,c1,r2,c2,i,j,k;
clrscr();
printf("Enter Number of rows & columns for Matrix1:");
scanf("%d %d",&r1,&c1);
printf("Enter Number of rows & columns for Matrix2:");
scanf("%d %d",&r2,&c2);
if(c1==r2)
{
printf("Enter elements for Mat1:");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&a[i][j]);
}
printf("Enter elements for Mat2:");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&b[i][j]);
}
printf("result");
for(i=0;i<r1;i++)
{
printf("\n");
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<c1;k++)
c[i][j]+=a[i][k]*b[k][j];
printf("%d\t",c[i][j]);
}
}
}
else
printf("\n Matrix multiplication is not possible");
getch();
1)
Enter Number of rows & columns for Matrix1:2
3
Enter Number of rows & columns for Matrix2:3
2
Enter elements for Mat1:2
2
2
2
2
2
Enter elements for Mat2:2
2
2
2
2
22
result
12 12
12 12
2)
Enter Number of rows & columns for Matrix1:2
3
Enter Number of rows & columns for Matrix2:2
2
VIVA QUESTIONS:
Description:
Algorithm:
main program
Step 1: start
Step 2: read n
Step 3: call sub program
Step4: f=fact(n)
Step 5: print f value
Step 6: stop
Sub program:
Start
Read n
Call subprogram
f = fact(n)
print f
Stop
Sub program
fact(int n)
false
n==0
true
Return 1 Return
n*fact(n-1)
Return to main
program
#include<stdio.h>
#include<conio.h>
int fact(int n)
{
int f;
if((n==0)||(n==1))
return 1;
else
f=n*fact(n-1);
return(f);
}
void main()
{
int n;
clrscr();
printf("enter the number :");
scanf("%d",&n);
printf("factorial of number %d is %d",n,fact(n));
getch();
}
Output:
1)
enter the number :5
factorial of number 5 is 120
2)
enter the number :9
factorial of number 9 is 362880
Viva Questions:
1) Define recursion,
2) Differences between normal functions and recursion.
3)Define library function?
4)Define formal parameters?
Description
This program interchanges values of two variables using functions and sending addresses.
Algorithm:
Step 1 : Start
Step 2 : Read num1,num2.
Step 3 : Display before swapping num1,num2.
Step 4 : Calling swap function.
Step 5 : Display after swapping.
Step 6 : Stop
Before Swapping
Print num1,num2
Swap(&num1,&
num2)
Stop
Subprogram:
temp=*a
*a=*b,
*b=temp
main()
Output:
Enter 2 Numbers to Swap:10 20
Before Swapping:
Two Numbers are:Num1=10 Num2=20
After Swapping:
Two Numbers are:Num1=20 Num2=10
Enter 2 Numbers to Swap:55 66
Before Swapping:
Two Numbers are:Num1=55 Num2=66
After Swapping:
Two Numbers are:Num1=66 Num2=55
Viva Questions:
Description:
Apply some of the predefined functions on given strings. These are included in string.h
header file.
Algorithm
Step 1 : start
Step 2: read s1,s2,s3
Step 3: compute l1= strlen(s1)
Step 4 : print l1
Step 5 : compute s=strcpy(s3,s1)
Step 6 : print s
Step7: compute e=strcmp(s1,s2)
Step 7 : if e==0 go to step 8 otherwise go to step 9
Step 8 : display “strings are equal”
Step 9 : display “Strings are not equal “
Step 10 : display “reverse of 1st string is “, strrev(s1)
Step 11 : display “after concatenation of two strings s1 and s2 is “ strcat(s1,s2)
Step 12 : stop
Read strings
s1,s2,s3
l1=strlen(s1)
Display l1
s=strcpy(s3,s1)
Display s
e=strcmp(s1,s2)
r=strrev(s1) c=strcat(s1,s2)
false
If
e==0
true
stop
#include<string.h>
#include<stdlib.h>
void main()
{
char s1[25],s2[25],s3[25];
int l1,l2,e;
clrscr();
printf("\n Enter three strings ");
gets(s1);
gets(s2);
gets(s3);
l1 = strlen(s1);
printf("\n length of s1 is %d ",l1);
printf("\n After copying 1st string into 3rd string is %s",strcpy(s3,s1));
e=strcmp(s1,s2);
if(e==0)
printf("\n The two strings s1 and s2 are equal ");
else
printf("\n The two Strings s1 and s2 are not equal ");
printf("\n Reverse of first string is %s ",strrev(s1));
printf("\n After adding first two strings %s",strcat(s1,s2));
getch();
}
Output:
1)
Enter three strings sagf
gec
gudlavalleru
length of s1 is 4
After copying 1st string into 3rd string is sagf
The two Strings s1 and s2 are not equal
Reverse of first string is fgas
After adding first two strings fgasgec
2)
Enter three strings gec
gec
gudlavalleru
length of s1 is 3
After copying 1st string into 3rd string is gec
The two strings s1 and s2 are equal
Reverse of first string is ceg
After adding first two strings ceggec
1) What is a string?
2) Which command is used to combine two strings?
3) Which command is used to copy the strings?
4) Which header file/s is used to implement string functions?
5) What is the difference between a character and a string?
6) What is a sub-string?
7) What do the functions gets(),puts() do?
Description:
Structure is a user defined data type available in C programming, which allows you
to combine data items of different kinds.Structures help to organize complex data in a
meaningful way.
Algorithm
1. Start.
2. Declare structure members with tag name emp
3. Read number of employees n
4. Read n employees information.(employee name ,date of birth, salary)
5. Display n employees information.( employee name ,date of birth, salary)
6. Stop
Read number
ofemployees(n)
i=0 i<n
i++
F T
Display n employees name,
date of birth , salary of emp[i]
Stop
}dob;
};
void main()
{
int i;
structemp e[10];
for(i=0;i<10;i++)
{
printf("enter name sal,date,month,year of emp[%d]",i+1);
scanf("%s%d%d%s%d",e[i].name,&e[i].sal,&e[i].dob.date,e[i].dob.month,&e[i].dob.year);
}
for(i=0;i<10;i++)
{
printf("employee %d details\n",i+1);
printf("name:%s\nsal:%d\ndob:%d %s
%d\n",e[i].name,e[i].sal,e[i].dob.date,e[i].dob.month,e[i].dob.year);
}
getch();
}
Output:
employee 3 details
name:
sal:
dob:
employee4 details
name:
sal:
dob:
employee 5 details
name:bhaskar
sal:22000
VIVA QUESTIONS:
1) What is a Structure?
2) Difference between Structure and Union?
3) How do you access Structure Members?
Description:
In this program, we have to count the number of lines, words and characters in a given
program or given text by using the string function. We check for conditions new line,
empty space for updating the above values.
Algorithm:
Step 1: Start
Step 2:initializenoc=0,now=0,nol=0.
Step 3: open filefname in read mode
Step 4: if fp is NULL, then print unable to open files, go to step 10 otherwise go
to step5
Step 5: read a character from file to c
Step 6: if c !=EOF then goto step 6.1otherwise go to step 7
6.1 increment noc by 1
6.2 if ch=’ ‘ or c=’\t’ then increment now by 1
6.3 if ch=\n the increment nol and now by 1
Step 7: increment nol and now by 1
Step 8:print the noc ,now and nol
Step 9:Close the file.
Step 10: Stop
Initialize nol,now,noc to
0
Read file name fname1
fp=fopen(fname1,"r")
F fp==NULL?
T
Unable to open the
filefile
ch=fgetc(p)
ch!=EOF ?
noc++
ch ==’ ‘ || \t’
T F
now++
F ch==’\n’ ?
T
nol++
now++
Display nol+1
Display noc
fclose(fp)
stop
#include<stdio.h>
#include<conio.h>
void main()
{
intnoc=0,now=0,nol=0;
FILE *fw,*fr;
charfname[20],ch;
clrscr();
printf("\n enter the source file name");
gets(fname);
fr=fopen(fname,"r");
if(fr==NULL)
{
printf("\n error \n");
exit(0);
}
do
{
ch=fgetc(fr);
noc++;
if(ch==' ')
now=1+now;
if(ch=='\n')
{
nol++;
now++;
}
}while(ch!=EOF);
fclose(fr);
printf("\n total no of character=%d",noc);
printf("\n total no of words=%d",now+1);
printf("\n total no of lines=%d",nol+1);
getch();
}
2)
enter the source file namerealloc.c
total no of character=431
total no of words=50
total no of lines=25
VIVA QUESTIONS: