Vous êtes sur la page 1sur 43

qwertyuiopasdfghjklzxcvbnmqwertyui

opasdfghjklzxcvbnmqwertyuiopasdfgh
jklzxcvbnmqwertyuiopasdfghjklzxcvb
B.TECH IT
nmqwertyuiopasdfghjklzxcvbnmqwer
GE6161 COMPUTER PRORAMMING
tyuiopasdfghjklzxcvbnmqwertyuiopas
dfghjklzxcvbnmqwertyuiopasdfghjklzx
cvbnmqwertyuiopasdfghjklzxcvbnmq
wertyuiopasdfghjklzxcvbnmqwertyuio
pasdfghjklzxcvbnmqwertyuiopasdfghj
klzxcvbnmqwertyuiopasdfghjklzxcvbn
mqwertyuiopasdfghjklzxcvbnmqwerty
uiopasdfghjklzxcvbnmqwertyuiopasdf
ghjklzxcvbnmqwertyuiopasdfghjklzxc
vbnmqwertyuiopasdfghjklzxcvbnmrty
uiopasdfghjklzxcvbnmqwertyuiopasdf
ghjklzxcvbnmqwertyuiopasdfghjklzxc
vbnmqwertyuiopasdfghjklzxcvbnmqw
ertyuiopasdfghjklzxcvbnmqwertyuiop
FIRST SEMESTER

MANUAL
REGULATION 2013

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

Ex.No:1

DOCUMENT CREATION, TEXT MANIPULATION


WITH SCIENTIFIC NOTATIONS

AIM:
To create a MS-word document using Formatting tool bar and create
mathematical equations using scientific notations.
PROCEDURE:
1.Open a new document and perform the following tasks:

Justify the Text.


Make some of the text as Bold type.
Correct the spellings.
Underline and make Italic style for some words.
Save the document with a suitable name.
Add the bullets and numbering using the format menu.
Change the line spacing as 1.5 for the whole text in a document.
Place a box to the Entire text.

2. Try out the following equations in your document:

Ca(HCO3)2

CaCo3 + Co2 + H2O

3. Inserting Symbols:

Type the text, then put the cursor where you want to add the
symbol.
Choose symbols options from the Insert menu.
Shows the symbols dialog box. Then choose the appropriate Font
type (normally for symbols Webdings font)
4. Advertisement:
Open a new word document.
Type the heading and select the font as Times New Roman, font style
as Title color and the font size as appropriate.
Select Insert -> Picture -> ClipArt and select the picture.
Select Tools -> Customize -> Toolbars -> Drawing and Word Art.
2

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

Select any one WordArt Style and insert in the document.

Type the given article and select Format -> Columns and select two
columns.
Insert the given shapes by selecting Auto shapes from the Drawing
Toolbar.
Apply border to the entire page by selecting Format -> Borders and
Shading.
Select View -> Header and Footer and add the necessary details.
Save the document as advertisement.doc.

RESULT:

CHARTS LINE, XY, BAR and PIE AND 3D

Ex.No:2

VIEW OF THE CHARTS


Aim
To create charts like Line, XY, Bar and Pie in Microsoft Excel editor.
Procedure
An Example,
Sales Report for the first quarter 2011

Vehicle

Jan

Feb

Mar

Total

Car

250

300

310

Auto

54

92

20

Jeep

91

120

11

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

Van

Total

125

119

78

Make sure that appropriate formulas are entered in column E so that total
sale of each vehile is shown properly. Similarly in row 6 type correct
formulas so that total sales for each month is shown in respective column.
Open a new worksheet window
Build the above table starting from cell A1.
Type the formula (=sum(B2:D2)) in cell E2 to get the Total
Drag through the range from (E2 to E5) and then press enter key
Similarly type the formula in cell B6 and drag upto B6 to get the total
for every month
1.Draw a Pie Chart to show vehicle wise total sales made between Jan and
Mar 2011.Total sales of each vehicle must be shown as a sector.
Select the data to be charted.
Choose Chart from the Insert menu or click on the ChartWizard
button.
Select the chart type: Pie and click on the Next button.
Read the dialog box, make sure the range is correct and then click the
Next button
Enter the Chart title, Category (x) axis, value (y) axis and click on next
button to continue
Click once on the As object in radio button and specify the object
name.
Click on the finish button and get the desired chart on the workbook.

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

