No: 1a
Date:
DOCUMENT CREATION AND TEXT FORMATTING
AIM:
To create a Word document according to the given specification.
EXERCISE:
I Open a new document and perform the following task.
1) Justify the text.
2) Make some of the text as bold type.
3) Correct the spellings
4) Underline and make italic style for some word.
5) Save the document with the suitable date.
II How can you do the following alignment feature?
Velammal institute of Technology (Left align)
Velammal institute of Technology (Right align)
Velammal institute of Technology (Center align)
III Add any two bullets and two numbering schemes for the following text.
PROCEDURE:
DOCUMENT CREATION
I DOCUMENT MANIPULATION:
To open a word document:
Step 1: To create the document, select Application->Office->Openoffice.org word
processor/ LibreOffice Writer, and save the document with extension.doc
Step 2: To select File->New->Text Document.
To justify the text:
Step 1: Open Open Office Writer
Step2: Click Insert and then click Frame
Step3: In the Frame window under type, change the horizontal and vertical position to
center and both to "Entire page."
Step4: Because the frame has borders, unless you want to keep these borders click the
borders tab and click None under Style.
Step5: Once this has been done you'll have a frame in the center of your page, which
allows you to enter any text you want and have it centred in the middle of your
page.
To Format a Text:
Step 1: Create a new document (choose File > New > Text Document or press Control
+ N).Type Heading 1 in it. Make sure that the cursor remains in that same line.
Step 2: Click the Styles and Formatting icon located on the Formatting Bar or press
the F11 key. This opens the Styles and Formatting window.
Step 3: Make sure the window is showing the Paragraph Styles section (click on the top
left icon of the Styles and Formatting window ).
You can select styles from this menu, just like with the Styles and Formatting
window. As an exercise, press Enter, type some text and select Heading 1 in the Apply
Styles list. The text acquires the properties of the Heading 1 style.
Modifying a style.
When the Paragraph Style window opens, choose the Alignment tab, select Center, and
click OK.
Center Heading 1.
Now, everything marked as Heading 1 will be centered. If you make another Heading
1 entry, it will be centered as well.
Set indentation.
Linked styles.
As an example, suppose you want to change the font of not only Heading 1, or Heading
2, but all headings. The easiest way to do that is to take advantage of this linking. Open
the Styles and Formatting window (press F11) and select Heading.
Step 9: Now, the fonts of all the heading styles have been changed in a single operation.
Your document should now resemble the illustration below.
Step4: Choose the required Bullet format from the bullet tab for bullets.
Step5: Choose the required number series from the numbered tab in the Bullets and
Numbering dialog box.
Line spacing:
Step 1: Select the text and go to the Format menu and Select Paragraph.
Step2: A paragraph dialog box appears. Select the 1.5 lines from the line spacing list box
then click OK.
Step3: Now the 1.5 line spacing is applied to the selected paragraph.
Font Types and sizes:
Step 1: Select the text to change with different font types and sizes.
Step 2: Then choose Character option from the Format menu and a font dialog box will
appear.
Step 3: Choose the required Font type from Font drop down list box and the required size
from the size list box then click OK.
Step 4: Now selected text is displayed with different font types and sizes.
OUTPUT:
DOCUMENT CREATION
Data:
Information:
The process data is called the information.
The information comes in various steps and sizes depending upon the application.
Computer can store, process and retrieve such data or information as and when required.
ALIGNMENT FEATURES
VELAMMAL INSTITUTE OF TECHNOLOGY
VELAMMAL INSTITUTE OF TECHNOLOGY
VELAMMAL INSTITUTE OF TECHNOLOGY
VELAMMAL INSTITUTE OF TECHNOLOGY
BULLETS AND NUMBERING FORMAT
RESULT:
Thus the document has been created and also text formatting has been performed in
OpenOffice.org word processor / LibreOffice Write.
Ex No: 1b
Date:
TEXT MANIPULATION AND SCIENTIFIC NOTATION
AIM:
To Create a word document with the given formulas and specifications
EXERCISE:
PROCEDURE:
TEXT MANIPULATION WITH SCIENTIFIC NOTATION
TEXT MANIPULATION:
DOCUMENT CREATION:
Step 1: To create the document, select Application->Office->Openoffice.org word
processor/ LibreOffice Writer, and save the document with extension.doc
Step 2: To select File->New->Text Document.
Step 3: To type the text in the document with the following options.
FORMATTING TEXT:
Font
Font Size
Bold/Italic / Underline
Font Color
Highlighting and changing text color
Alignment(Left/right/Centre/Justify)
Bullets and Numbering
Header and Footer
Step 4: To open a new formula windows, Application->Office-> OpenOffice.org word
processor, then select File->New->Formula (OR) Application->Office->
LibreOffice Math.
Step 5: Choose the formula elements in view menu. View->Elements.
Step 6: Select the corresponding formula in Elements and create new formula.
OUTPUT:
FORMULAS AND EQUATIONS
A)
Ca (HCO3)2 CaCO3+CO2+H2O
B)
(A+B)2=A2+B2+2AB
C)
ax
x=
4ab 10
2abc
D)
m
Pr x j T
j 0
E)
X1
m
X j T X 2
j 0
X
3
RESULT:
Thus the document has been created and also text manipulation with scientific notation
has been performed in OpenOffice.org word processor / LibreOffice Write.
Ex No: 1c
Date:
TABLE CREATION TABLE FORMATTING AND CONVERSION
AIM:
To create a word document with the given table structure and perform necessary
manipulations in the table.
EXERCISE:
Create a Time Table for your class.
PROCEDURE:
TABLE CREATION, TABLE FORMATTING
To open a word document
Step 1: To create the document, select Application->Office->Openoffice.org word
processor/ LibreOffice Writer, and save the document with extension.doc
Step 2: To select File->New->Text Document.
To create a Table
Step 3: To insert a table select, TableInsert Table option. Enter the required number
of rows and columns in the Insert Table dialog box and click Ok.
Step 4: To merge rows in the table select the required rows and Choose TableMerge Cells
option. Similarly to merge the columns in the table select the required columns and
Choose Table Merge Cells option.
Step 5: To split the cells, select the cell and Choose Table Split Cells option. To Specify
the number(number of cells to be splitted) and
direction(Horizontal(rows),Vertical(column)) in the Split Cell dialog box.
Step 6: To insert borders and shading, select the TableTable PropertiesBorder option.
Choose the required style and click ok.
To Sort
Step 7: To sort the text, select TableSort option. Specify the order(ascending or
descending) and select the direction of sorting and click ok.
To Format table
Step 8: To specify the styles to table, select the Table Table AutoFormat option. Select
the required style from the Table styles list and click Apply.
To Convert table form
Step 9: To convert the text into table, select the required text and choose TableConvert
Text to Table option separate text option(choose any options) and click Ok.
Finally text will be converted to table.
Step10: To convert the table into text, select the required table and choose Table ->
Convert ->Table to Text option-> separate text option(choose any options) and
click Ok. Finally table will be converted to text
OUTPUT:
TABLE CREATION
RESULT:
Thus the table creation, formatting and conversion has been performed using OpenOffice
word processor / LibreOffice Writer.
Ex.No:1d
Date:
CREATING MAIL MERGE USING OPENOFFICE.
AIM:
To create a form letter is the manual method described in creating a Mail Merge wizard.
EXERCISE:
Develop a Mail wizard for College Symposium.
ALGORITHM:
Step 1: Select starting document
The wizard gives various options to select your starting document:
Use the current document.
Create a new document.
Use a template.
Use an existing document.
Select Use the current document and click Next under Select starting document.
3. In the New Address Block dialog, you can add or delete address elements using the
arrow buttons on the left. To move elements around, use the arrow buttons on the
right. For example, to add an extra space between first and last names, click <Last
Name> and then click the right arrow button. New address block
.
Matching the fields
Finally, it is time to match the wizards fields with the spreadsheet fields, so that items
like <Last Name> and Surname match correctly.
1. Look at section 3 of step 3 of the wizard. The box at the bottom displays one record
at a time, using the address block format you selected. Use the right and left arrow
buttons below that address box to step through the addresses, checking that they
display correctly. Do not assume that all the records display correctly, just because
one or two do. Check them all if you can, or at least a good proportion.
2. If the addresses do not display correctly (and they probably will not right away),
click Match Fields. The Match Fields dialog box opens.
Create a salutation.
Adjust layout.
Step 6: Edit document and insert extra fields
Edit document.
You can also edit the body of the document. If you started with a blank document,
you can write the whole letter in this step. Click Edit Document to shrink the wizard to a
small window so you can easily edit the letter.
Personalize document.
As with step 6, when editing the document, the wizard shrinks to small window.
Click on this window to expand the wizard to its full size.
Step 8: Save, print or send
You have now completed the mail merge process. The last step is to do something
with it. In step 8, you can save the original sample letter, save the merged document, print
the letters right away or, if you created email messages, send them.
OUTPUT:
RESULT:
Thus the creation of mail merge wizard has been performed using OpenOffice word
processor / LibreOffice Writer.
Ex.No: 2a
Date:
TABLE CREATION, FORMATTING AND CONVERSION USING OPENOFFICE
CALC.
AIM:
To create a spread sheet with the given table structure and perform necessary
manipulations using open office calc.
EXERCISE:
1) Create a table with the following columns and display the result in separate cells for the
following:
1. Employee Name, Basic pay, DA, HRA, TA, net pay, PF, loan, Gross pay 5 Record
To calculate HRA
Step 1: Place the cursor in the 2nd row of HRA column and type the equation =
c5*20/100. It displays HRA of the first employee and drag the formulas to
remaining rows.
To calculate the Net Pay
Step 1: Place the cursor in the 2nd row of Net Pay column, Click insert ->Function .It
displays a formula dialog box with formula = SUM () and select the data fields
from basic column to TA.
Step 2: Now the Net Pay for the first employee is displayed at the Net Pay column. Now
we can drag the formulas for remaining rows using mouse.
OUTPUT:
TABLE CREATION & CHART
RESULT:
Thus a Spread sheet is created with the given table structure using open office calc.
Ex.No: 2b
Date:
PRESENTATION USING OPENOFFICE IMPRESS.
AIM:
To create a Presentation using open office impress according to the given specification.
EXERCISE:
Open power point
Add titles and sub titles.
Add new slides
Insert Clip arts.
Apply Design Templates
Modify Background and transitions
Run the slide show
PROCEDURE:
CREATING A PRESENTATION:
1) To create a new presentation, go to applicationsopen office impress then in the
first wizard select empty presentation.
3) In the third wizard choose slide transition effects. And then click on create.
SAVING A PRESENTATION:
To save a presentation, go to file menu, click on save option.
ADDING CLIP ART PICTURES:
We can add pictures to our PowerPoint presentation from insert option, go to picture and
select the picture we want to be pasted.
FORMATTING TEXT:
Select the text we wish to format. Make the formatting changes by using the font and the
paragraph below.
INSERTING TEXT BOX AND TEXT FORMATTING:
To insert a text box from the draw function and then choose text box option.
CHANGING THE FILL COLOUR OF THE TEXT BOX:
Select the text box and then Choose color option we want to set as the background of the
textbox.
CHANGING TEXT COLOUR:
Select the text box and choose format tab as shown. In the format tab, select the text fill
option. Then choose the color of the text.
PRESENTING THE SLIDE SHOW:
We can preview our slide presentation in the slide show view.
OUTPUT:
RESULT:
An effective and elegant presentation about the computer using open office impress is
created.
Ex.No:3
Date:
FLOWCHARTS
AIM:
To draw a flow chart in open office draw tool.
EXERCISE:
i)
Draw a Flow chart for greatest among 3 numbers using open office draw.
ii)
Draw a Flow chart for Student mark details using open office draw.
i) PROCEDURE:
DRAWING AND FLOWCHARTS
Step 1: Create Open office window by choosing
Application
Office
Open office.org.draw
Step 2: Open a new document using File
New option
Step 3: Choose flow chart option in the basic shape icon of the drawing tool bar.
Step 4: The oval shaped symbol always begins and ends the flowchart. The start symbol will
have only one flow file but not entering line flow line. The stop symbol will have a
entering flow line but not exit.
Step 5: Type start in the symbol, by right click, then choose ADD text.
Step 6: Use the arrow Button, line style button arrow style in the drawing toolbar draw the
lines connecting to the different flow chart symbol .These are left to right or top to
bottom lines connecting symbol. These line show flow of control thought the
program. The flow lines indicate the exact sequence in which the instructions are
executed.
Step 7: Choose the process symbol from the flow chart option. The rectangle symbol is used
primarily for calculations and initialization of memory locations. All the arithmetic
operation, data movements, initialization operations.
Step 8: Declare the variable mark1,mark2,mark3,total,avg of using symbol.
Step 9: Select the Input / Output symbol and drag it in the document. The parallelogram is
used both for input and output(read and write).
Step 10: Enter read mark1,mark2,mark3 in the symbol and connect it with the next by
using arrows.
Step 11: Select the process symbol as mentioned earlier enter total=mark1+mark2+mark3
Avg = total / 3.
Step 12: Select the decision symbol the diamond shaped symbol is used in flowchart to
indicate at a point at which a decision has to be made and a branch to one of two or
more alternative point is possible. There will be always two exits from a decision
symbol one is labeled yes and other as no.
Step 13: Enter the text in the decision symbol and connect it with two arrows heads. One
arrow head represent yes and the other no.
Step 14: To add text in the decision box flow lines place the cursor in the flow line and then
click add text. Then right click the text box in the select format text box. In the
dialog box select color as no color and click ok. The text will be displayed.
Step 15: Check the avg 75 .If the condition is true. Display the grade as distinction by
using input / output symbol otherwise connect it with the next symbol.
Step 16: Check the condition if avg < 75 && 60 .If the condition is true. Display the
grade as first class by using Input / Output symbol. Connect it with the next symbol.
Step 17: Check the condition avg < 60 && 50 .If the condition is satisfied .Display the
grade as II nd class by using Input / Output symbol displaying fail.
Step 18: Terminate the flow chart by using a terminal symbol and connecting the output
with the help of flow lines.
ii) PROCEDURE:
Step 1: Create Open office window by choosing
Application
Office
Open office.org.draw
Step 2: Open a new document using file
New option
Step 3: Choose flow chart option in the basic shape icon of the drawing tool bar.
Step 4: Choose the appropriate flowchart symbol. then drag then in the document .
Step 5: Type the text in the symbol, by double click.
Step 6: Type start in the symbol, by double click.
Step 7: Initialize the variable a, b, c by entering the text in the process symbol. Connect it to
the next symbol with the help of flow line.
Step 8: Enter read a,b,c in the input / output symbol
Step 9: Enter the text if a>b <c b>c in the decision box and connect the flow chart to the
corresponding symbol.
Step 10: Check the condition if a>b<c b>c.If the condition is true .Display a is greater by
using input / output symbol other wise connect it with the next symbol
Step 11: Check the condition if b>c. If the condition is true. Display b is greater else display
c is greater by using input / output.
Step 12: Terminate the flowchart by using terminate symbol and connecting the output with
the help of flow lines.
OUTPUT:
start
int m1,
m2, m3,
tot,avg
Read
m1,m2,
m3
Tot=m1+m2+m3
Avg=tot/3
Yes
No
If
avg>=7
5
Ye
s
If avg<75
&&
avg>60
No
No
Destinctio
n
Fail
Stop
If
avg<60
&&
avg>=5
0
Second
class
Yes
First
class
Start
Int a, b, c
Read
a, b, c
Yes
No
If a>b
&& a>c
Yes
If
b>c
No
C is
greater
A is
greater
B is
greater
Stop
RESULT:
Thus a Open office document is created and a flowchart to display the grade of a student
marks list and greatest of 3 numbers is drawn.
Ex.No: 4a
Date:
CONVERTING THE GIVEN TEMPERATURE IN FAHRENHEIT TO CELSIUS.
AIM:
To write a C program for converting the given temperature in Fahrenheit to Celsius.
ALGORITHM:
Step 1: Start the program.
Step 2: Read the temperature in Fahrenheit (f).
Step 3: Temperature in Celsius (c) = 5/9*(f-32).
Step 4: Print Temperature in Celsius.
Step 5: Stop
PSEUDOCODE:
READ the value of f
COMPUTE c by multiplying 5/9 to (f-32)
PRINT c
STOP
FLOW CHART:
PROGRAM:
#include<stdio.h>
void main()
{
float f,c;
printf(Enter temperature in Fahrenheit:);
scanf(%f,&f);
c= 5.0/9.0 *(f-32);
printf(Given Temperature in Celsius:%f,c);
}
OUTPUT:
Enter temperature in Fahrenheit: 113
Given Temperature in Celsius: 45.000000
RESULT:
Thus, a C program for converting the given temperature in Fahrenheit to Celsius was
successfully executed and its output was verified.
EX NO: 4b
DATE :
AREA AND CIRCUMFERENCE OF CIRCLE.
AIM:
To write a C program to find the area and circumference of circle.
ALGORITHM:
Step 1: Start.
Step 2: Read the value of Radius of circle (r).
Step 3: Circumference of circle (c) = 2 * 22/7 * r.
Step 4: Area of circle (a) = 22/7 *r * r.
Step 5: Print circumference and Area of circle.
Step 6: Stop.
PSEUDOCODE:
READ the values of r.
COMPUTE 2* 22/7*r and store it's value in c.
COMPUTE 22/7*r*r and store it's value in a.
PRINT the values of c and a.
STOP
FLOW CHART:
PROGRAM:
#include<stdio.h>
void main()
{
float r,c,a;
printf(Enter the radius of circle\n);
scanf(%f,&r);
c=2.0*22.0/7.0*r;
a= 22.0/7.0*r*r;
printf(Circumference of circle: %f , c);
printf(\nArea of circle: %f ,a);
}
OUTPUT:
Enter the radius of circle 5
Circumference of circle: 78.500000
Area of circle: 31.400000
RESULT:
Thus a C program to find the area and circumference of circle was successfully executed
and its output was verified.
Ex.No: 4c
Date:
FIND THE AVERAGE OF THREE NUMBERS.
AIM:
To write a C program to find the average of three numbers.
ALGORITHM:
Step 1: Start.
Step 2: Read the values of num1, num2, num3.
Step 3: Total of three numbers (tot) = (num1 + num2 + num3)
Step 4: Average of three numbers (avg) = tot/3.
Step 5: Print the value of avg.
Step 6: Stop.
PSEUDOCODE:
READ the values of num1,num2,num3
COMPUTE (num1+num2+num3) and store it's value in tot
COMPUTE (tot/3) and store it's value in avg
PRINT the value of avg
STOP
FLOW CHART:
PROGRAM:
#include<stdio.h>
void main()
{
int num1,num2,num3, tot;
float avg;
printf(Enter any three numbers:);
scanf(%d%d%d,&num1,&num2,&num3);
tot=num1+num2+num3;
avg=tot/3;
printf(\nTotal of three numbers: %d,tot);
printf(\nAverage of three numbers: %f,avg);
}
OUTPUT:
Enter any three numbers:3
5
6
Total of three numbers:14
Average of three numbers:4.666667
RESULT:
Thus, a C program to find the average of three numbers was successfully executed and its
output was verified.
Ex.No: 4d
Date:
FIND THE SIMPLE INTEREST AND MATURITY AMOUNT.
AIM:
To write C program to find the simple interest and maturity amount.
ALGORITHM:
Step 1: Start.
Step 2: Read the values of principle amount (p), rate of interest(r) and number of
years(n).
Step 3: Interest(i) = (p*n*r)/100.
Step 4: Maturity amount (amt) = p+i.
Step 5: Print the value of amt
Step 6: Stop.
PSEUDOCODE:
READ the values of p,n,r
COMPUTE p*n*r and store it's value in i
COMPUTE p+i and store the result in amt
PRINT the value of amount.
FLOW CHART:
PROGRAM:
#include<stdio.h>
void main()
{
float p,n,r,amt,i;
printf(Enter principle amount(p),number of years(n) and
rate of interest(r)\n);
scanf(%f%f%f,&p,&n,&r);
i=(p*n*r)/100.0;
amt= p+i;
printf(\n Simple Interest:%f,i);
printf(\n Total amount to be paid is:%f,amt);
}
OUTPUT:
Enter principle amount(p),number of years (n) and rate of interest(r)
1000
2
10
Simple Interest:200.000000
Total amount to be paid is:1200.000000
RESULT:
Thus, a C program to find the simple interest and maturity amount was successfully
developed and its output was verified.
Ex.No: 4e
Date:
FIND AREA OF A TRIANGLE WHOSE SIDES ARE A,B AND C.
AIM:
To write a C program to find area of a triangle whose sides are a,b and c.
ALGORITHM:
Step 1: Start.
Step 2: Read the values of sides a, b and c of a triangle.
Step 3: Semi perimeter (s) is given by (a+b+c)/2.
Step 4: Area of triangle (a) is equal to square-root of( s * (s-a)*(s-b)*(s-c) ).
Step 5: Print the value of a.
Step 6: Stop.
PSEUDOCODE:
READ the values of a,b,c
COMPUTE (a+b+c)/2 and store it's value in s
COMPUTE sqrt(s*(s-a)*(s-b)*(s-c) ) and store this value in a
PRINT the value of a
STOP
FLOW CHART:
PROGRAM:
#include<stdio.h>
#include<math.h>
void main()
{
int a,b,c,s;
float a=0.0;
printf(Enter the three sides of triangle:\n);
scanf(%d%d%d,&a,&b,&c);
s=(a+b+c)/2;
a= sqrt((s*(s-a)*(s-b)*(s-c)));
printf(\nArea of triangle is:%f,a);
}
OUTPUT:
Compile: cc filename.c lm
Output: ./a.out
Enter the three sides of triangle:3
4
5
Area of triangle is:6.000000
RESULT:
Thus, a C program to find area of a triangle whose sides are a,b and c was successfully
executed and its output was verified.
Ex.No: 5a
Date:
ELECTRICITY BILL PREPARATION
AIM:
To write a C program for electricity bill preparation.
ALGORITHM:
Step 1: Start.
Step 2: Read strlno, rcptno, billmonth,date,present and previous meter reading.
Step 4: Consumed = present previous.
Step 5: Check if consumed >=200, Total = consumed * 2.50, Total = consumed * 1.50.
Step 6: Print srlno, rcptno, billmonth, date, Print consumed, total.
Step 8: Stop.
PSEUDOCODE :
BEGIN the program by reading the srlno, rcptno, billmonth, date.
READ present and previous meter reading. consumed = present previous.
IF consumed >=200 then total = consumed * 2.50 .ELSE total = consumed * 1.50.
PRINT srlno, rcptno, billmonth, date, consumed, total.
TERMINATE the program
Start
FLOWCHART:
If Consumed>=200
Stop
PROGRAM:
#include<stdio.h>
void main()
{
int present, previous, consumed, strlno;
char name[20], rcptno[10], billmonth[15], date[12];
float total;
clrscr();
printf(\n Enter Serial Number & Receipt Number : );
scanf(%d %s,srlno,rcptno);
printf(\n Enter Bill Month & Date : );
scanf(%s%s,billmonth,date);
printf(Present and Previous readings : );
scanf(%d %d,&present, &previous);
consumed = present previous;
if(consumed >=200)
total = consumed *2.50;
else
total = consumed *1.50;
printf(\n \t ELECTRICITY BILL \n);
printf(\t \t-----------------------------------\n);
printf(\n SC No. %d \t \t Receipt.No: %s \n, srlno, rcptno);
printf(\n Bill Month :%s \t \t date : %s \n,billmonth,date);
printf(\n total cost for consumed %d unit us Rs : %f , consumed, total);
getch();
}
OUTPUT :
Enter Serial Number & Receipt Number: 128 AC1237
Enter Bill Month & Date: 6/2006 15-07-2006
Present and Previous readings: 980 520
ELECTRICITY BILL
SC No. 128
Receipt. No: AC1237
Bill Month: 6/2006
Date: 15-07-2006
Total cost for consumed 460 units is
Rs: 1150.000000
RESULT:
Thus the program for electricity bill is executed and the output is verified.
Ex.No: 5b
Date:
LEAP YEAR
AIM:
To write a C program to find whether a year is a Leap Year or not.
ALGORITHM:
Step 1: Start the program
Step 2: Declare year as int data type
Step 3: Read the year
Step 4: Check if (ye%4)=0
Step 4.1: Print It is a leap year
Step 5: Else
Step 5.1: Print It is not a leap year
Step 6: Stop.
PSEUDOCODE:
Set initial year.
READ the year.
IF(year % 4 == 0) THEN
WRITE the year is leap year.
ELSE
WRITE the year is not a leap year.
ENDIF
Stop
FLOW CHART:
PROGRAM :
#include<stdio.h>
main()
{
int year;
printf (Enter the year \n);
scanf (%d, &year);
if (year%4==0)
printf (It is a leap year: \n);
else
printf (It is not a leap year\n);
}
OUTPUT:
Enter the year: 2000
It is a leap year
RESULT:
Thus the program to find whether a year is leap year has been executed successfully.
Ex.No: 5c
Date:
ODD (or) EVEN
AIM:
To write a program to find whether the number is prime or not.
ALGORITHM:
Step 1: Start the program.
Step 2: Read num.
Step 3: If the number is divided by 2 , print the given number is even .
Step 4: If the number is not divided by 2, print the given number is odd.
Step 5: Stop the program
PSEUDOCODE :
BEGIN the program by entering a number.
READ the given number and check the condition.
IF it is true , print even ELSE odd.
TERMINATE the program.
FLOW CHART:
PROGRAM :
#include<stdio.h>
void main()
{
int num;
printf("Enter the number...");
scanf("%d",&num);
if(num%2==0)
printf("The given number is a Even number");
else
printf("The given number is a Odd number");
}
OUTPUT :
Enter the number5
The given number is a Odd number
RESULT:
The program to find whether the number is even or odd is verified.
Ex.No: 5d
Date:
BASIC MATHEMATICAL OPERATIONS USING SWITCH STATEMENT
AIM:
To write a simple menu driven program using switch statement.
ALGORITHM:
Step 1: start
Step 2: display menu
Step 3: read the two variables a and b
Step 4: enter the option code
Step 5: evaluate option code with case statements
Step 5.1: case =1 c=a+b print c. goto step-7
Step 5.2: case=2 c=a-b print c. goto step-7
Step 5.3: case=3 c=a*b print c. goto step-7
Step 5.4: case=4 c=a/b print c. goto step-7
Step 5.5: case=5 c=0 exit
Step 6: entered case option is invalid code the print invalid operation code
Step 7: stop
PSEUDOCODE:
BEGIN the program by displaying the menu
READ the two variable a and b
ENTER the option code
EVALUATE option code with case constants.
TERMINATE the program.
FLOWCHART:
start
read
Case
1
C=a+b
If
N<=4 &
N>0
Print c
Case
2
C=ab
Read
a,b
Switch
n
Print c
B
Case
3
C=a*
b
Print
c
Case
4
C=a/
b
Print
c
Case
0
A
B
Print invalid
operation code
sto
p
PROGRAM:
#include <stdio.h>
Void main()
{
int a,b,c,n;
printf( \n menu-- );
printf(\n 1 addition);
printf(\n 2 subtraction);
printf(\n 3 multiplication);
printf(\n4 division);
printf(\n enter your choice : );
scanf(%d,&n);
if(n<=4 & n>0)
{
printf(\n enter two numbers);
scanf(%d %d,&a,&b);
}
switch(n)
{
case 1: c=a+b; printf(\n Addition : %d,c); break;
case 2: c=a-b; printf(\n subtraction: %d,c); break;
case 3: c=a*b; printf(\n multiplication: %d,c); break;
case 4: c=a/b; printf(\n division:%d,c); break;
default: printf(\n invalid operation code);
}
}
OUTPUT :
--MENU-1 addition
2 subtraction
3 multiplication
4 division
Enter your choice : 1
Enter two numbers : 8 6
addition: 14
RESULT:
The program is executed and the output is verified.
Ex.No: 5e
Date:
ARMSTRONG NUMBER
AIM:
To write a c program to find the given number is Armstrong number are not.
ALGORITHM:
Step 1: Start
Step 2: Read the value for a.
Step 3: Assign value of a to the variable e.
Step 4: Check whether the value of a is greater than zero are not.
Step 5: If step-4 is True, do step-6 to step-10
Step 6: Compute b = a % 10.
Step 7: Compute c = b * b * b.
Step 8: Compute a = a/10.
Step 9: Compute d = c + d
Step 10: Go to step-4
Step 11: If step-4 is false do the following steps
Step 12: Check the value of e is equal to value of d
Step 13: If step-12 is true print Armstrong
Step 14: If step-12 is false print not Armstrong
Step 15: Stop.
PSEUDOCODE:
BEGIN the program
READ the value to the a
ASSIGN value a to the variable e
CHECK whether the value of a is greater than are not
IF step-4 is true, do step-6 to step-10
Compute b = a%10
Compute c = b * b * b
Compute a = a/10
Compute d = c + d
GOTO step-4
IF step-4 is false, do the following steps
CHECK the value of e is equal to value of d
IF step-12 is true, PRINT Armstrong
IF step-12 is false, print not Armstrong
TERMINATE the program
FLOWCHART:
start
Read a
e=a
At
a>0
b = a % 10
c=b*b*b
a = a/10
d=c+d
at
e=d
Print
Not Armstrong
Print
Armstrong
stop
PROGRAM:
#include<stdio.h>
void main()
{
int a, b, c, d, e;
printf(\n Enter the number : );
scanf(%d, &a);
e = a;
while(a > 0)
{
b = a % 10;
c = b * b * b;
a = a\10;
d = c + d;
}
if(e == d)
printf(\n %d is an Armstrong number.,e);
else
printf(\n %d is not an Armstrong number.,e);
}
OUTPUT:
Enter the number : 153
153 is an Armstrong number.
Enter the number : 123
123 is not an Armstrong number.
RESULT:
The program is executed and the output is verified.
Ex.No: 6a
Date:
TO FIND TOTAL AND AVERAGE MARKS OF A STUDENTS USING ONE
DIMENSIONAL ARRAY
AIM:
To find total and average marks of a student using one dimensional array.
ALGORITHM:
Step 1: Start the program
Step 2: initialize the array marks, total, average.
Step 3: Read the number of subjects (n).
Step 4: Set a loop running from zero till number of students to accept marks of all.
Step 5: Sum up all the marks and store it in total and Find average by dividing total by
number of subjects (n).
Step 6: Print the values of total and average.
Step 7: Stop
PSEUDOCODE:
INITIALISE marks[100], total=0,avg=0.0,i=0.
READ the value of number of subjects(n).
Is i<n then, do step-3.1 to step-3.3 else go to step-4
READ mark[i] COMPUTE total+=mark[i].
INCREMENT i by 1. COMPUTE avg=total/n.
PRINT total, avg.
STOP
FLOW CHART:
PROGRAM:
#include<stdio.h>
void main()
{
int a[100],total=0,n, i;
float avg=0.0;
printf(\nEnter number of subjects);
scanf(%d,&n);
printf(\nEnter the student marks:);
for(i=0;i<n;i++)
scanf(%d,&a[i]);
for(i=0;i<n;i++)
total+=a[i];
avg=total/n;
printf(\nTOTAL:%d \t AVERAGE:%6.2f,total, avg); getch();
}
OUTPUT:
Enter number of subjects 3
90
90
90
TOTAL: 270 AVERAGE:90.0
RESULT:
Thus a C program to find Total and average marks of a student was successfully executed
and its output was verified.
Ex.No: 6b
Date:
TO FIND MAXIMUM ARRAY ELEMENT
AIM
To write a C program to find the maximum array element.
ALGORITHM:
Step 1: Start the program.
Step 2: Initialize array, i, limit, max.
Step 3: Accept the value of limit(n)
Step 4: Set a loop running from zero till n and accept array[i].
Step 5: Assign array[0] to max
Step 6: Set a loop running from zero till n and re assign it to a[i] if it is greater than max.
Step 7: Print the value of max.
Step 8: Stop the program.
PSEUDOCODE:
INITIALISE a[100],i, n, max=0.
READ the value of n
Is i<n is true, do step-3.1 to step-3.2 else goto step-4
ACCEPT a[i] INCREMENT i by 1 ASSIGN a[0] to max
Is i<n is true, Is (max<a[i]) true then, max=a[i]. INCREMENT i by 1
PRINT max
STOP
FLOWCHART:
PROGRAM:
#include<stdio.h>
void main()
{
int i,a[100],max=0,n;
printf(\nEnter the limit);
scanf(%d,&n);
printf(\nEnter %d numbers,n);
for(i=0;i<n;i++)
scanf(%d,&a[i]);
max=a[0];
for(i=0;i<n;i++)
{ if(max<a[i])
max=a[i]; }
printf(\nMaximum value is:%d,max); getch();
}
OUTPUT:
Enter the limit 2
Enter the numbers 3
1
Maximum value is:3
RESULT:
Thus a C program to find maximum element was successfully executed and its output as
verified.
Ex.No: 6c
Date:
TO FIND MINIMUM ARRAY ELEMENT
AIM:
To write a C program to find the minimum array element.
ALGORITHM:
Step 1: Start the program.
Step 2: Initialize array, i, limit, min.
Step 3: Accept the value of limit(n)
Step 4: Set a loop running from zero till n and accept array[i].
Step 5: Assign array[0] to min
Step 6: Set a loop running from zero till n and reassign it to a[i] if it is less than min.
Step 7: Print the value of min.
Step 8: Stop the program.
PSEUDOCODE:
INITIALISE a[100],i, n, min=0.
READ the value of n
Is i<n is true , do step-3.1 to step-3.2 else goto step-4
ACCEPT a[i]
INCREMENT i by 1
ASSIGN a[0] to min
Is i<n is true, Is (min>a[i]) true then, min=a[i]. INCREMENT i by 1
PRINT min
STOP
FLOWCHART:
PROGRAM:
#include<stdio.h>
void main()
{
int i,a[100],min=0,n;
printf(\nEnter the limit);
scanf(%d,&n);
printf(\nEnter %d numbers,n);
for(i=0;i<n;i++)
scanf(%d,&a[i]);
min=a[0];
for(i=0;i<n;i++)
{
if(min>a[i])
min=a[i]; }
printf(\nMinimum value is:%d,min);
}
OUTPUT:
Enter the limit 2
Enter the numbers 3
1
Minimum value is:1
RESULT:
Thus a C program to find minimum element was successfully executed and it's output
was verified.
Ex.No: 6d
Date:
MATRIX ADDITION USING 2-D ARRAY.
AIM:
To write a program to perform matrix addition.
ALGORITHM:
Step 1: Start the program.
Step 2: Enter the row and column of the matrix.
Step 3: Enter the elements of the a matrix.
Step 4: Enter the elements of the b matrix.
Step 5: Print the a matrix in the matrix form.
Step 6: Print the b matrix in the matrix form.
Step 7: Set a loop up to the row.
Step 8: Set a inner loop up to the column
Step 9: Add the elements of a and b in column wise and store the result in c matrix.
Step 10: After the execution of the two loops. Print the value of c matrix.
Step 11: Stop.
PSEUDOCODE:
BEGIN the program by entering the row and column of the matrix.
ENTER the elements of a and b matrix.
PRINT the a and b matrix in matrix form.
SET a loop up to row and inner loop up to column.
ADD the elements of a and b in column wise and store the value the result in c matrix.
PRINT the value of c matrix.
TERMINATE the program.
FLOWCHART:
PROGRAM:
#include<stdio.h>
main()
{
int a[25][25],b[25][25], c[25][25], I, j m, n;
printf(\n Enter the rows and columns of two matrixes );
scanf(%d %d , &m, &n)
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf(%d,&a[i][j]);
}
printf{\n Enter the elements of B matrix);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf(%d, &b[i][j]);
}
printf(\n The elements of A matrix);
for(i=0;i<m;i++)
{
printf(\n);
for(j=0;j<n;j++)
printf(\t %d, a[i][j]);
}
printf(\n The elements of B matrix);
for(i=0;i<m;i++)
{
printf(\n);
for(j=0;j<n;j++)
printf(\t %d,b[i][j]);
}
printf(\n The addition of two matrices);
for(i=0;i<m;i++)
{
printf(\n);
for(j=0;j<n;j++)
{
c[i][j]=a[i][j] + b[i][j];
printf(\t %d,c[i][j]);
}}
}
OUTPUT:
Enter the rows and columns of two matrices. 3 3
Enter the elements of A matrix 1 2 3 4 5 6 7 8 9
Enter the elements of B matrix 1 2 3 4 5 6 7 8 9
The elements of A matrix
1 2 3
4 5 67 8 9
The elements of B matrix
1 2 3
4 5 6
7 8 9
The addition of two matrixes
2
4
6 8
10
12 14 16
18
RESULT:
The program for matrix addition using 2-D array is executed and the output is verified.
Ex.No: 6e
Date:
MATRIX MULTIPLICATION USING 2D-ARRAY
AIM:
To write a program to perform matrix multiplication.
ALGORITHM:
Step 1: Start
Step 2: Read rows and columns limits for matrices m,n,p,q
Step 3: Check p is equal to n else go to step-12
Step 4: Set a loop to get A matrix values
Step 5: Read matrix value a[i][j]
Step 6: Set a loop to get B matrix values
Step 7: Read matrix value b[i][j]
Step 8: Repeat step-9 until i<m, j<n, k<p
Step 9: d[i][j]=0:
d[i][j]=d[i][j] + a[i][k] * b[k][j]
Step 10: Set a loop to print matrix values
Step 11: Print matrix values d[i][j] go to step-13
Step 12: Print the number of row a and columns should not be equal.
Step 13: Stop.
PSEUDOCODE:
BEGIN the program by reading the rows and columns limits of matrices m,n,p,q.
CHECK p is equal to n else PRINT the number of rows and columns should not be equal.
SET a loop to get A and B matrix values.
READ matrix value a[i][j] and b[i][j].
PRINT matrix value d[i][j].
TERMINATE the program.
FLOW CHART:
start
for i=0;i<m; i++
Read p,q
for j=0; j<n; j++
Read m,n
d[i][j] = 0
if
p==n
Read a[i][j]
print
d[i][j]
End
c
PROGRAM:
#include<stdio.>
void main()
{
int a[10][10], b[10][10], d[10][10], i,j,p,q,m,n,k;
printf(\n Enter the size of the A matrix: );
scanf(%d %d,&p,&q);
printf(\n Enter the size of the B matrix:);
scanf(%d %d ,&m,&n);
if(p==n) {
printf(\n enter the elements of A matrix.);
for(i=0; i<p;i++)
{
for(j=0; j<q; j++)
scanf(%d,&a[i][j]); }
printf(\n enter the elements of B matrix.);
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
scanf(%d,&b[i][j]); }
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
d[i][j]=0;
for(k=0; k<p; k++)
d[i][j] = d[i][j]+a[i][k] * b[k][j]);
}}
printf(\n Multiplication of A and B matrix: );
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
printf(%5d,d[i][j]);
printf(\n); }}
else
printf(\n The no. rows and columns should not be equal); }
OUTPUT:
Enter size of A matrix: 2
2
Enter size of B matrix: 2
2
Enter the elements of A matrix.
1
2
3
4
Enter the elements of B matrix.
1
2
3
4
Multiplication of A and B matrix:
7
10
15 22
RESULT:
The program for Matrix Multiplication using 2-D array is executed and the output is
verified.
Ex.No: 7
Date:
STRING MANIPULATION
AIM:
To write a program to perform string manipulation functions like string concatenations,
string comparison, string length, string reverse and string copy without using library function.
i) STRING CONCATENATION
ALGORITHM:
Step 1: Start
Step 2: Read str1, str2
Step 3: Set a loop to move str3 to str1
Step 4: Set a loop to move str3 to str2
Step 5: Print str3
Step 6: Stop
PSEUDOCODE:
BEGIN the program.
READ str1, str2
SET a loop to move str3 to str1 and str3 to str2.
PRINT str3
TERMINATE the program.
FLOW CHART
Start
str3[i] = str1[i]
for(j=0; str2[j]!=\0;j++)
str3[i] = str1[i]
i = i+1
Print str3
Stop
PROGRAM:
#include<stdio.h>
void main()
{
char str1[10], str2[10], str3[40];
int i,j;
printf(\n Enter the two string : );
scanf(%s %s,str1, str2);
for(i=0; str1[i]!=\0; i++)
{
str3[i] = str1[i];
}
for(j=0; str2[j]!=\0; j++)
{
str3[i] = str2[j];
i++;
}
str3[i] = \0;
printf(\n Concatenated string is.%s , str3);
}
OUTPUT:
Enter the two string : venkat muni
concatenated string is venkamuni
ii) STRING COMPARISON
ALGORITHM:
Step 1: Start
Step 2: Read the two string str1, str2
Step 3: Set a loop to compare two strings
Step 4: Check if(str1[i] = str2[i])
Step 4.1: Print Strings are equal else
Step 4.2: Print Strings are not equal
Step 5: Stop
PSEUDOCODE:
BEGIN the program by reading the two string str1, str2
SET a loop to compare two string
CHECK if(str1[i] = str2[i])
PRINT Strings are equal else Strings are not equal
TERMINATE the program.
FLOW CHART:
Start
if
str1[i] = str2[i]
Stop
PROGRAM:
#include<stdio.h>
void main()
{
int I,equal=0;
char str1[20], str2[20];
printf(|n Enter the first and second string : );
scanf(%s %s, str1, str2);
for(i=0; i<strlen(str1); i++)
{
if(str1[i] == str2[i])
equal=1;
else
{equal=0; break;}
}
if(equal==0)
printf(Strings are not equal);
else
printf(Strings are equal);
}
OUTPUT:
Enter the first and second string : venkat venkat
Strings are equal.
iii) STRING LENGTH:
ALGORITHM:
Step 1: Start
Step 2: Read str
Step 3: Set a loop to calculate length of the string
Step 4: Print length of the string using variable len
Step 5: Stop
PSEUDOCODE:
BEGIN the program by reading str
SET a for loop to calculate length of the string
PRINT length of the string using variable len
TERMINATE the program.
FLOW CHART
Start
Read str
Print len
Stop
PROGRAM:
#include<stdio.h>
void main()
{
char str[50];
int len;
printf(\n Enter the string : );
scanf(%[^\n],str);
for(len=0; str[len]!=\0; len++);
printf(Length of main string is %d \n ,len);
}
OUTPUT:
Enter the string : VRB publishers, vadapalani, Chennai-26.
Length of main string is 39.
iv) STRING REVERSE
ALGORITHM:
Step 1: Start
Step 2: Read str1
Step 3: Set a loop to copy a string 1 to string 2 in reverse.
Step 4: Print The reversed string str2
Step 5: Stop
PSEUDOCODE:
BEGIN the program by reading str1
SET a loop to copy a string 1 to string 2 in reverse.
PRINT The reversed string str2
TERMINATE the program.
FLOW CHART:
Start
Read str1
Print str1
len=strlen(str1)
str2[--len] = str1[i]
Print str2
Stop
PROGRAM:
#include<stdio.h>
void main() {
int i,len;
char str1[50], str[50];
printf(\n Enter the string : );
scanf(%s, str1);
printf(\n The string is %s, str1);
len=strlen(str1);
for(i=0; str1[i]!=\0; i++)
{
str2[--len] = str1[i]; }
str2[i] = \0;
printf(\n Reverse of the string without using strrev() function);
printf(\n The reversed string is %s, str2); }
OUTPUT:
Enter the string: Velammal The string is Velammal
Reverse of the string without using strrev() function
The reversed string is lammaleV
v) STRING COPY
ALGORITHM:
STEP 1: Start
STEP 2: Read str1
STEP 3: Set a loop to copy a string 1 to string 2, Print The copied string str2
STEP 4: Stop
PSEUDOCODE:
BEGIN the program by reading str1
SET a loop to copy a string 1 to string 2
PRINT The copied string str2
TERMINATE the program.
FLOW CHART:
Start
Read str1
Print str1
Print str2
Stop
PROGRAM:
#include<stdio.h>
void main()
{
int i;
char str1[50], str[50];
printf(\n Enter the first string : );
scanf(%s, str1);
printf(\n The first string is %s, str1);
for(i=0; str1[i]!=\0; i++)
{
str2[i] = str1[i];
}
str2[i] = \0;
printf(\n copy the string 1 to string 2 without using strcpy() function);
printf(\n The copied string is %s, str2);
}
OUTPUT:
Enter the first string : MUNISUJI
The first string is MUNISUJI
Copy the string 1 to string 1 without using strcpy() function
The copied string is MUNISUJI.
RESULT:
The program for string manipulation without using Library and built in function is
executed and the output is verified.
Ex.No: 8
Date:
SWAP TWO NUMBERS USING FUNCTIONS
AIM:
To write a C program to swap two numbers using third variable (Call by value and Call by
reference) and without using third variable
i) USING THIRD VARIABLE (CALL BY VALUE)
ALGORITHM:
Step 1: Start the program
Step 2: Enter two numbers
Step 3: Call the display function
Step 4: Pass the value of the two numbers to the calling function.
Step 5: Get the value in the calling function.
Step 6: Swap the number using temporary variable.
Step 7: Print the swapped values in the main function .
Step 8: Stop.
PSEUDOCODE:
READ two numbers
CALL the function
PRINT swapped numbers
STOP
FLOWCHART:
function
Start
Enter numbers
t=x
x=y
y=t
Call function
Stop
Print swapped
numbers
Stop
PROGRAM:
#include<stdio.h>
void display(int,int);
main()
{
int x,y;
printf(\nEnter two numbers);
scanf(%d,&x,&y);
printf(\nEntered numbers x=%d \t y=%d,x,y);
display(x,y);
printf(\nAfter swapping: x=%d \t y=%d \n,x,y);
}
void display(int a, int b)
{
int t;
t=a;
a=b;
b=t;
printf(\n In swap: a=%d\t b=%d\n,a,b);
}
OUTPUT:
Enter two numbers.. 10 20
Entered numbers x=10 y=20
In swap: a=20 b=10
After swapping : x=10 y=20
ii) USING THIRD VARIABLE (CALL BY REFERENCE)
ALGORITHM:
Step 1: Start the program
Step 2: Enter two numbers
Step 3: Call the display function
Step 4: Pass the address of the two numbers to the calling function.
Step 5: Get the address in the calling function in the pointer.
Step 6: Swap the number using temporary variable.
Step 7: Print the swapped values in the main function.
Step 8: Stop.
PSEUDOCODE:
READ two numbers
CALL the function
PRINT swapped numbers
STOP
function
FLOWCHART:
Start
Enter
numbers
t=*x
*x=*
y
*y=t
Call
function
Stop
Print
swapped
numbers
Stop
PROGRAM:
#include<stdio.h>
void display(int *,int *);
main()
{
int x,y;
printf(\nEnter two numbers); scanf(%d,&x,&y);
printf(\nEntered numbers x=%d \t y=%d,x,y);
display(&x,&y);
printf( \nAfter swapping: x=%d \t y=%d \n,x,y);
}
void display(int *a, int *b)
{
int t;
t=*a;
*a=*b;
*b=t;
printf(\n In swap: a=%d\t b=%d\n,*a,*b);
}
OUTPUT:
Enter two numbers.. 10 20
Entered numbers x=10 y=20
In swap: a=20 b=10
After swapping :x=20 y=10
Enter
numbers
x=x+
y
y=x-y
x=x-y
Call
function
Stop
Print
swapped
numbers
Stop
PROGRAM:
#include<stdio.h>
void display(int,int);
main()
{
int x,y;
printf(\nEnter two numbers); scanf(%d,&x,&y);
printf(\nEntered numbers x=%d \t y=%d,x,y);
display(x,y);
printf(\nAfter swapping: x=%d \t y=%d \n,x,y);
}
void display(int a, int b)
{
a=a+b;
b=a-b;
a=a-b;
printf(\n In swap: a=%d\t b=%d\n,a,b);
}
OUTPUT:
Enter two numbers.. 10 20
Entered numbers x=10 y=20
In swap: a=20 b=10
After swapping :x=20 y=10
RESULT:
Thus a C program to swap two numbers using pointer was successfully developed and
its output was verified.
Ex.No: 9a
Date:
FACTORIAL USING RECURSION
AIM:
To write a program to find the factorial of the given number using recursion.
ALGORITHM:
Step 1: Start
Step 2: Read num
Step 3: a=recur(num)
Step 4: print num, a
Step 5: Stop
Step 1: recur start
Step 2: fact=1
Step 3: Is no=1
T: return 1
F: fact=no*recur (no-1)
Step4: return
PSEUDOCODE:
Set initial num, a, fact=1
READ num
A=recur (num)
IF (no==1)
WRITE the factorial of the number
Else
Fact=no*recur (no-1)
ENDIF
Stop
FLOWCHART
start
recur(no)
Read num
a=recur(num)
Print a
stop
If
no==1
return
Fact=no*recur(no-1)
PROGRAM:
#include<stdio.h>
recur(int no)
{
if(no==1)
return(1);
else
return (no*recur(no-1));
}
main()
{
int num,a;
printf("enter the number\n");
scanf("%d",&num);
a=recur(num);
printf("the factorial of the number %d is %d",num,a);
}
OUTPUT:
Enter the number : 5
The factorial of the number 5 is 120
RESULT:
Thus the C program to find the factorial of a given number using recursion is successfully
completed.
Ex.No: 9b
Date:
FIBONACCI SEQUENCE USING RECURSION
AIM:
To write a c program to generate Fibonacci sequence generation using recursion.
ALGORITHM:
Step 1: Start the program.
Step 2: Read n.
Step 3: Call the function fib ( n ) then print n.
Step4: Stop
Step 1: start the function
Step 2: if n<2, then f1=0,f2=1 goto step 5
Step 3: call the function fib ( n-1)
Step 4: temp=f2, f1+f2, f1=temp.
Step 5: print f1.
Step 6: return to main.
PSEUDOCODE:
BEGIN the program.
READ n
CALL the function fib( n)
START the function IF( n<2) f1=0,f2=1,goto step 8
CALL fib( n-1)
CALCULATE temp=f2, f1+f2,f1=temp
PRINT f1
TERMINATE the program.
FLOWCHART:
PROGRAM:
#include<stdio.h>
void main()
{
int n;
void fib();
printf(\nNumber of terms to be generated);
scanf(%d,&n);
printf(\nFibonacci series upto %d terms:\n\n);
fib(n);
printf(\n);
}
void fib(int n)
{
int n;
static int f1=0,f2=1;
int temp;
if(n<2)
{
f1=0; f2=1;
}
else {
fib(n-1);
temp=f2;
f2=f1+f2;
f1=temp; }
printf(%5d,f1);
return 0;
}
OUTPUT:
Number of terms to be generated? 8
Fibonacci sequence upto 8 terms :
0 1 1 2 3 5 8 13
RESULT:
Thus a C program to generate Fibonacci sequence was successfully executed and its
output is verified.
Ex.No: 10a
Date:
STUDENT DETAILS USING STRUCTURE
AIM:
To print the mark sheet of 'n' students using structure.
ALGORITHM:
Step 1: Start the program.
Step 2: Initialize structure std with members.
Step 3: Read the number of students 'n'.
Step 4: Set up for loop to get student number, name, and six subjects marks.
Step 5: Read s[i].sno, s[i].name, s[i].m1, s[i].m2, s[i].m3, s[i].m4, s[i].m5, s[i].m6.
Step 6: s[i].tot=s[i].m1+s[i].m2+s[i].m3+s[i].m4+s[i].m5+s[i].m6 and s[i].avg=s[i].tot/6;
Step 7: Check if(s[i].m1<35 or s[i].m2<35 or s[i].m3<35 or s[i].m4<35 or s[i].m5<35 or
s[i].m6<35="F" else
Step 7.1: Check if(s[i].avg>=75)
s[i].grade="D" else
Step 7.2: Check if(s[i].avg<75 and s[i].avg>=60) s[i].grade="F" else
Step 7.3: Check if(s[i].avg<60 and s[i].avg>=50) s[i].grade="S" else
Step 7.4: Check if(s[i].avg<50 and s[i].avg>=35)
s[i].grade="T".
Step 8: Set a loop to print student mark lists details.
Step 9: Stop the program.
PSEUDOCODE:
BEGIN the program
INITIALIZE structure with members, READ the numbers
SETUP a for loop to get student number, name and six subjects marks.
READ the numbers
EVALUATE the total and average using the formula.
CHECK the values and PRINT the grade, TERMINATE the program.
FLOWCHART:
PROGRAM:
#include<stdio.h>
struct std
{
int sno,m1,m2,m3,m4,m5,m6,tot;
char name[10],grade;
float avg;
}s[10];
void main( )
{
float avg;
int tot,n,i;
clrscr( );
printf("Enter the number of students to process....");
scanf("%d",&n);
printf("Enter student number, name and 6 subject marks...\n");
for(i=1;i<=n;i++)
{
scanf("%d%s%d%d%d%d%d%d",&s[i].sno,&s[i].name,&s[i].m1,s[i].m1,s[i].m2,
s[i].m3,s[i].m4,s[i].m5,s[i].m6);
s[i].tot=s[i].m1+s[i].m2+s[i].m3+s[i].m4+s[i].m5+s[i].m6;
s[i].avg=s[i].tot/6;
if(s[i].m1<35 || s[i].m2<35 || s[i].m3<35 || s[i].m4<35 || s[i].m5<35 || s[i].m6<35)
s[i].grade='F';
else
{
if(s[i].avg>=75)
s[i].grade='D';
else if(s[i].avg<75 && s[i].avg>=60)
s[i].grade='F';
else if(s[i].avg<60 && s[i].avg>=50)
s[i].grade='S';
else if(s[i].avg<50 && s[i].avg>=35)
s[i].grade='T';
}
}
printf("Student marks lists are...\n");
printf("S.NO\tNAME\tTOTAL\tAVERAGE\tGRADE\n");
printf("------------------------------------------------------\n");
for(i=1;i<=n;i++)
{
printf("%d\t%s\t%d\t%f\t%c",s[i].sno,s[i].name,s[i].tot,s[i].avg,s[i].grade);
printf("\n");
}
}
OUTPUT:
Enter the number of students in process....5
Enter student number, name and 6 subjects marks....
1 MUNI
56 67 78 56 78 20
2 LAK
78 79 89 80 90 99
3 SUJI
60 61 62 63 64 60
4 RAJ
50 51 52 53 54 55
5 VENKAT 40 41 42 43 44 45
Student mark list are....
S.NO
NAME
TOTAL
AVERAGE
GRADE
----------------------------------------------------------------------------------1
MUNI
355
59.000000
F
2
LAK
515
85.000000
D
3
SUJI
370
61.000000
F
4
RAJ
315
52.000000
S
5
VENKAT
255
42.000000
T
RESULT:
The C program for Student details using Structure is executed and the output is verified.
EX.NO: 10b
DATE:
SALARY DETAILS OF AN EMPLOYEE USING UNION
AIM:
To print the salary details of n employees using union.
ALGORITHM:
Step 1: Start
Step 2: Initialize structure student with members.
Step 3: Read the number of students n.
Step 4: Set up for loop to get student number, name and six subject marks.
Step 5: Read stud[i].rno, stud[i].m1,stud[i].m2, stud[i].m3, stud[i].m4, stud[i].m5
Step 6: stud[i].tot=stud[i].m1+stud[i].m2+stud[i].m3+stud[i].m4+stud[i].m5
Step7: stud[i].avg=stud[i].tot/6;
Step 8: Set a loop to print student mark list details.
Step 9: Printf stud[i].rno, stud[i].name, stud[i].tot, stud[i].avg
Step 10: stop
PSEUDOCODE:
BEGIN the program
INITIALIZE structure with members
READ the numbers
SETUP a for loop to get student number, name and five subject marks.
READ the numbers
EVALUATE the total and average using the formula
TERMINATE the program.
FLOWCHART:
PROGRAM:
#include<stdio.h>
#include<string.h>
union employee
{
int e_id;
int e_basic;
char e_name[25];
}emp;
void main()
{
int hra,id;
char name[25];
float da,ded,e_salary;
printf("Enter the emp id,emp name and basic\n");
scanf("%d ",&emp.e_id);
id=emp.e_id;
scanf(%s, emp.e_name);
strcpy(name,emp.e_name);
scanf(%d, &emp.e_basic);
da=emp.e_basic*0.75;
hra=1000;
ded=emp.e_basic*0.05;
e_salary=emp.e_basic + da+hra-ded;
printf("The salary details of employee :\n");
printf("Emp ID\t name\t Basic\t Net salary\n");
printf("%d\t%s\t%d\t%f", id, name,emp.e_basic,e_salary);
}
OUTPUT:
Enter the emp id, emp name and basic
1 ARUN 4400
The salary details of employee:
Emp ID Name
Basic
Net salary
1
ARUN 4400
8480.000000
RESULT:
Thus the C program for Employee details using union is executed and the output is
verified.