c program record completed
c program record completed
SALEM 636011
FIRST YEAR
NAME :
REGISTER NUMBER :
1
2
GOVERNMENT COLLEGE OF ENGINEERING
(An Autonomous Institution Affiliated to Anna University, Chennai)
SALEM 636011
22CS102-COMPUTER PRACTICE LABORATORY
Staff In Charge
3
4
TABLE OF CONTENTS
STAFF
EX.NO: DATE NAME OF THE EXPERIMENT P.NO
SIGNATURE
MS WORD
Document creation and text manipulation
1. 7
with scientific notations
Table creation, formatting and
2. 19
conversion
Mail Merging and letter preparation
3. 25
MS EXCEL
Chart-Line, XY, Bar, Pie, formula
21 editor, sorting, export/import 31
4.
FLOWCHART
Flowchart to find the sum of first 100
5. 39
natural numbers
C PROGRAMMING
7. Odd Or Even 57
8. Calculator 65
5
STAFF
EX.NO: DATE NAME OF THE EXPERIMENT P.NO SIGNATURE
PROGRAM USING LOOPING
STATEMENT
16. 131
Function with array
PROGRAM USING STUCTURE
6
Ex No: 01 WORD PROCESSING-DOCUMENT
Date : CREATION TEXT MANIPULATION
WITH SCIENTIFIC NOTATION
AIM:
To create a document and manipulate the text with the
scientific notation.
PROCEDURE :
Step1: select Start->All Programs->Microsoft Office- >Microsoft
Office Word
7
8
SPELLING AND GRAMMER MISTAKE CHECK
If any spelling mistake in the word is underlined with red colour, then
click right of the red line, menu will appear and it shows the suggested
correct spelling and choose right one.
If any grammar mistake occurs in text means green line will occur
in text then click right of the green line, hence menu will appear.
LINE SPACING
Select the paragraph of the document by press ctrl+A select line
spacing value from editing
9
Watermark
2
10
CREATING BORDERS AND SHADING
Click page borders from background->page layout
Border and shading dialogue box will open click page border tab,
select setting what you want
CREATE WATERMARK IN THE DOCUMENT
Watermarks are text or pictures placed behind the text in your
document. You can add text watermarks, such as Draft or Confidential,
to your document. Word has a gallery of watermarks to choose from,
or you can create your own custom watermark, such as a company
logo for your document.
Click page layout and select page border from page
background and choose watermark button and click custom
watermark
Printed watermark dialogue box will open and type text then
click ok button.
TO CREATE MARGIN IN THE PAGE
Select the page setup from pagelayout and click margin
CHANGING TEXT INTO DIFFERENT CASE
Select the word or text, then click button from home then select one.
TYPE FORMULA
Type formula by using subscript button and superscript
button from home menu->font
INSERTING SYMBOLS AND EQUATIONS
Insert->symbols->select symbol
Insert->equation->select
equation
FIND AND REPLACE A WORD OR SENTENCE
If we want to find or replace word, choose find and replace
dialogue box will open when we select it from edit
Type the word which to find
11
Insert Symbols and formulas
Word Art
Macro
12
If we want to replace anything type the words in replace text box
HEADER AND FOOTER
To enter the header that repeats on all pages in your document
chose insert->header and footer->Header. To enter the footer that
repeats on all pages in your document choose insert->header and
footer->footer.
13
14
WORD ART
If we want to insert word art click insert->text->wordart
MACRO
It is a function which is used for typing purpose
1. Click view then select macro and then click record macro
2. Record macro dialogue box will open
3. Now give macro name in text box
4. Then click stop recording
5. Now macro is created if we want to use macro in any
document means click macro then click macroname you want.
Finally click few features now the text will appear in the document
GIVE BORDER TO THE TEXT
Select the text home->paragraph->borders->select bordertype
PROTECTING THE DOCUMENT
Click review->protect the document->restrict formatiing and editing-
>stop protection->enter password->documents are unprotected lab
and class
REPROTECT THE DOCUMENTS
Click review->protect the document->restrict formatting and editing-
>stop protection->enter password->documents are unprotected
SAVE THE DOCUMENT
Use the office button->select savebutton/ctrl+S->save as dialogue
box will open->choose a suitable name text->click same button now
the document is under a given name.
15
16
Result:
Thus the document has been created and manipulated with scientific notation.
17
18
Ex No: 02 WORD PROCESSING-TABLE
CREATION TABLE FORMATTING
Date :
AND CONVERSION
AIM :
To create table in the Microsoft office word document and convert
text to a table.
PROCEDURE :
TO CREATE A TABLE
1. Place your insertion point where you want the table to appear,
then select the Insert tab
2. Click the Table command
3. A drop menu containing a grid of squares will appear. However the
mouse over the grid to select the number of columns and rows in
the table.
4. Click the mouse and the table will appear in the document
5. You can now place the insertion point anywhere in the table to
add text
ADDING TEXT TO A TABLE
To move the insertion point to the next cell, press the tab key while
typing. If the insertion point is in the last cell, pressing the tab key will
automatically create a new row.
TO CONVERT EXISTING TEXT TO A TABLE
In this example, each row of information contains an item name
and price, separated by tabs. Word can convert this information into
a table and it will use the tabs to separate the data into two colums
1. Select the text you wish to convert
2. From the insert tab, Click Table command.
3. Select convert Text to Table the drop-down menu.
4. A dialogue box will appear. Choose one of the options in the
separate text at section. This is how Word knows what text to
put in each column.
5. Click OK. The text appears in a table.
19
20
MODIFYING TABLES
Its easy to modify the look and feel of any table after adding it to
document. Word includes may different options for customising a
table, including adding rows or columns, changing the table style, and
more.
TO ADD BORDERS TO A TABLE
1. Select the cells you wish to add border to
2. From the Design tab, select the desired Line Style, Line
Weight, and Pen colour.
3. Click the borders drop-down arrow.
4. Select the desired border type from the menu that
appears. Selecting a border type
5. The border will appear around the selected cells.
21
22
Result :
Thus the table in the Microsoft Office Word document has been
created and the text is converted to a table.
23
24
Ex No: 03 WORD PROCESSING - MAIL MERGE
Date :
AND LETTER PREPARATION
AIM
To use the mail merge option in the Microsoft Office word
document and to prepare letters
25
26
address list, you can click the Type a
new list button and click Create. You can then type your address list.
STEP4:
copy of the letter will basically be the same for the recipient data, so that
mail merge knows exactly where to add the data.
27
From
Mr/Ms
Mechanical ,GCE,Salem-11
To
GCE,Salem-11
Respected Sir/Madam,
I am writing to complain about the condition of the playground. Over the last two weeks,
I have noticed a great deal of litter.
It is my opinion that this litter is a health hazard. For example, yesterday a year 4 boy
fell over and cut his hand on a broken bottle. The boy in question needed four stitches.
I believe that there are a number of things that you could do to rectify this problem.
Firstly, it may be possible for you purchase additional litterbins. This would help prevent
people discarding their litter recklessly.
In addition, I think that our campus needs more adequate security to prevent vandals littering.
In conclusion, I hope you will take my concerns seriously and I look forward to your
reply.
Yours Faithfully ,
28
To Insert Recipient Data:
1. Place the insertion point in the document where you
wish the information to appear.
2. Choose one of the four placeholder optiond: Address block,
Greeting Line, Electronic postage, or More items.
3. Depending on your selection, a dialogue box ,may appear
with various options. Select the desired options and click
OK.
4. A placeholder will appear in your document. For example:
<<Address Block>>
5. Repeat these steps each time you need to enter information
from your data record. In our example, add a Greeting
lline.
6. When done, click Next:Preview your letters to move to step5.
For some letters, only need to add an address block and
Greeting line. Sometimes, however, you may wish to place recipient
data within the body of the letter to personalise it even further.
STEP5:
1. Preview the letters to make sure the information from the
recipients list appears correctly in the letter. You can use the
left and right scroll to view each document.
2. Click Next: Complete the merge to move to step6.
STEP6:
1. Click Print..to print the letters.
2. A dialogue box will appear. Click All, and then click OK.
3. The Print Dialogue box will appear. Adjust the print setting
if needed and the click OK. The letters will be printed.
Result:
Thus the mail merge option in the Microsoft office word
document has been used to create letters to multiple recipients.
29
30
Ex No: 04
CREATE CHARTS IN MS EXCEL
Date :
AIM :
To create a line XY, bar and pie charts using MS-excel.
PROCEDURE :
STEP1: Click start button and select all programs, then select
MS-0ffice 2007 and click MS-Excel2007
STEP2: Type the data in the excel sheet
STEP3: Select all data in the worksheet. Click insert->data option
and select the chart
STEP4: Choose chart name and its type like XY,(scatter),pie and
bar charts
Result :
Thus the chart was created successfully for the given data by
using excel sheet.
31
32
Ex No: 05
MS EXCEL-FORMULA EDITOR
Date :
AIM
STEP2:
Move the crusor to thhe toolbar and and mention the address of
the starting cell position and the address of the ending cell position and
press enter/tab for calculating the total.
Ex: C3:D3
STEP3:
Place the crusor in the end of the cell and drag it
STEP4:
Similarly, repeat the steps for remaming calculations.
SEPT5:
Use the office button and then select save button or ctrl+S and a
dialogue box will open choose a suitable file name text box and then click
save button. Now select close button or press Alt+F4.
Result
Thus the Calculation using formula editor in excel sheet is performed in
MS-excel.
33
34
Ex No: 06 MS EXCEL SORTING AND IMPORT/
Date :
EXPORT FEATURES
Aim
To sort set of data and import/export it using MS Excel worksheet
Procedure
Step 1: To import the data
i. Create a table named by using MS access. Save it
into a known location.
ii. To open MS Excel
iii. Type the following data in excel worksheet
Result:
Thus the imported and export features of sorted MS Excel are
implemented successfully using MS access.
35
36
Ex No: 07
INCLUSION OF OBJECT, PICTURE
Date : AND GRAPHICS, PROTECTING
THE DOCUMENT AND SHEET
Aim:
To include an object, picture and protect a MS excel worksheet.
Procedure:
A. To Include an object
Step 1: Include an object . Select Start Search and the click
required
***.bmp to identify the location of particular object file.
Step 2: Select insert the object and create from file, browse
and then choose object.
Step 3: Select file name is included into a particular cell.
B. To include a picture
Choose insert and then picture and then click insert.
C. To protect the sheet
Click review and then protect sheet and then enter password
and re enter password and click OK
Step 4: Report Sheet
Click Review and then click unprotected sheet and enter the
password
Result:
Thus the object, pictures which are to be inserted on the sheet
is protected and unprotected by using MS-Excel
37
38
Ex.no:
Date : FLOWCHART
AIM:
To prepare the flowchart in Microsoft word to find sum of first 100 natural numbers.
ALGORTHIM :
Step 1: Start
Step 2: Open a new document and click the insert menu
Step 3: Then click the shapes options and then click the different symbols in the
Flowchart option to draw a flow chart.
PROCESS :
39
OUTPUT :
40
Decision A decision or branching point
41
FLOWCHART :
42
RESULT :
Thus the flowchart to find the sum of 100 natural numbers was successfully drawn in
MS-WORD
43
44
EX.NO: PROGRAM USING DIFFERENT
DATE : OPERATORS
AIM:
Towritea Cprogram todemonstratethe useof different typesof operators.
ALGORITHM:
Step 1: Start the program
Step 2: Declare variables for demonstration
Step 3: Perform operations using different types of operators:
Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
Increment/Decrement Operators
Ternary Operator
Sizeof Operator
Step 4: Display the results.
Step 5: Stop the program.
45
46
PSEUDO CODE:
STEP 1: BEGIN
STEP 2: Declare variables: a, b, result
STEP 3: Perform Arithmetic operations (+, -, *, /, %)
STEP 4: Perform Relational operations (>, <, >=, <=, ==, !=)
STEP 5: Perform Logical operations (CC, ||, !)
STEP 6: Perform Bitwise operations (C, |, ^, <<, >>)
STEP 6: Perform Assignment operations (=, +=, -=, *=, /=, %=)
STEP 7: Use Increment and Decrement operators (++ and --)
STEP 8: true_value : false_value)
STEP 9: Use sizeof operator to check the size of variables
STEP 10: Display results
STEP 11: END
47
FLOWCHART:
Start
Declare variable
Initialize variable
End
48
PROGRAM 1:
#include <stdio.h>
int main() {
int a = 10, b = 5;
// Arithmetic Operators
printf("Arithmetic Operators:\n");
printf("a + b = %d\n", a + b);
printf("a - b = %d\n", a - b);
printf("a * b = %d\n", a * b);
printf("a / b = %d\n", a / b);
printf("a %% b = %d\n\n", a % b); // %% prints %
// Relational Operators
printf("Relational Operators:\n");
printf("a == b: %d\n", a == b);
printf("a != b: %d\n", a != b);
printf("a > b: %d\n", a > b);
printf("a < b: %d\n", a < b);
printf("a >= b: %d\n", a >= b);
printf("a <= b: %d\n\n", a <= b);
// Logical Operators
printf("Logical Operators:\n");
printf("(a > b) && (b > 0): %d\n", (a > b) && (b > 0));
49
50
printf("(a < b) || (b > 0): %d\n", (a < b) || (b > 0));
printf("!(a == b): %d\n\n", !(a == b));
// Bitwise Operators
printf("Bitwise Operators:\n");
printf("a & b: %d\n", a & b);
printf("a | b: %d\n", a | b);
printf("a ^ b: %d\n", a ^ b);
printf("~a: %d\n", ~a);
printf("a << 1: %d\n", a << 1);
printf("a >> 1: %d\n", a >> 1);
return 0;
}
PROGRAM 2:
#include <stdio.h>
int main() {
int x = 10, y = 5, result;
// Assignment Operators
printf("Assignment Operators:\n");
result = x;
printf("result = x: %d\n", result);
result += y;
printf("result += y: %d\n", result);
result -= y;
printf("result -= y: %d\n", result);
51
52
result *= y;
printf("result *= y: %d\n", result);
result /= y;
printf("result /= y: %d\n", result);
result %= y;
printf("result %%= y: %d\n\n", result);
// Increment/Decrement Operators
printf("Increment/Decrement Operators:\n");
printf("x before increment: %d\n", x);
printf("++x: %d\n", ++x);
printf("x after increment: %d\n", x);
printf("--x: %d\n\n", --x);
// Ternary Operator
printf("Ternary Operator:\n");
int min = (x < y) ? x : y;
printf("Smaller number between x and y: %d\n\n", min);
// sizeof Operator
printf("sizeof Operator:\n");
printf("Size of int: %lu bytes\n", sizeof(int));
printf("Size of float: %lu bytes\n", sizeof(float));
printf("Size of double: %lu bytes\n", sizeof(double));
printf("Size of char: %lu bytes\n", sizeof(char));
return 0;
}
53
OUTPUT 1:
OUTPUT 2:
54
RESULT:
The program successfully demonstrates the use of different
types of operator.
55
56
EX.NO:
ODD OR EVEN
DATE :
AIM:
To write a c program to find given number odd or even.
ALGORITHM:
Step 1: Start.
Step 2: Assign x as an integer variable.
Step 3: Read the value of x.
Step 4: If x%2 = = 0.
Step 5: Display the number you enter as input is even.
Step 6: Else, display the number you entered as input is odd.
Step 7: Stop.
57
58
PSEUDO CODE:
Step 1: BEGIN
Step 2: PRINT "Enter a number: "
Step 3: READ number
Step 4: CHECK if the number is divisible by 2 IF
(number MOD 2 == 0) THEN
Step 5: PRINT "The number is even." ELSE
Step 6: PRINT "The number is odd."
ENDIF
Step 7: END
59
FLOW CHART:
START
IF
X%2==0
STOP
60
PROGRAM:
else
printf("the number you entered as a input is odd");
return 0;
}
61
OUTPUT:
62
RESULT:
The above c program used to find whether the given number is odd or
even is executed and verified.
63
64
EX.NO :
CALCULATOR
DATE :
AIM:
To write a C program to create a calculator.
ALGORITHM:
Step 1 : Start
Step 2 : Display a message to enter an operator (+, -, *, /).
Step 3 : Read the operator.
Step 4 : Display a message to enter two numbers.
Read num1 and num2.
Step 5 : Use a switch statement to perform the corresponding operation:
(i) Case '+': Compute num1 + num2 and display the result.
(ii) Case '-': Compute num1 - num2 and display the result.
(iii) Case '*': Compute num1 * num2 and display the result.
(iv) Case '/':
If num2 != 0, compute num1 / num2 and display the result. Else,
display an error message for division by zero.
Default: Display an invalid operator message.
(v)
Step 6 : End
65
66
PSEUDOCODE:
Step 1: BEGIN
Step 2: READ operator
Step 3: READ
num1,num2
STEP 4: SWITCH
(operator)
Case '+': PRINT num1 +
num2 Case '-': PRINT
num1 - num2 Case '*':
PRINT num1 * num2 Case
'/':
STEP 5: IF num2 THEN
PRINT num1 / num2
ELSE
PRINT "Error! Division by
zero." ENDIF
STEP 6: DEFAULT: PRINT "Invalid
operator!" END SWITCH
Step 7: END
67
FLOWCHART :
68
PROGRAM:
#include <stdio.h>
int main() {
char operator;
double num1, num2, result;
printf("Enter an operator (+, -, *, /): ");
scanf(" %c", &operator);
printf("Enter two numbers: ");
scanf("%lf %lf", &num1, &num2);
switch(operator) {
case '+':
result = num1 + num2;
printf("Result: %.2lf\n", result);
break;
case '-':
result = num1 - num2;
printf("Result: %.2lf\n", result);
break;
case '*':
result = num1 * num2;
printf("Result: %.2lf\n", result);
break;
case '/':
if (num2 != 0)
69
70
result = num1 / num2;
else {
printf("Error! Division by zero is not allowed.\n");
return 1;
}
printf("Result: %.2lf\n", result);
break;
default:
printf("Invalid operator!\n");
return 1;
}
return 0;
}
71
OUTPUT:
72
RESULT:
The above C program to create a calculator is successfully
executed and verified.
73
74
EX.NO:
GRADING FOR STUDENT MARKS USING
DATE :
CONTROL STATEMENTS
AIM:
To write a C program to check grade of a student and display the
division.
ALGORITHM:
STEP 1: Start
STEP 2:Input the student's marks
STEP 3: Check conditions:
If marks 90, print "Grade: A"
Else if B" Else if
"Grade: C" Else if marks
60, print "Grade: D" Else
print "Grade: E" Else, print "Grade: F
(Fail)"
STEP 4: End
75
76
PSEUDOCODE:
Step 1: BEGIN
Step 2: PRINT "Enter your marks: "
Step 3: READ marks
Step 4: IF marks >= 90 THEN PRINT "Grade: A"
77
FLOWCHART:
Start
Input marks
Yes
Grade: A
No Yes
Grade: B
No Yes
Grade: C
No
Yes Grade: D
Yes
Grade: E
No
Grade: F (Fail) End
78
PROGRAM:
#include <stdio.h>
int main() {
int marks;
printf("Enter your marks: ");
scanf("%d", &marks);
if (marks >= 90) {
printf("Grade: A\n");
} else if (marks >= 80) {
printf("Grade: B\n");
} else if (marks >= 70) {
printf("Grade: C\n");
} else if (marks >= 60) {
printf("Grade: D\n");
} else if (marks >= 50) {
printf("Grade: E\n");
} else {
printf("Grade: F (Fail)\n");
}
return 0;
}
79
OUTPUT:
80
RESULT:
The above C program to find the grade of a student and
display the division is successfully executed and verified.
81
82
EX NO :
DATE :
SUM OF FIRST N NATURAL NUMBERS
AIM:
To write a C program to find the sum of first n natural numbers.
ALGORITHM:
Step 1: Start.
Step 2: Input: Read an integer N from the user.
Step 3: Initialize: Set sum=0.
Step 4: Loop: Use a loop from i=1 to N: Add i to
sum in each iteration.
Step 5: Output: Print the final value of sum.
Step 6: End.
83
84
PSEUDOCODE:
Step 1: Begin
Step 2: Declare N, sum, i as integer,
Step 3: Print "Enter a positive integer:"
Step 4: Read N
Step 5: Set sum = 0
Step 6: For i from 1 to N
do sum = sum + i
Step 7: Print "Sum of first", N, "natural numbers is:", sum
Step 8: End
85
FLOWCHART:
86
PROGRAM:
#include <stdio.h>
int main()
{
int N, sum = 0;
printf("Enter a positive integer: ");
scanf("%d", &N);
for (int i = 1; i <= N; i++)
{
sum += i;
}
printf("Sum of first %d natural numbers is: %d\n", N, sum);
return 0;
}
87
OUTPUT :
88
RESULT:
The above C program to find the sum of first n natural numbers is
successfully executed and verified.
89
90
EX NO :
FACTORIAL OF A NUMBER
DATE :
AIM :
To write a C program to find the factorial of a given number.
ALGORITHM :
Step 1 : Start
Step 2 : Declare an integer variable n for input and fact for storing the
factorial result.
Step 3 : Initialize fact = 1
Step 4 : Input the value of n from the user.
Step 5 : Check if n < 0
If n is negative, print "Factorial is not defined for negative numbers"
and exit.
Step 6 : Loop from i = 1 to n Multiply fact by
i
Step 7 : End Loop
Step 8 : Print the factorial value stored in fact
Step 9 : End
91
92
PSEUDOCODE :
Step 1: Begin
Step 2: Print "Enter a number:"
Step 3: Read N
Step 4: If N = 0 or N = 1 then
factorial = 1
Step 5: Else
Set factorial = 1
Step 6: For i from 1 to N do
factorial = factorial * i
Step 7: End for
Print "Factorial of", N, "is", factorial
Step 8: End
93
FLOWCHART :
Start
Declare n,i
Read n
Declare i
Print Factorial is not
defined for negative
numbers
while i<=n
fact *=i
i++
Print fact
Stop
94
PROGRAM :
#include <stdio.h>
int main()
{
int n;
unsigned long long fact = 1;
printf("Enter a number: ");
scanf("%d", &n);
if (n < 0) {
printf("Factorial is not defined for negative numbers.\n");}
else {
int i = 1;
while (i <= n) {
fact *= i;
i++;
}
printf("Factorial of %d = %u\n", n, fact);
}
return 0;
}
95
OUTPUT :
96
RESULT :
Thus the C program to find the factorial of a given number is
successfully executed and verified.
97
98
EX NO :
REVERSE OF A NUMBER
DATE :
AIM :
To write a C program to find the reverse of a given number.
ALGORITHM :
Step 1 : Start
Step 2 : Declare integer variables num, reversed = 0, and remainder.
Step 3 : Input the number num from the user.
Step 4 : Do the following steps at least once:
Extract the last digit using remainder = num % 10.
Append the digit to reversed using reversed = reversed
* 10 + remainder.
Remove the last digit from num using num = num / 10.
Step 5 : Repeat the above steps until num becomes 0.
Step 7 : End
99
100
PSEUDOCODE :
Step 1: Begin
Step 2: Declare num, reversed, remainder as integer
Step 3: Set reversed = 0
Step 4: Print "Enter a number: "
Step 5: Read num
Step 6: do
Set remainder = num mod 10
Set reversed = (reversed * 10) + remainder
Set num = num / 10
Step 7: While num > 0
Print "Reversed Number = ", reversed
Step 8: End
101
FLOWCHART :
Start
Read num
Initialise reversed = 0
DO
reminder = num%10
reversed = reversed*10+reminder
num=num/10
Print reversed
Stop
102
PROGRAM :
#include <stdio.h>
int main() {
int num, reversed = 0, remainder;
printf("Enter a number: ");
scanf("%d", &num);
do {
remainder = num % 10;
reversed = reversed * 10 + remainder;
num /= 10;
} while (num != 0);
printf("Reversed Number = %d\n", reversed);
return 0;
}
103
OUTPUT :
104
RESULT :
Thus the C program to find the reverse of a given number is
successfully executed and verified.
105
106
EX NO: FINDING THE SUM OF
DATE : ELEMENTS OF AN ARRAY
AIM :
To write a C program to find the sum of the elements of an array.
ALGORITHM :
Step 1 : Start
Step 2 : Initialize an array of integers with some values.
Step 3 : Initialize a variable sum to 0. This will hold the sum of the array
elements.
Step 4 : Calculate the size of the array. (You can do this using sizeof in C to
get the total size of the array and divide it by the size of one
element.)
Step 5 : Loop through the array from index 0 to the last index.
For each iteration, add the current element to sum.
Step 6 : After the loop finishes, display the value of sum, which now contains
the total of all the array elements.
Step 7 : End.
107
108
PSUEDOCODE :
Step 1 : Start
Step 2 : Declare an array arr of size n
Step 3 : Initialize sum = 0
Step 4 : For i = 0 to n-1 do:
Step 5 : sum = sum + arr[i]
Step 6 : End For
Step 7 : Print sum
Step 8 : End
109
FLOWCHART :
110
PROGRAM :
#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 5};
int sum = 0;
int size = sizeof(arr) / sizeof(arr[0]);
for (int i = 0; i< size; i++) {
sum += arr[i];
}
printf("The sum of the array elements is: %d\n", sum);
return 0;
}
111
OUTPUT :
112
RESULT :
Thus the C program to find the sum of elements if an array is successfully
executed and verified.
113
114
EX NO :
DATE :
REVERSE OF A STRING
AIM :
To write a C program to find the reverse of a string.
ALGORITHM :
Step 1 : Start
Use the strlen() function to get the length of the string and store it in
length.
Loop through the string from the last character (i.e., index length-1)
to the first character (index 0).
Print each character in reverse order.
Step 7 : End
115
116
PSEUDOCODE :
Step 1 : BEGIN
READ str
END IF
PRINT str[i]
END FOR
PRINT newline
END
117
FLOWCHART :
118
PROGRAM :
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
printf("Enter a string: ");
if (fgets(str, sizeof(str), stdin) == NULL) {
printf("Error reading input!\n");
return 1;
}
str[strcspn(str, "\n")] = '\0';
if (strlen(str) == 0) {
printf("Empty string! Exiting program.\n");
return 1;
}
int length = strlen(str);
printf("Reversed string: ");
for (int i = length - 1; i >= 0; i--) {
printf("%c", str[i]);
}
printf("\n");
return 0;
}
119
OUTPUT :
120
RESULT :
Thus the C program to find the reverse of a string is successfully executed
and verified.
121
122
EX.NO:
DISPLAYING ARRAY ELEMENTS WITH
DATE : POINTER
AIM:
To write a c program on function with pointer.
ALGORITHM:
Step1: Define a function display() that takes a pointer to an array.
Step2: Inside the function, initialize a pointer to the start of the array.
Step3: Traverse the array using a while loop until all elements are printed.
Step4: Print each element and move the pointer to the next position.
Step5: Return to the main program after complete.
123
124
PSEUDOCODE:
Step 1 : Function Display(pointer, size):
Step 2 : Initialize i = 0
Step 3 : While i is less than size:
Step 4 : Print value at (pointer + i)
Increment i by 1
Step 5 : Print a newline
Step 6 : Declare an array with values [10, 20, 30, 40, 50]
Step 7 : Print "Array elements: "
Step 8 : Call Display function with array and size as arguments
Step 9 : End Program
125
FLOWCHART:
126
PROGRAM:
#include <stdio.h>
void display(int *pointer, int size)
{
int i = 0;
while (i < size)
{
printf("%d ", *(pointer + i));
i++;
}
printf("\n");
}
int main()
{
int arr[] = {10, 20, 30, 40, 50};
127
OUTPUT:
128
RESULT:
The program for displaying array elements with pointer was executed
successfully.
129
130
EX NO:
FUNCTION WITH ARRAY
DATE:
AIM:
To write a c program to calculate factorial using array with function.
ALGORITHM:
Step 1: Start.
Step 2: Read a number n, Initialize variables:
i = 1, fact = 1
Step 3: if i <= n go to step 4 otherwise go to step 7.
Step 4: Calculate
fact = fact * i
Step 5: Increment the i by 1 (i=i+1) and go to step 3.
Step 6: Print fact.
Step 7: Stop.
131
132
PSEUDOCODE:
Step 1: BEGIN
Step 2: FUNCTION factorial(n):
SET fact=1
FOR i = 1 to n:
fact = fact * i
Step 3: END FOR
RETURN fact
END FUNCTION
Step 4: PRINT "Enter the number of elements: "
READ n
Step 5: CREATE an array arr of size n
PRINT "Enter n numbers:"
FOR i = 0 to n-1:
READ arr[i]
Step 6: END FOR
PRINT "Factorials:"
FOR i = 0 to n-1:
Step 7: PRINT "Factorial of arr[i] = factorial(arr[i])"
END FOR
Step 8: END
133
FLOWCHART:
134
PROGRAM:
#include <stdio.h>
long long factorial(int n)
{
long long fact = 1;
for (int i = 1; i <= n; i++)
{
fact *= i;
}
return fact;
}
int main()
{
int n;
int arr[n];
printf("Enter %d numbers:\n", n);
135
136
for (int i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
return 0;
}
137
OUTPUT:
138
RESULT:
The program for displaying factorial using function with array was
executed successfully.
139
140
AIM:
To write a C program for student information using structures.
ALGORITHM:
Step 1: Start
Step 2: Define a structure named "student" with
141
142
PSEUDO CODE:
Step 1: Define a structure Student:
- name (string)
- fund (float)
Initialize totalFunds to 0
Initialize maxFund to 0
Initialize maxIndex to 0
Read name
Read fund contributed
- Roll number
- Name
- Fund contributed
143
FLOWCHART:
144
PROGRAM:
#include <stdio.h>
#include <string.h> // Include string.h for strcspn function
struct student {
int rollno;
char name[50];
float fund;
};
int main() {
struct student students[5];
float totalFunds = 0;
float maxFund = 0;
int maxIndex = 0;
totalFunds += students[i].fund;
return 0;
}
145
OUTPUT:
146
RESULT:
The above C program for the implementation of student information using
structures was successfully executed and verified
147
148
149
150
151
152
153
154
155
156
157
158
159
160
EX NO:
STORE AND PRINT DATA FROM FILE
DATE:
AIM:
To write a C program for file manipulation.
ALGORITHM:
Step-1: Start
Step-2: Open file in write mode
Step-3: Read data of the console upto end of the line
Step-4: Write data into the file
Step-5: Close file
Step-6: Open file in read more
Step-7: Read data in the file upto EOF
Step-8: Display data into the screen
Step-9: Close file
Step-10: Stop
161
162
PSEUDO CODE:
Step 1: BEGIN
Step 2: DECLARE file pointer fp
Step 3: DECLARE character variable c CLEAR the screen
Step 4: OPEN a file named "TEXT" in write mode
Print "Enter text:"
Step 5: Repeat
Read character c from user input
Step 6: If c is not newline character
Write character c to file
Until c is newline character
Close the file
Step 7: Print"Displaying text from file:"
Step 8: Open the file "TEXT" in read mode
Step 9: While not end of file
Step 10: Read character c from file
Step 11: Print character c
Step 12: End while
163
FLOWCHART:
Start
Open file(w)
If end of line
Display
Close file
Close file
Open file(r)
Stop
If end of line
164
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *fp;
char c;
system("cls");
fp = fopen("TEXT.txt", "w");
if (fp == NULL) {
printf("Error opening file for writing.\n");
return 1;
}
165
OUTPUT:
166
RESULT:
The C program to store and print same data to and from the file is
successfully executed and verified.
167