Right click the above figure, and select the 3D view to get the
3D view of the above Pie chart.

3D view of the Pie chart

Car
Auto
Jeep
Van
Total

2. Draw a bar graph/column chart to show sale of vehicles for each month.
Highlight the data to be charted.
Choose Chart from the Insert menu
Choose the Chart type: Column and then select the desired chart subtype from the samples on display. Click on the Next button.
In the dialog box, the default radio button for columns would be
selected. If the range is correct, click on the Next button.
5

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

Select Titles tab from the dialog box and enter the chart title,
category x axis value, y axis value.
Click on the Legend folio and select the desired placement where the
legends should be displayed. Click on the next button.
Click once on the As object in radio button and specify the object
name.
Click on the finish button and get the desired chart on the workbook.

Right click the above figure, and select the 3D view to get the
3D view of the above column chart.

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in


3D view of the column chart

350
300
250
total

200

Jan

150

Feb

100

Mar

50

Total

Mar

0
Car Auto
Jeep Van
Vehicle

Jan

Month

Total

3. Draw a stacked bar graph to show the sale of each vehicle in comparison
with the total sales for the month.
Highlight the data to be charted.
Choose Chart from the Insert menu
Choose the Chart type: Bar and then select the desired chart sub-type
from the samples on display. Click on the Next button.
In the dialog box, the default radio button for columns would be
selected. If the range is correct, click on the Next button.
Select Titles tab from the dialog box and enter the chart title,
category x axis value, y axis value.
Click on the Legend folio and select the desired placement where the
legends should be displayed. Click on the next button.
Click once on the As object in radio button and specify the object
name.
Click on the finish button and get the desired chart on the workbook.

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

4. Draw a Line graph to show the sales trend over the first quarter of the
year 2011.
Highlight the data to be charted.
Choose Chart from the Insert menu
Choose the Chart type: Line and then select the desired chart sub-type
from the samples on display. Click on the Next button.
In the dialog box, If the range is correct, click on the Next button.
Select Titles tab from the dialog box and enter the chart title,
category x axis value, y axis value.
Click on the Legend folio and select the desired placement where the
legends should be displayed. Click on the next button.
Click once on the As object in radio button and specify the object
name.
Click on the finish button and get the desired chart on the workbook.

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

5. Type the following data in column F


F
1.

Cost

2.

200000

3.

700000

4.

900000

5.

1000000

Draw an XY graph comparing two numerical variables viz., cost of the


vehicle andsale of the vehicle.
Enter the above data in the worksheet
Select the Total and Cost columns from the worksheet
Choose Chart from the Insert menu
Choose the Chart type: XY(Scatter) and then select the desired chart
sub-type from the samples on display. Click on the Next button.
9

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

In the dialog box, If the range is correct, click on the Next button.

Select Titles tab from the dialog box and enter the chart title,
category x axis value, y axis value.
Click on the Legend folio and select the desired placement where the
legends should be displayed. Click on the next button.
Click once on the As object in radio button and specify the object
name.
Click on the finish button and get the desired chart on the workbook.

Result

10

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

Ex.No:3

FLOWCHART DRAWING

Aim
To draw a flowchart in Microsoft word.

Procedure
Right click on the tool bars.
Click and include the drawing tool bar .
Click Auto shape.
Select flow chart.
Click on the symbol .Drag on the document. Add text.
Basic Flowcharting Shapes
Flowcharts use special shapes to represent different types of actions or steps
in a process. Lines and arrows show the sequence of the steps, and the
relationships among them.

Start/End

