You are on page 1of 16

Future Institute of Engineering & Management

Department of Computer Science & Engineering

REPORT ON: _____ PROGRAMMING FOR PROBLEM SOLVING .LAB

NAME: _______SREYA SAHA_____________________________________________________________________

DEPARTMENT: CSE_ ROLL NO.: 14800120081 SEMESTER: 2ND GROUP: A YEAR: 1ST

EXPT. NO.: ASSIGNMENT NO. - 10

TITLE: FILE OPERATIONS._______________________________________________

OBJECTIVE: READING & WRITING OF A FILE, COUNTING THE NUMBERS OF WORDS, LINES & CHARACTERS IN A
PARAGRAPH, SORTING OF FILE.

CO-WORKERS:
1 ………………………………………..

2 ……………………………………….. DATE OF PERFORMANCE: 27/07/2021

3 ………………………………………. DATE OF SUBMISSION: 31/07/2021

MARKS/GRADE: …………………………………

TEACHER’S SIGNATURE:………………………………… DATE:………………………..

1
Future Institute of Engineering & Management
Department of Computer Science & Engineering

CONTENT

Assignment Date of Title of Page Teacher’s


No./Expt. No. Performance Assignment/Expt. No. Remarks Signature

1. 25/05 TO SWAP THE NUMBERS 1-4

TO PERFORM ARITHMETIC
OPERATION 5-6

TO FIND THE AREA OF


THE CIRCLE 9-10

TO CONVERT THE
TEMPERATURE 7-8

TO COMPUTE SIMPLE
AND COMPOUND 10-11
INTEREST

TO FIND WHETHER A 3-4


2. 04/06 GIVEN NUMBER IS EVEN
OR ODD

TO FIND THE LARGEST 4-7


& SAMLLEST VALUE OF
THEREE Numbers.

TO ASSIGN GRADE 7-10


ACCORDING TO THE
PERCENTAGE OF
MARKS.

TO FIND THE LARGEST


OR SMALLEST NUMBER
3. 08/06 AMONG THREE 4
NUMBERS USING
CONDITIONAL
OPERATOR.

2
Future Institute of Engineering & Management
Department of Computer Science & Engineering

CONTENT
Assignment Date of Title of Page Teacher’s
No./Expt. No. Performance Assignment/Expt. Remarks Signature
No.
TO CHECK WETHER A YEAR IS
LEAP YEAR OR NOT. 5-6

TO COMPUTE THE REAL


ROOTS OF QUADRETIC 7-8
EQUATION.

TO COMPUTE THE FACTORIAL


4 15/06 OF A NUMBERS 5-6

TO CHECK WETHER A
NUMBER IS PRIME OR NOT 7-8

TO FIND THE SUM OF ALL


PRIME NUMBERS BETWEEN A
GIVEN RANGES 9-10

TO FIND THE SUM OF ALL


EVEN/ODD NUMBERS 11-12
BETWEEN 1-100

TO FIND THE SUM OF ALL


DIVISABLE BY 7 WITHIN A 13-14
GIVEN RANGES

FOR DETERMINING WHETHER


A NUMBER IS PERFECT 15-16
NUMBER OR NOT
FOR DETERMINING HOW
MANY PERFECT NUMBERS
ARE EXIST WITHIN A GIVEN 17-18
RANGES

FOR DETERMINING WHETHER


A NUMBER IS AN
ARMSTRONG NUMBER OR 19-20
NOT

FOR DETERMINING WHETHER


A NUMBER IS A KRISHNA
MURTHY NUMBER OR NOT 21-22

3
Future Institute of Engineering & Management
Department of Computer Science & Engineering

CONTENT
Assignment Date of Title of Teacher’s
No./Expt. No. Performance Assignment/Expt. Page No. Remarks
Signature

TO FIND REVERSE OF AN
INTEGER NUMBER
23-24

TO FIND SIN OR COS VALUE


OF AN ANGLE FROM TAYLOR
25-26
SERIES.

SERIES
05. 22/06 17-18

FIBONACCI SERIES 18-19

SUM OF THE DIGITS OF 20-21


