c Lab Manual
c Lab Manual
LAB MANUAL
NAME:
ROLL NO:
COURSE:
YEAR /SEM:
1
List of Experiments
C PROGRAMMING
MS OFFICE TOOLS
16. Preparing a Newsletter : To prepare a newsletter with borders, two columns text, header and
footer, inserting a graphic image and page layout.
17. Creating and editing the table.
18. Printing envelopes and mail merge.
19. Using formulas and functions : To prepare a worksheet showing the monthly sales of a
company in different branch offices.
20. Prepare a statement for displaying result of 10 students in 5 subjects.
2
INDEX
PAGE SIGNATURE
SI. DATE EXPERIMENTS NO. OF THE
NO. STAFF
3
PAGE SIGNATURE
SI. DATE EXPERIMENTS NO. OF THE
NO. STAFF
4
C-PROGRAMMING
Date :
Exp. No:
Aim :
To write a C program to calculate the factorial of a given positive number using function.
Algorithm :
Step 1: Start
Step 2: Declare Variable n, fact, i
Step 3: Read number from User
Step 4: Initialize Variable fact=1 and i=1
Step 5: Repeat Until i<=number
fact=fact*i
i=i+1
Step 6: Print fact
Step 7: Stop
5
Flow Chart :
Start
Read n
i = 1 , fact = 1
is False
i<=n?
True
i=i+1
Print fact
Fact=fact*i
Stop
6
Code :
#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,fact=1;
printf("Enter any number : ");
scanf("%d", &n);
for(i=1; i<=n; i++)
fact = fact * i;
printf("Factorial value of %d = %d",n,fact);
return 0;
}
7
Output :
Result :
8
Date :
Exp. No:
Algorithm :
Step 1: Declare int and long variables.
Step 2: Enter base value through console.
Step 3: Enter exponent value through console.
Step 4: While loop.
Exponent !=0
Value *=base
–exponent
Step 5: Print the result.
9
Flow chart :
Start
Long value = 1
if long False
value < Value*=base
power
No
Print output
Stop
10
Code :
#include<stdio.h>
int main()
{
int base, exponent;
long value = 1;
printf("Enter a base value:");
scanf("%d", &base);
printf("Enter an exponent value: ");
scanf("%d", &exponent);
while (exponent != 0)
{
value *= base;
--exponent;
}
printf("Result = %ld", value);
return 0;
}
11
Output :
Result :
12
Date :
Exp. No:
Find GCD and LCM of two given integer numbers using function.
Aim :
To write a C program to find GCD and LCM of two given integer numbers using function.
Algorithm :
Step-2 : Compare the two numbers, store the greater number in the numerator and the
smaller number in the denominator.
Step-3 : Run the while loop until the remainder becomes ‘0’.
Step-4 : Inside the while loop keep on dividing the numerator by denominator and store
the value in the remainder variable.
Step-5 : When the value of the remainder variable becomes ‘0’ come out of the loop and
store the value of the denominator in the GCD variable.
Step-6 : Now, calculate the lcm by the formula LCM = (num1 * num2) / GCD
13
Flow chart :
14
Code :
#include <stdio.h>
void main()
{
int num1, num2, gcd, lcm, remainder, numerator, denominator;
numerator = (num1>num2)?num1:num2;
denominator = (num1<num2)?num1:num2;
remainder = numerator % denominator;
while (remainder != 0)
{
numerator = denominator;
denominator = remainder;
remainder = numerator % denominator;
}
gcd = denominator;
lcm = num1 * num2 / gcd;
printf("GCD of %d and %d = %d\n", num1, num2, gcd);
printf("LCM of %d and %d = %d\n", num1, num2, lcm);
}
15
Output :
Result :
16
Date :
Exp. No:
Aim :
To write a C program to find the sum of N natural numbers using function.
Algorithm :
Step –1 : Start
Step –3 : Enter the value of num i.e. number upto which sum is to be calculated.
Step –5 : Stop.
17
Flow chart :
18
Code :
#include <stdio.h>
#include <conio.h>
void main()
{
int num, i, sum = 0;
printf(" Enter a positive number: ");
scanf("%d", &num);
for (i = 0; i <= num; i++)
{
sum = sum + i;
}
19
Output :
Result :
20
Date :
Exp. No:
Aim :
To write a C program for book information using structures method.
Algorithm :
Step -3 : Enter details of each book with name, author, pages & price.
Step -5 : Stop
Flow chart :
21
Code :
#include<stdio.h>
#include<string.h>
#define SIZE 20
struct bookdetail
{
char name[20];
char author[20];
int pages;
float price;
};
void main()
{
struct bookdetail b[SIZE];
int num,i;
printf("Enter the Numbers of Books:");
scanf("%d",&num);
printf("\n");
for(i=0;i<num;i++)
printf("\t=:Book %d Detail:=\n",i+1);
22
printf("Enter the Price of Book:\n");
scanf("%f",&b[i].price);
output(b,num);
int i,t=1;
for(i=0;i<n;i++,t++)
printf("\n");
printf("Book No.%d\n",t);
printf("\n");
23
Output :
Result :
24
Date :
Exp. No:
Aim :
To write a C program to store student information using structures.
Algorithm :
Step -3 : Enter details of each book with name, register no and marks.
Step -5 : Stop
25
Flow chart :
26
Code :
#include <stdio.h>
struct student
{
char name[50];
int roll;
float marks;
};
int main()
{
struct student s;
printf("\nDisplaying Information\n");
printf("Name: %s\n",s.name);
printf("Roll: %d\n",s.roll);
printf("Marks: %.2f\n",s.marks);
return 0;
}
27
Output :
Result :
28
Date :
Exp. No:
Aim :
To write a C program to print the address of a variable and its value using pointer.
Algorithm :
Step -5 : Stop
29
Flow chart :
Start
Input var
Print var
Stop
30
Code :
#include<stdio.h>
int main()
{
var = 23.32;
ptr = &var;
return 0;
}
31
Output :
Result :
32
Date :
Exp. No:
Algorithm :
Step 1: Start
Step 2: input r
Step 4: area = pi * r * r
Step 5: Perimeter = 2 * pi * r
Step 7: Stop
33
Flow chart :
34
Code :
#include<stdio.h>
void main()
{
float radius, area, p;
printf("Enter Radius of Circle\n");
scanf("%f",&radius);
area=3.14*radius*radius;
printf("The area of Circle is %f",area);
p=2*3.14*radius;
printf("\nThe perimeter of Circle is %f",p);
}
35
Output :
Result :
36
Date :
Exp. No:
Aim :
Algorithm :
Step -6: If both are same then the number is palindrome otherwise not.
37
Flow chart :
38
Code :
#include <stdio.h>
int main() {
int n, reversed = 0, remainder, original;
printf("Enter an integer: ");
scanf("%d", &n);
original = n;
while (n != 0) {
remainder = n % 10;
reversed = reversed * 10 + remainder;
n /= 10;
}
if (original == reversed)
printf("%d is a palindrome.", original);
else
printf("%d is not a palindrome.", original);
return 0;
}
39
Output :
Result :
40
Date :
Exp. No:
Aim :
Algorithm :
Step -1: Take num as input.
41
Flow chart :
42
Code :
#include <stdio.h>
int main()
{
int n, i, flag = 0;
printf("Enter an integer: ");
scanf("%d", &n);
if (n == 0 || n == 1)
flag = 1;
if (n % i == 0) {
flag = 1;
break;
}
}
if (flag == 0)
printf("%d is a prime number.", n);
else
printf("%d is not a prime number.", n);
return 0;
}
43
Output :
Result :
44
Date :
Exp. No:
Aim :
Algorithm :
45
Flow chart :
46
Code :
#include <stdio.h>
int main()
{
int num, sum=0;
while(num!=0)
{
return 0;
}
47
Output :
Result :
48
Date :
Exp. No:
Aim :
To write a C program to display Fibonacci series up to N terms.
Algorithm :
Step -2: Declare and initialize three variables, a=0, b=1, c=0.
Step -3: Here c is the current term, b is the n-1th term and a is n-2th term.
Step -5: The loop structure should look like for(i=1; i<=term; i++).
Step -7: Inside the loop copy the value of n-1th term to n-2th term i.e. a=b.
Step -8: Next, copy the value of nth to n-1th term b=c
Step -9: Finally compute the new term by adding previous two terms i.e. c = a+b.
49
Flow chart :
50
Code :
#include <stdio.h>
int main()
{
int a, b, c, i, terms;
a = 0;
b = 1;
c = 0;
a = b;
b = c;
c = a + b;
}
return 0;
}
51
Output :
Result :
52
Date :
Exp. No:
Aim :
Algorithm :
Step -3: A character is alphabet if ((ch >= ‘a’ && ch <= ‘z’ ) || (ch >= ‘A’ && ch <= ‘Z’ ))
Step -5: A character is digit if (ch >= ‘0’ && ch <= ‘9’ )
Step -6: Finally, if a character is neither alphabet nor digit, then character is a special character.
53
Flow chart :
Start
Input character
Ch=’A’&
&’Z’, Print alphabet
’a’&&’z’
Ch >=
'0' &&
ch <= '9'
Print numeric
Else
Special
character
Stop
54
Code :
#include <stdio.h>
int main()
{
char ch;
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf(“%c' is alphabet.", ch);
}
else if(ch >= '0' && ch <= '9')
{
printf("%c' is numeric.", ch);
}
else
{
printf("%c' is special character.", ch);
}
return 0;
}
55
Output :
Result :
56
Date :
Exp. No:
Aim :
To write a C program to count vowels and consonants in a given string.
Algorithm :
Step -2: Initialize two other variables to store vowel and consonant count.
Vowel = 0 and consonant = 0
Step -4: Inside the loop increment vowel by 1 if current character is vowel.
57
Flow chart :
Start
Declare var ch
True
Count vowels
Stop
58
Code :
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void main()
{
char str[str_size];
int i, len, vowel, cons;
vowel = 0;
cons = 0;
len = strlen(str);
59
Output :
Result :
60
Date :
Exp. No:
Aim :
To write a C program to find product of two matrices.
Algorithm :
Step -2: Calculate the number of rows and columns present in the array a and store it in
variables row1 and col1 respectively.
Step -3: Calculate the number of rows and columns present in the array b and store it in
variables row2 and col2 respectively.
Step -4: Check if col1 is equal to row2. For two matrices to be multiplied, the number of
column in the first matrix must be equal to the number of rows in the second matrix.
Step -5: If col1 is not equal to row2, display the message "Matrices cannot be
multiplied."
Step -6: If they are equal, loop through the arrays a and b by multiplying elements of the
first row of the first matrix with the first column of the second matrix and add all the
product of elements.
e.g prod11 = a11 x b11 + a11 x b21 + a11 x b31
Step -7: Repeat the previous step till all the rows of the first matrix is multiplied with all
the columns of the second matrix.
61
Flow chart :
62
Code :
#include <stdio.h>
const int MAX = 100;
printf("\n");
}
}
void multiplyMatrix(int row1, int col1, int A[][MAX],int row2, int col2, int B[][MAX])
{
int i, j, k;
int C[MAX][MAX];
if (row2 != col1) {
printf("Not Possible\n");
return;
}
int main()
{
int row1, col1, row2, col2, i, j;
int A[MAX][MAX], B[MAX][MAX];
63
printf("Enter the number of rows of First Matrix: ");
scanf("%d", &row1);
printf("%d", row1);
printf("\nEnter the number of columns of First Matrix: ");
scanf("%d", &col1);
printf("%d", col1);
return 0;
}
64
Output:
Result :
65
66
MS-OFFICE
Date :
Exp. No:
Aim :
To prepare a newsletter with borders, two columns text, header and footer and inserting a
graphic image and page layout.
Procedure :
Step-1 : Create a New page.
67
Step–2 : To create borders.
• Click on Design → Select Page Border → Choose the required border style and
click OK.
68
Step – 3 : To create a two column text.
69
• Your page looks like the below figure.
Header :
70
• Give the required data like Date, Article name & Place.
Footer :
71
• Give page number and the page looks like the below figure.
• Place the cursor were you need to place the graphic image.
• Click on Insert → Pictures.
72
• Select the required image and click on insert.
73
Step – 6 : Page Layout.
• Here you can set margins, apply themes, control of page orientation and size, add
sections and line breaks, display line numbers, and set paragraph indentation and lines.
Result :
74
Date :
Exp. No:
Aim :
To create a table and edit the table in MS Office.
Procedure :
Step - 1 : To create a new table :
§ Move the cursor to the location in the document where you want to create the
table.
§ Click the Table button in the Elements tool or choose Insert → click Table. The
table dialog displays
§ Enter the initial number of rows and columns for the new table and specify the
border width.
75
§ Click the confirm button.
§ The table is created successfully.
76
Add rows and columns :
• You can add the number of rows and columns by selecting the options in the dialog box.
77
Step – 3 : Deleting the table.
Result :
78
Date :
Exp. No:
Aim :
To create an envelope and mail merge the envelope using MS Office.
Procedure :
Creating Envelope :
Step – 1 :
Step – 2 :
79
Step – 3 :
Your envelope is successfully created and you can print the envelope.
80
Mail Merge :
Mail Merge is a handy feature that incorporates data from both Microsoft Word and Microsoft
Excel and allows you to create multiple documents at once, such as letters, saving you the time
and effort of retyping the same letter over and over.
Step – 1:
§ The first thing you do is create an Excel spreadsheet, creating a header for each field such
as First Name, Last Name, Address & City.
81
Step – 2 :
Step – 3 :
82
• Click on next option.
83
• Click on next option.
84
• Click on “Greeting Line” option.
• Insert greeting line dialog box appears.
• Select a greeting line format and click OK.
85
• Click on next option.
• Preview of the selected recipient name address and greeting line were attached
to the letter.
86
vi. Complete the merge :
87
Result :
88
Date :
Exp. No:
Aim :
To prepare a worksheet showing the monthly sales of a company to different branch offices
using formulas and functions.
Procedure :
Step – 1 :
• To write the company name in larger word within a single cell, select the space you
need.
• Click on Merger and Center option.
89
Step – 2 :
90
• To fill other cell with the same multiplication operation, drag the cell pointer downwards.
• The auto-fill option will take care of doing the remaining cell calculations immediately.
Step – 3 :
91
• Select the cell F6 and type the formula as =E6*5%
• Then press Enter key for answer.
92
Step – 4 :
OR
93
Result :
94
Date :
Exp. No:
Aim :
To prepare a statement for displaying result of 10 students in 5 subjects.
Procedure :
Step – 1 :
• Create a worksheet with 10 students name and marks obtained by them in 5 subjects.
Step – 2 :
( Formula = First cell name + Second cell name + Third cell name )
95
• Select the cell G6 and type the formula as =SUM(B2,C2,D2,E2,F2) or
=b2+C2+D2=E2+F2.
• Then press Enter key for answer.
96
Step – 3 :
97
Step – 4 :
98
Result :
99
100