system. It

hdhfjhjsdh
Action or

The terminator symbol marks the starting or ending point of the


It usually contains the word Strat or End.

A box can represent a single step or an entire sub-process within a larger

Process

process.

Document

process

A printed document or report.

11

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in


A decision or branching point. Lines representing different decisions
Decision

emerge fr

emerge from different points of the diamond.

Represents material or information entering or leavithe system.


Input/
Output

Indicates that the flow continues on another page, where a matching


Connector

symbol has

Flow

symbol has been placed (containing the same letter).

Lines indicate the sequence of steps and the direction of flow.

Result:

12

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

1. Operators & Expressions


Ex.No.4A

MENU DRIVEN CALCULATOR USING SWITCH CASE

Aim
To write a simple menu driven calculator program using switch
statement
Algorithm
Step 1: Start the program
Step 2: Read a, b, c and ch
Step 3: Pass ch to switch statement
Step 4: If ch is +, print c=a+b
Step 5: If ch is -, print c=a-b
Step 6: If ch is *, print c=a*b
Step 7: If ch is /, print c=a/b
Step 8: Print enter correct operator in default case
Step 9: End of program
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,choice;
clrscr();
printf("\n eneter the first no.:");
scanf("%d",&a);
printf("\n enter the second no.:");
scanf("%d",&b);
printf("1.addition \n");
printf("2.subtraction \n");
printf("3.multiplication \n");
13

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

printf("4.division \n");
printf("0.exit \n");
printf("\n enter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:c=a+b;printf("%d",c);break;
case 2:c=a-b;printf("%d",c);break;
case 3:c=a*b;printf("%d",c);break;
case 4:c=a/b;printf("%d",c);break;
case 0:exit(0);break;
default :printf("the choice is out of range \n");
}
getch();
}
OUTPUT:
Enter the first no:3
Enter the second no:2
Enter ur choice:3
6
Result:

2. Control Structures.

Ex.No.4B

MULTIPLICATION TABLE

Aim
To print multiplication table for the given number.
Algorithm
Step 1: Start the program
Step 2: Read number, count value and a
Step 3: Initialize for loop with a=1 and check the condition a<=count value
and

increment a by 1 until the given condition fails

Step 4: Then print number, a and number*a


14

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

Step 5: End of program


Program
#include<stdio.h>
#include<conio.h>
void main()
{
int product,n,i;
clrscr();
printf("\n enter the no. of table");
scanf("%d",&n);
printf("the result is \n");
for( i=1;i<=10;i++)
{
product=i*n;
printf("%d*%d=%d \n",i,n,product);
}
getch();
}
OUTPUT
enter the no. of table
the result is
1*5=5
2*5=10
3*5=15
4*5=20
5*5=25
6*5=30
7*5=35
8*5=40
9*5=45
10*5=50

Result:

Ex.No.4C

PALINDROME OR NOT

Aim
To write a C program to check the palindrome of a number
15

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

Algorithm
Step 1: Start the program
Step 2: Read the number from the user
Step 3: Separate each digit by dividing the number by 10
Step 4: Store the remainder in other variable to reverse the number
Step 5: If the original number is equal to the reversed number then that
number is palindrome
Step 6: If the original number is not equal to the reversed number then
that number is not palindrome
Step 7: Display the result
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int num,b=0,c=0,e;
clrscr();
printf("Enter the number:\n");
scanf("%d",&num);
e=num;
while(num>0)
{
b=num%10;
c=c*10+b;
num=num/10;
}
if(e==c)
{
printf("The number is a palindrome",c);
}
else
{
printf("The number is not a palindrome",c);
}
getch();
}
16

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

OUTPUT:
Enter the number: 121
The number is a palindrome
Enter the number: 134
The number is not a palindrome
Result:
Ex.No.5A

PRIME NUMBER OR NOT