NUMBERS

PATTERNS 22-28

DECIMAL TO BINARY 6-7


CONVERSATION.
06. 29/06

BINARY TO DECIMAL 8-9


CONVERSATION.

GENERATE THE FIBONACCI 10-11


SERIES UPTO Nth TERMS.

TO CHECK MAXIMUM &


MINIMUM NUMBER IN
12-13
ARRAY.

4
Future Institute of Engineering & Management
Department of Computer Science & Engineering

CONTENT
Assignment Date of Title of Teacher’s
No./Expt. Performance Page No. Remarks
Assignment/Expt. Signature
No.

TO SORT THE IN AN ARRAY


(BUBBLE/INSERTION/SECTION
14-19
SORT).

TO CHECK HOW MANY


VOWELS ARE IN A GIVEN LINE 20-21

TO SEARCH AN ELEMENTS IN
AN ARRAY (LINEAR/BINARY
22-25
SEARCH)

07. 06/07 SHOW THE ELEMENTS OF A


MATRIX. 7-8

FIND THE SUM OF TWO


MATRIXES 9-11

FIND THE MULTIPLICATION


OF TWO MATRIXES. 12-14

FIND THE TRANSPOSE OF A


MATRIX. 15-17

REVERSE A STRING WITHOUT


USING THE SYSTEM 18
FUNCTION.

CHARACTER COUNT
WITHOUT USING THE SYSTEM 19
FUNCTION.

5
Future Institute of Engineering & Management
Department of Computer Science & Engineering

CONTENT

Assignment Date of Title of Page Teacher’s


Remarks
No./Expt. No. Performance Assignment/Expt. No. Signature
LOWER CASE OF THE
GIVEN INPUT STRING
20
WITHOUT USING THE
SYSTEM FUNCTION.

SUM OF THE UPPER


TRIANGULAR MATRIX
21-22
WITHOUT USING THE
SYSTEM FUNCTION.

SUM OF THE LOWER


TRIANGULAR MATRIX
23-24
WITHOUT USING THE
SYSTEM FUNCTION.

FIND THE FACTORIAL


WITH THE HELP OF
RECURSION OF A GIVEN 8-9
NUMBER USING
FUNCTION.

TO GENERATE THE
PASCAL’S TRIANGLE 10-12
USING FUNCTIONS.

TO FIND THE GCD & LCM


OF TWO GIVEN NUMBERS 13-14
USING FUNCTION.

TO FIND THE SUM OF THE


SERIES: (CALCULATE THE
FACTORIALS USING 15-16
FUNCTION) S= 1! + 2! + 3!
+ 4! + . . .

6
Future Institute of Engineering & Management
Department of Computer Science & Engineering

CONTENT

Assignment Date of Title of Page Teacher’s


Remarks
No./Expt. No. Performance Assignment/Expt. No. Signature
TO FIND MAX
ELEMENT FROM AN 17-18
ARRAY USING
FUNCTION

TO CALCULATE THE
AREA OF A TRIANGLE,
RECTANGLE OR A 19-23
CIRCLE USING
FUNCTION

TO SWAP TWO
09 20\07 NUMBERS USING 8-9
POINTERS &
FUNCTION

TO SORT AN ARRAY OF
NUMBERS USING 10-11
POINTERS &
FUNCTION (USE
BUBBLE SORT).

LIBRARY FUNCTION 12-13