Aim
To check and print whether the given number is prime number or not.
Algorithm
Step 1: Start the program
Step 2: Read a
Step 3: Check if a=1 and if it yes print 1 is neither a prime number nor a
composite number
Step 4: Initiate b=2 and check b<=a-1 in the while loop, if yes enter the
while loop
Step 5: If a%b=0, print given number is not a prime number
Step 6: If b=a print given number is a prime number
Step 7: End of program
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i;
clrscr();
printf("Enter the number:\n");
scanf("%d",&num);
for(i=2;i<num;i++)
{
if(num%i==0)
{
printf("The number is not a prime number");
break;
17

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

}
else continue;
}
if(i==num)
printf("The number is a prime number");
getch();
}
OUTPUT:
Enter the number 3
The number is a prime number
Result:
Ex.No.5B

GENERATING FIBONACCI SERIES

AIM
To write a C program to generate a Fibonacci series.
ALGORITHM
1. 1.Start the program
2. Read the limit n from the user.
3. Assign f1=0,f2=1.
4. Set loop for I and for all i<n value calculate f3=f1+f2.
5. Assign f1=f2 and f2f3.
6. 6.Display f1.
7. 7.Stop the program
Program
#include<stdio.h>
void main()
{
int n,f0=0,f1=1,f2,i;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
f2=f0+f1; f0=f1;
f1=f2;
printf("%d\t",f2);
}
18

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

getch();
}
OUTPUT:
Enter the number : 7
The fibannoci series is
0112358
RESULT:
3. Arrays
Ex.No.6A FINDING THE LARGEST AND SMALLEST NUMBER
OF AN ARRAY
AIM:
To write a C program to find the Largest and Smallest number of an array.
ALGORITHM
1. 1.Start the program
2. Read total numbers in an array.
3. Read the numbers in an array.
4. Initialize max=0,and min=32767.
5. Set the loop and check for, all the I element a[i]>max=a[i].
6. Check for all the I value a[i]<min then assign min=a[i].
7. Print the maximum and minimum values after execution of the loop.
8. Stop the program.
Program
#include<stdio.h>
#include<conio.h>
#define n 8
void main()
{
int i,a[10],max,min;
int num[n];
clrscr();
for(i=0;i<n;i++)
{
printf("Enter the numbers one by one \n",a[i]);
scanf("%d",&a[i]);
19

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

max=a[0]; min=a[0];
}
for(i=1;i<n;i++)
{
if(a[i]>max)
{
max=a[i];
}
if(a[i]<min)
{
min=a[i];
}
}
printf("The smallest number is %d\n",min);
printf("The largest number is %d",max);
getch();
}
OUTPUT:
Enter the total numbers:5
Enter the numbers one by one:34
78
12
90
56
The largest number is 90
The smallest number is 12
RESULT:

Ex.No.6B

SORTING IN ASCENDING AND DESCENDING ORDER

Aim
To Sort numbers in an array in ascending / descending order.
Algorithm
Step 1: Start the program
Step 2: Read n
Step 3: Read n numbers using for loop

20

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

Step 4: Enter for loops by checking the conditions i<=n-1 and j<n and by
initializing for loops with i=0, j=i+1
Step 5: If (a[i]>a[j]), swap these two variables with another variable temp
Step 6: Print the ascending orders by initializing for loop with i=0 and the
condition is i<n by incrementing i in steps of 1
Step 7: Print the descending order by initializing for loop with i=n-1 and the
condition is i>=0 by decrementing i in steps of 1
Step 8: End of program
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,num[10],temp;
clrscr();
printf("Enter the elements\n");
scanf("%d",&n);
printf("Enter the numbers one by one\n");
for(i=0;i<n;i++)
scanf("%d",&num[i]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(num[i]>num[j])
{
temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}
}
printf("\n ASCENDING ORDER\n");
for(i=0;i<n;i++)
printf("%d\t",num[i]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
21

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

{
if(num[i]<num[j])
{
temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}
}
printf("\n DESCENDING ORDER\n");
for(i=0;i<n;i++)
printf("%d\t ",num[i]);
getch();
}
OUTPUT:
Enter the elements:6
Enter the numbers one by one:
34
89
12
67
56
78
ASCENDING ORDER
12
34
56
67
78
89
DESCENDING ORDER
89
78
67
56
34
12
Result:

22

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

Ex.No.6C

MATRIX ADDITION

Aim
To write a C program to add the two matrices

Procedure
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: Set a loop for rows
Step 6: Set an inner loop for columns
Step 7: Add the elements of A and B in column wise and kept the result in C
matrix
Step 8: After the execution of the loops, print the C matrix
Step 9: End the program
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int a[25][25],b[25][25],c[25][25];
int i,j,m,n;
clrscr();
printf("Enter the row and column");
scanf("%d%d",&m,&n);
printf("Enter the elements of A matrix:");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("Enter the elements of B matrix:");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&b[i][j]);
23

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

printf("\nElements 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 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("\nThe addition of two matrics:");
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]);
}
}
getch();
}
OUTPUT:
Enter the row and column:3
Enter the elements of A matrix:5 7 2 9 6 11 4 8 23
Enter the elements of B matrix: 6 8 4 11 7 23 6 35 12
Elements of A matrix:
572
9 6 11
4 8 23
Elements of B matrix:
684
11 7 23
6 35 12
The addition of two matrix:
11 15 6
20 13 34
10 43 35
24

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

Result:

Ex.No.6D

MATRIX MULTIPLICATION

Aim
To write a program to perform matrix multiplication
Algorithm
Step 1: Start the program
Step 2: Get the order of matrix A and B
Step 3: Check whether the rows of matrix A is equal to columns of matrix B
Step 4: If the condition is true get the values for matrices A and B
Step 5: Initialize i to be zero and check i< rows of matrix B
Initialize j to be zero and check j< columns of matrix B
Step 6: Initialize k to be zero and check k< rows of matrix A
Step 7: Perform d[i][j]=d[i][j] + (a[i][j] * b[i][j]) until the above condition
satisfies
Step 8: Print the resultant matrix d[i][j]
Step 9: End the program
#include<stdio.h>
#include<conio.h>
void main()
{
int a[25][25],b[25][25],c[25][25];
int i,j,k,m,n,p,q;
clrscr();
printf("Enter the row and column of A matrix");
scanf("%d%d",&m,&n);
printf("Enter the row and column of B matrix");
scanf("%d%d",&p,&q);
if(n==p)
{
printf("multiplication is possible");
printf("Enter the elements of A matrix:");
for(i=0;i<m;i++)
25

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("Enter the elements of B matrix:");
for(i=0;i<p;i++)
for(j=0;j<q;j++)
scanf("%d",&b[i][j]);
printf("\nElements 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 Elements of B matrix:");
for(i=0;i<p;i++)
{
printf("\n");
for(j=0;j<q;j++)
printf("\t%d",b[i][j]);
}
perintf("\nThe multipliaction of two matrix:");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<q;j++)
printf("\t%d",c[i][j]);
}
}
else
printf("matrix multiplication is not possible");
getch();
26

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

}
OUTPUT:
Enter the row and column of A matrix:3 3
Enter the row and column of B matrix:3 3
Enter the elements of A matrix:1 2 3 4 5 6 7 8 9
Enter the elements of B matrix:9 8 7 6 5 4 3 2 1
Elements of A matrix:
123
456
789
Elements of B matrix:
987
654
321
The multiplication of two matrix
30 24 18
84 69 54
138 114 90
Result:

4. STRINGS
Ex.No.7A STRING MANUIPULATION WITHOUT USING LIBRARY
FUNCTIONS - STRING CONCATENATION
Aim
To concatenate the given strings without using library functions
Algorithm
Step 1: Start the program
Step 2: Read name1[20], name2[20], i and c
Step 3: Check the condition name1[i] !=\0 in while loop and increment i by
1 until condition fails
Step 4: Check another condition name2[i] !=\0 in while loop and store the
elements of name2 in name1 and increment c by 1 until condition fails
Step 5: Print the concatenated string
Step 6: End of program
27

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