TO SORT AN ARRAY OF
STRINGS USING
POINTERS & 14-15
FUNCTION
(DICTIONARY SORTING

SORTING OF MARKS 16-18

DISPLAY TIME 19-20


DIFFERENCE

7
Future Institute of Engineering & Management
Department of Computer Science & Engineering

CONTENT
Assignment Date of Title of Teacher’s
No./Expt. Performance Page No. Remarks
Assignment/Expt. Signature
No.

10 27/07 READING & WRITING OF A


FILE.

COUNTING THE NUMBERS OF


WORDS, LINES &
CHARACTERS IN A
PARAGRAPH.

SORTING OF FILE.

8
Q.1.

Problem Statement:
Write a Program in C to write a line of text into a file (xyz.txt) and read from that file to print.

Algorithm:
Step1:Start
Step2:declaring the main()
Step3:declaring a file pointer 2 integer variables and 2 character arrays and a character
variable
Step4:storing the lines as input in the file from the user by opening the file in reading
mode
Step5:opening the file in reading mode
Step6:displaying the contents in the file
Step7:end of main()
Step8:end
C Code:

#include <stdio.h>

int main ()
{
FILE * fptr;
int i,n;
char str[100];
char fname[20]="test.txt";
char str1;

fflush(stdin);
printf("\n :: The lines are ::\n");
fptr = fopen (fname,"w");
fgets(str, sizeof str, stdin);
fputs(str, fptr);
fclose (fptr);
fptr = fopen (fname, "r");
printf("\n The content of the file %s is :\n",fname);
str1 = fgetc(fptr);
while (str1 != EOF)
9
{
printf ("%c", str1);
str1 = fgetc(fptr);
}
printf("\n\n");
fclose (fptr);
return 0;
}

OUTPUT:

10
Q.2.

Problem Statement:
Write a Program in C to create a text file (abc.txt) containing a paragraph and count number of
characters, words, lines in that file and print on the console.
Algorithm:
Step1:start
Step2:declaring the main()
Step3:declaring a file using pointer and 2 character array and a character and 3 integer
type variables
Step4:declaring the name of the file and creating a file in writing mode
Step5:writing the sentences as input from user and storing them in the file
Step6:opening the file in reading mode
Step7:counting the number of words lines and characters and displaying them
Step8:end of main()
Step9:end
C Code:
#include <stdio.h>
#include <stdlib.h>

int main()
{
FILE * file;
char path[100], sentence[1000];
char ch;
int characters, words, lines;
printf("Enter the name of file : ");
scanf("%s", path);
fflush(stdin);
file = fopen(path, "w");
if (file == NULL)
{
printf("\nUnable to open file.\n");
printf("Please check if file exists and you have read privilege.\n");

exit(EXIT_FAILURE);
11
}
printf("Enter a paragraph:\n");
fgets(sentence, sizeof(sentence), stdin);
fprintf(file, "%s", sentence);
fclose(file);
file=fopen(path,"r");
characters = words = lines = 0;
while ((ch = fgetc(file)) != EOF)
{
characters++;
if (ch == '\n' || ch == '\0' || ch == '.')
lines++;
if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\0')
words++;
}
printf("\n");
printf("Total characters = %d\n", characters);
printf("Total words = %d\n", words);
printf("Total lines = %d\n", lines);
fclose(file);

return 0;
}

OUTPUT:

12
Q.3.

Problem Statement:
Write a Program in C to read N numbers from a file (abc.txt), sort and store into the same file.

Algorithm:
Step1:start
Step2:declaring a file using pointer and a character array and integer variables and an
integer array
Step3:taking the file name from user
Step4:opening the file in read mode and entering the data and storing them in an array
Step5:sorting the data in ascending order
Step6:displaying the sorted data in the file
Step7:end of main()
Step8:end
C Code:
#include <stdio.h>
#include<stdlib.h>
int main()
{

FILE*fptr;
char s[100];
int i=0,j,n=0,min,index,val[10],temp;
printf("Enter the file name: ");
gets(s);
fptr=fopen(s, "w");
printf("Enter the data: ");
for (i=0;i<5;i++)
{
scanf("%d",&val[i]);
fprintf(fptr,"%d ",val[i]);
}
printf("numbers generated successfully !! \n\n");
for (i = 0; i < 5-1; i++)
{
for (j = 0; j < 5-i-1; j++)
13
{
if (val[j] > val[j+1])
{
int temp = val[j];
val[j] = val[j+1];
val[j+1] = temp;
}
}
}
printf("Sorted list: \n");
for (i=0;i<5;i++)
{
printf("%d ",val[i]);
fprintf(fptr,"%d ",val[i]);
}
fclose(fptr);
return 0;
}

OUTPUT:

14
15
16

You might also like