Program
#include<stdio.h>
#include<conio.h>
void main()
{
Char str1[10],str2[10],str3[40];
int I,j;
clrscr();
printf(Enter the two string:);
scanf(%s%s,str1,str2);
for(i=0;str[i]!=\0;i++)
{
str3[i]=str1[i];
}
for(j=0;str[j]!=\0;j++)
{
str3[i]=str2[j];
i++;
}
str3[i]=\0;
printf(Concatenated string is %s\n,str3);
getch();
}
Output 1
Enter the two string: divya malli
Concatenated string is divyamalli
Output 2
Enter the two string: DIVS Publishers
Concatenated string is DIVSPublishers
28

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

Result:

Ex.No.7B STRING MANUIPULATION WITHOUT USING LIBRARY


FUNCTIONS - STRING COMPARISON
Aim
To compare the two given strings without using library functions
Algorithm
Step 1: Start the program
Step 2: Read name1[10], name2[10] and initialize i=0
Step 3: Check the condition name[i] = name[2] and name1[i] !=\0
Step 4: If the condition is true increment i by 1 and then if name1[i] =
name2[i], print given two strings are equal
Step 5: Then if the above condition is false, print given two strings are not
equal
Step 6: End of program
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
char str1[20],str2[20];
clrscr();
printf(Enter the first and second string:);
scanf(%s%s,str1,str2);
for(i=1;i<2;i++)
{
if(str1[i]==str2[i])
29

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

printf(The both string is equal);


else
printf(The both string is not equal);
getch();
}
}
Output 1
Enter the first and second string: divya divya
The both string is equal

Output 2
Enter the first and second string: divya malli
The both string is not equal
Result:

Ex.No.7C SORTING THE NAMES IN ALPHABETICAL ORDER


AIM
To Write a C program to sort the names in alphabetical order using string
function.
ALGORITHM
1. Start the program.
2. Enter number of names.
3. Enter the names.
4. Set two loops and compare every two strings.
5. If strcmp function return greater than zero value then swap two
strings. Using strcpy function and use temporary variable.
6. Repeat step 5 until all the strings are compared.
7. Stop the program.
PROGRAM:
30

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char names[20][20],temp[10];
int i,j,n;
clrscr();
printf("Enter the no of names:");
scanf("%d",&n);
printf("Enter names to sort: \n");
for(i=0;i<n;i++)
{
scanf("%s",names[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(strcmp(names[i],names[j])>0)
{
strcpy(temp,names[i]);
strcpy(names[i],names[j]);
strcpy(names[j],temp);
}
}
}
printf("The sorted order is:\n");
for(i=0;i<n;i++)
{
printf("%s\n",names[i]);
}
getch();
}
OUTPUT:
Enter the no of names4
Enter names to sort
Bala
Arun
Mala
Sudha
The sorted order is
31

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

Arun
Bala
Mala
Sudha
RESULT:

5. Functions
Ex.No.8A

BUBBLE SORTING

Aim
To implement bubble sorting in C.
Procedure
Step 1: Start the program
Step 2: Get the total number of elements of the array as n
Step 3: Get the elements of the array
Step 4: Initialize a for loop with i as 1 and continue the loop until the
condition i<n is true and increment i insteps of 1
Step 5: Initialize an inner for loop with j as 1 and continue the loop until the
condition j<=n-1 and increment j insteps of 1
Step 6: Check the condition a[j] > a[j+1] and if so swap the elements
Step 7: Print the sorted elements of the array
Step 8: End the program
Program
#include<stdio.h>
#include<conio.h>
void main()
32

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

{
int i,n,a[10];
clrscr();
printf("Enter the no of elements:");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
bubble(n,a);
getch();
}
int bubble(int n,int x[])
{
int i,j,temp;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(x[i]>x[j])
{
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
}
}
printf("After sorting:");
for(i=0;i<n;i++)
printf("%d\t",x[i]);
}
OUTPUT
Enter the no. of elements
5
10
56
23
89
12
After sorting
10
12
23
56
33

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

89
Result:

Ex. No.8B

SEQUENTIAL SEARCH

Aim
To perform sequential search operation in an array of elements
Procedure
Step 1: Start the program
Step 2: Get the total number of elements as n
Step 3: Get an elements of the array
Step 4: Get the number to be searched in the array as no
Step 5: Pass the array elements to a function
Step 6: Initialize a for loop with i as 1 and check if i<a[n] and increment i insteps of 1
Step 7: Check if the number to be searched is equal to element in the array,
if so then print the position of the number and the number and get
out of the loop
Step 8: If not so then, print as the number is not in the array
Step 9: End the program

Program
#include<stdio.h>
#include<conio.h>
void seq(int [],int ,int);
void main()
{
int a[50],n,x,i;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
34

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

printf("enter the elements:");


for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("Enter the number to search:");
scanf("%d",&x);
seq(a,n,x);
getch();
}
void seq(int b[],int r,int t)
{
int i,f=0;
for(i=1;i<=r;i++)
{
if(b[i]==t)
f=f+1;
}
if(f!=0)
{
printf("Element found");
return;
}
else
printf("Element not found");
}

OUTPUT:
Enter the number:5
enter the elements:1
2
3
4
5
Enter the number to search:2
Element found
Result:

35

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

Ex.No.9

FACTORIAL OF A NUMBER IN RECURSIVE METHOD

Aim
To find the factorial of a number in recursive method
Algorithm
Step 1: Start the program
Step 2: Read n, fact
Step 3: Call the function factorial(n)
Step 4: If n is 0, return 1 and if not return (n*factorial(n))
Step 5: Print fact
Step 6: End of program
Program
#include<stdio.h>
#include<conio.h>
void main()
{
long int factorial(int );
int n;
long int fact;
clrscr();
36

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

printf("Enter the number:");


scanf("%d",&n);
fact=factorial(n);
printf("Factorial of is %d is %ld \n",n,fact);
getch();
}
long int factorial(int x)
{
long int fact;
if(x==0)
return 1;
else
fact=x*factorial(x-1);
return fact;
}

OUTPUT:
Enter the number:5
Factorial of 5 is 20
Result:

6. Structures and Union


Ex.No.10A PRINTING MARKSHEETS OF n STUDENTS
USING STRUCTURES
Aim
To print the mark sheet of n students using structures
Algorithm
Step 1: Start the program
Step 2: Initiate structure student with char name[25] and integer physics,
chemistry, mathematics and total
Step 3: Read the number of student
Step 4: Read name, physics, chemistry, mathematics marks using for loop
37

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

Step 5: Print the name, physics, chemistry, mathematics marks


Step 6: Obtain the total by adding physics, chemistry and mathematics
marks
Step 7: Print the total marks
Program:
#include<stdio.h>
#include<conio.h>
struct student
{
char name[10],grade;
int rollno,m1,m2,m3,total;
float avg;
};
void main()
{
int n,i,j;
struct student s1[10];
clrscr();
printf("Enter the number of students:");
scanf("%d",&n);
printf("Enter student number,name,and 3 subjects marks....\n");
for(i=1;i<=n;i++)
{
printf("Enter the roll number:\n");
scanf("%d",&s1[i].rollno);
printf("Enter the name:\n");
scanf("%s",&s1[i].name);
printf("Enter the Mark1:\n");
scanf("%d",&s1[i].m1);
printf("Enter tha Mark2:\n");
scanf("%d",&s1[i].m2);
printf("Enter the Mark3:\n");
scanf("%d",&s1[i].m3);
s1[i].total=s1[i].m1+s1[i].m2+s1[i].m3;
s1[i].avg=s1[i].total/3;
if(s1[i].m1<35||s1[i].m2<35||s1[i].m3<35)s1[i].grade='F';
else
{
if(s1[i].avg>=75)s1[i].grade='D';
else if (s1[i].avg<75)s1[i].grade='F';
38

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

else if(s1[i].avg<60)s1[i].grade='S';
else if(s1[i].avg<50)s1[i].grade='T';
}
}
printf("\n The details of the marklist is as follows\n");
printf("\nRollno");
printf("\tName");
printf("\tMark1");
printf("\tMark2");
printf("\tMark3");
printf("\tTotal");
printf("\tAVERAGE");
printf("\tGRADE");
printf("\n");
for(i=1;i<=n;i++)
{
printf("\n%d",s1[i].rollno);
printf("\t%s",s1[i].name);
printf("\t%d",s1[i].m1);
printf("\t%d",s1[i].m2);
printf("\t%d",s1[i].m3);
s1[i].total=s1[i].m1+s1[i].m2+s1[i].m3;
printf("\t%d",s1[i].total);
printf("\t%f",s1[i].avg);
printf("\t%c",s1[i].grade);
}
getch();
}
OUTPUT:
Enter the number of students:2
Enter student number,name,and 3 subjects marks:
Enter the roll number:35
Enter the name:Priya
Enter the Mark1:45
Enter the Mark2:98
Enter the Mark3:78
Enter student number,name,and 3 subjects marks:
Enter the roll number:36
Enter the name:Asha
Enter the Mark1:98
39

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

Enter the Mark2:56


Enter the Mark3:75
The details of the marklist is as follows:
Roll no Name Mark1 Mark2 Mark3 Total
35
Priya
45
98
78
221
36
Asha
98
56
75
239
Result:

Ex.No.10B PROGRAM TO FIND SIZE OF UNION AND NUMBER


OF BYTES RESERVED FOR IT
Aim:
To find size of union and number of bytes reserved for it

Algorithm:
Step1: start the program
Step 2: initialize the union and structure name
Step 3: print size of the union and structure
Program:
#include<stdio.h>
void main()
{
union result
{
int marks;
char grade;
};
struct res
40

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

{
char name[15];
int age;
char sex;
char address;
int pincode;
union result perf;
}
clrscr();
printf("Size of Union:%d\n",sizeof("data.perf"));
printf("Size of Structure:%d\n",sizeof("data"));
getch();
}
Output:
Size of Union:10
Size of Structure:5
RESULT:

Ex.No.10C PROGRAM TO PRINT THE VALUES USING UNION


Aim:
To print the values using union
Algorithm:
Step 1: start the program
Step 2: initialize the union
Step 3: read the variables a and b
Step 4: print the values of a and b
Step 5: stop
Program:
#include<stdio.h>
#include<conio.h>
union name
{
int a;
char b[2];
};
main()
{
union name c;
c.a=256;
41

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in

clrscr();
printf("c.a value is %d\n",c.a);
printf("c.b[0] value is %d\n",c.b[0]);
printf("c.b[1] value is %d\n",c.b[1]);
getch();
}
Output:
c.a value is 256
c.b[0] value is 0
c.b[1] value is 1
RESULT:

Ex No.11 PROGRAM TO FIND THE SUM OF SERIES

Aim: Program to print the following series until there sum exceeds 2.6 term value exceeds 1.5
x+x2/2!+x3/3!+------------.

Program:
#include<stdio.h>
#include<conio.h>
main( )
{
float x,sum=0,prod=1;
int i;
clrscr( );
printf(enter x value);
scanf(%f,&x);
i=1;
while((sum<2.6)&&(prod<=1.5))
{
prod=prod*(x/i);
If(prod<=1.5)
sum=sum+prod;
if(sum>2.5)
42

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in


{
sum=sum-prod;
Break;
}
printf(sum=%f,sum);
I++;
}
getch();
}

43

Vous aimerez peut-être aussi