Académique Documents
Professionnel Documents
Culture Documents
Output
GLOBAL INSTITUTE
OF ENGINEERING & TECHNOLOGY
Melvisharam, Vellore
Courses
Offered
SALIENT FEATURES
Highly Qualified staffs
Well equipped labs
ECE
CSE
EEE
Mech
Ex No : 01
Date :
MS WORD
Aim:
To create a Microsoft word document and perform the various text manipulation
operations.
Procedure:
1. Create a new word document using File-> New option, and justify the text by
using the justify button on the formatting tool bar.
2. For Bold, Italic and Underline press the CTRL+B, CTRL+I, CTRL+U
respectively.
3. For Left, Right and Center alignment press the CTRL+C, CTRL+R, CTRL+E
respectively.
4. Select the text were we want to add the Bullets and Numberings. Then select the
Bullets and Numbering option from the Formatting tool bar.
5. For line spacing select the text and click the Paragraph option from the Format
menu.
6. Select the 1.5 lines from the line spacing list box, and then click OK.
7. If you want to change the text style and size, select the text which you want to
change and check the Font option from Format menu.
8. Choose the required font type from the font drop down list box and the size from
the size list box. Then click OK.
9. To insert the Symbols put the cursor where you want to insert the symbol. Then
select the symbol from the Insert menu.
10. Then choose required symbol from the symbol dialog box, then click Insert.
Result:
Thus the word document is created and all the text manipulation operations are
tested successfully.
Table
Name
Dhamu
Mark 1
60
Mark 2
55
Mark 3
50
Total
165
Average
55
Kumar
40
60
50
150
50
Priya
90
75
81
246
82
Raj
90
75
81
246
82
Ram
80
85
72
237
79
Ramya
80
65
74
219
73
Ex No : 02
Date :
TABLE CREATION
Aim:
To create a table in Microsoft Word and perform the various table formatting
operations.
Procedure:
1. Choose the Table option from the menu bar, and then choose the Insert -> Table
option from the table option.
2. Choose the required number of rows and columns, and then click OK.
3. Now the table is inserted in your document, enter the text in the columns.
4. After adding the text, place the cursor in the table and click Table -> Sort.
5. It shows the Sort Dialog Box, from that select the field which you want to sort.
Select the Ascending from the drop down list and click OK.
6. For calculating the sum, place the cursor in the appropriate and click Table ->
Formula, it will display a formula dialog box with=.
7. Click OK, now the sum is displayed in the column. Do the same for remaining
columns also.
8. If you want to add a row in your table means, place the cursor at the last row and
click Table -> Insert -> Rows this will creates the Blank row.
9. Like this we can insert the rows above are below to the current row.
10. For columns also we can follow the same as the rows.
11. If you want to give the various formats to your table, then select Table Auto
Format in the Table menu.
12. It shows the table auto Format Dialog Box, choose the required format then click
OK.
Result:
Thus the table is created and formatted in the Microsoft Word Document.
Table
Name
Dham
u
Kuma
r
Priya
Raj
Ram
Ramy
a
Mark 1
Mark 2
Mark 3
Total
Average
60
55
50
165
55
THIRD
40
60
50
150
50
FAIL
90
75
81
246
82
First
90
75
81
246
82
First
80
85
72
237
79
First
80
65
74
219
73
SECOND
Chart
Picture
Class
Ex No : 03
Date :
SPREAD SHEET
Aim:
To create a Spread sheet with various fields of datas and charts. And also insert
the objects and pictures in the sheet.
Procedure:
1. Enter the name and three subjects names in the first row of the Spreadsheet.
2. Enter the marks of the each student.
3. Place the cursor in the column Sum and type = SUM(B2..D2).
4. Place the cursor in the column Average and type = AVERAGE(B2D2).
5. Place the cursor in the column Class and type the following Formula to find the
class of the student.
=IF(OR(B5<50,C5<50,E5<50),"FAIL",IF(F5>75,"FIRST",IF(F5>60,"SECO
ND","THIRD")))
6. To create the chart for the student marks, first select the name and marks column.
Then click the Chart Wizard from the Formatting Toolbar.
7. It shows the Chart Wizard Step 1 of 4. Choose the chart type and click Next.
8. It shows the Chart Wizard step 2 pf 4. Chart Source Data dialog Box, choose
the chart source and click on Next.
9. It shows the Chart Wizard- step 3 of 4, Chart Option Dialog box, choose the
Chart Title, X- Axis and Y- Axis labels and click on Next.
10. It shows the Chart Wizard- step 4 of 4, choose the Chart Location and click on
Next. Then click Finish.
11. Now the chart is shown in the sheet.
12. If you want to insert the picture select the Picture option from the Insert menu. If
opens a sub menu from that select the Clip Art.
13. Clip Art window will open. You can select any clip art from the list and insert in
your sheet by clicking Insert.
Result:
7
Thus the Spreadsheet is created with various fields and operations, and also
various types of charts and pictures are inserted
Flow Chart
Start
Read A,B;
C = A + B;
Print C
C = A - B;
Print C
C = A B;
Print C
C = A / B;
Print C
Stop
10
Ex no : 04
Date
ARITHMETIC OPERATIONS
Aim:
Write a C program to perform all the basic arithmetic operations.
Algorithm:
1.
2.
3.
4.
5.
6.
7.
8.
9.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int A,B,C;
clrscr();
printf("\n Enter the value for A
scanf("%d",&A);
printf("\n Enter the value for B
scanf("%d",&B);
C=A+B;
printf("\n Sum of A and B is
C=A-B;
printf("\n Difference of A and B is
C=A*B;
printf("\n Product of A and B is
C=A/B;
printf("\n Quotient of A by B is
getch();
}
: ");
: ");
: %d",C);
: %d",C);
: %d",C);
: %d",C);
11
12
Output:
Enter the value of A : 10
Enter the value of B : 5
Sum of A and B is
Difference of A and B is
Product of A and B is
Quotient of A by B is
: 15
:5
: 50
:2
Result:
Thus the C program to perform the basic arithmetic operations is written and
executed successfully.
13
Flow Chart
Start
Read a, b,
n;
No
Switc
h
(n)
Yes
Yes
No
Ca
se
1
C=a+b;
Print
c;
C=a+b;
Print
c;
C=a+b;
Print
c;
C=a+b;
Print
c;
Yes
Ca
se
2
No
Ca
se
3
Yes
No
Yes
Ca
se
4
No
Ca
se
0
Yes
exit ( );
No
Stop
14
Ex No : 05
Date :
Algorithm:
1.
2.
3.
4.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,n;
clrscr();
printf("\n OUTPUT ");
printf("\n ~~~~~~ ");
printf("\n Enter the values for A and B : ");
scanf("%d%d",&a,&b);
printf("\n 1.Addition");
printf("\n 2.Subtraction");
printf("\n 3.Multiplication");
printf("\n 4.Division");
printf("\n 0.Exit");
15
16
Output 1 :
Enter the values for A and B : 10 2
1.Addition
2.Subtraction
3.Multiplication
4.Division
0.Exit
Enter your choice : 1
The sum is : 12
Output 2 :
Enter the values for A and B : 10 5
1.Addition
2.Subtraction
3.Multiplication
4.Division
0.Exit
17
18
Output 3 :
Enter the values for A and B : 10 5
1.Addition
2.Subtraction
3.Multiplication
4.Division
0.Exit
Enter your choice : 3
The product is :50
Output 4 :
Enter the values for A and B : 10 5
1.Addition
2.Subtraction
3.Multiplication
4.Division
0.Exit
Enter your choice : 4
The quotient is : 2
Output 5 :
Enter the values for A and B : 10 5
1.Addition
2.Subtraction
3.Multiplication
4.Division
0.Exit
Enter your choice : 5
Enter the correct choice.
Result:
Thus the menu driven calculator is executed successfully.
19
Flow Chart
Start
Read x,n;
No
while
(i<=n
)
Yes
Stop
y=x*i;
Print i,x,y;
i++;
20
Ex No : 06
Date :
MULTIPLICATION TABLE
Aim:
Write a C program to generate a multiplication table by using the while statement.
Algorithm:
1.
2.
3.
4.
5.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y=1,i=1,n;
clrscr();
printf("\n Enter the table you want : ");
scanf("%d",&x);
printf("\n Enter the no number of terms : ");
scanf("%d",&n);
while(i<=n)
{
y=x*i;
printf("\n %d * %d = %d",i,x,y);
i++;
}
getch();
}
21
22
Output:
Enter the table you want : 5
Enter the no number of terms : 12
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
11 * 5 = 55
12 * 5 = 60
Result:
Thus the coding for generating the multiplication table is written and executed
successfully.
23
Flow Chart
Start
Read X;
x=x*3.14/180;
t=x;
sum=x;
for(i=1;i<n+1;i++)
t=(t*pow((double)(-1),(double)(2*i1))*x*x)/(2*i*(2*i+1));
sum=sum+t;
Print sum;
Stop
24
Ex No : 07
Date :
SIN SERIES
Aim:
Write a C program to print the sin series
Algorithm:
1.
2.
3.
4.
5.
6.
7.
8.
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x,t,sum;
int i,n=10;
clrscr();
printf("\n Enter the value of X : ");
scanf("%f",&x);
printf("%4.2f %d\n",x,n);
x=x*3.14/180;
t=x;
sum=x;
for(i=1;i<n+1;i++)
{
t=(t*pow((double)(-1),(double)(2*i-1))*x*x)/(2*i*(2*i+1));
sum=sum+t;
}
printf("\n The value of SIN(X) = %6.2f\n",sum);
getch();
}
Output:
Enter the value of X: 90
The value of SIN(X) = 1.00
Result:
Thus sin series program is written and executed successfully.
25
Flow Chart
Start
Read n;
yes
no
if
(n ==
0)
for(i=0;i<n;i++)
Print 0;
f=f+a;
a=b;
b=f;
Print f;
Stop
26
Ex No : 08
Date :
FIBONACCI SERIES
Aim:
Write a C program to generate the Fibonacci series.
Algorithm:
1.
2.
3.
4.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int f=0,n,a=0,b=1,i;
clrscr();
printf("\n Enter the no of terms : ");
scanf("%d",&n);
printf("\n Fibonacci sequence upto %d terms : ",n);
if(n==0)
{
printf("\n 0");
}
else
{
for(i=0;i<n;i++)
{
f=f+a;
a=b;
b=f;
printf(" %d",f);
}
}
getch();
}
27
28
Output:
Enter the no of terms : 5
Fibonacci sequence upto 5 terms : 0 1 1 2 3
Result:
Thus the Fibonacci series is generated successfully by using the C coding.
29
Flow Chart
Start
Read n;
false
whil
(i<=
n)
true
print f;
f = f*i;
i++;
Stop
30
Ex No : 09
Date :
FACTORIAL
Aim:
Write a C program to find the factorial of the given number.
Algorithm:
1. Start the program.
2. Read the number, initialize i = 1 and f = 1.
3. while(i<=n)
{
f=f*i;
i++;
}
4. Print the f value.
5. Stop the Program.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int f=1,n,i=1;
clrscr();
printf("\n Enter the number : ");
scanf("%d",&n);
while(i <= n)
{
f = f*i;
i++;
}
printf("\n Factorial of %d is %d",n,f);
getch();
}
Output:
Enter the number : 5
Factorial of 5 is 120
Result:
Thus the factorial of the given number is calculated successfully.
31
Flow Chart
Start
Read a,b,c;
d=b*b-4*a*c;
Yes
No
if
(d==
0)
No
Print roots
are real &
equal
if
(d >
0)
Yes
r1 = (-b+sqrt(d))/(2*a);
r2 = (-b-sqrt(d))/(2*a);
Print roots
are imaginsry
Stop
32
Print roots
are real &
unequal
Print r1,r2;
Ex No : 10
Date :
QUADRATIC EQUATION
Aim:
Write a C program to find the roots of the given quadratic equation.
Algorithm:
1.
2.
3.
4.
5.
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,d;
float r1,r2;
clrscr();
printf("\n Enter the values of A,B and C : ");
scanf("%d%d%d",&a,&b,&c);
d=b*b-4*a*c;
if(d = = 0)
printf("\n The roots are real and equal");
else if(d > 0)
{
printf("\n The roots are real and unequal");
r1 = (-b+sqrt(d))/(2*a);
r2 = (-b-sqrt(d))/(2*a);
printf("\n Root1 : %f",r1);
printf("\n Root2 : %f",r2);
}
else
{
printf("\n The roots are imaginary");
}
getch();
}
33
34
Output 1:
Enter the values of A, B and C : 1 2 1
The roots are real and equal
Output 2:
Enter the values of A, B and C : 1 0 -9
The roots are real and unequal
Root1 : 3.0
Root2 : -3.0
Output 3:
Enter the values of A, B and C : 1 2 3
The roots are imaginary
Result:
Thus the roots of a quadratic equation are found successfully.
35
Flow Chart
Start
for(i=0;i<5;i++)
Read a[i];
for(i=0;i<5;i++)
Print a[i];
Stop
36
Ex No : 11
Date :
Algorithm:
1.
2.
3.
4.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i;
clrscr();
printf("\n Enter any five numbers : ");
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
}
printf("\n The numbers in the array are : ");
for(i=0;i<5;i++)
{
printf(" %d",a[i]);
}
getch();
}
Output:
Enter any five numbers : 1 2 3 4 5
The numbers in the array are: 1 2 3 4 5
Result:
Thus the one dimensional integer array concept is tested successfully.
37
Flow Chart
Start
for(i=0;i<5;i++)
Read a[i];
for(i=0;i<5;i++)
Print a[i];
Stop
38
Ex No : 12
Date :
Algorithm:
6.
7.
8.
9.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
char a[10];
clrscr();
printf("\n Enter any five characters : ");
for(i=0;i<5;i++)
{
scanf("%c",&a[i]);
}
printf("\n The characters in the array are : ");
for(i=0;i<5;i++)
{
printf("%c",a[i]);
}
getch();
}
Output:
Enter any five characters : KUMAR
The characters in the array are: KUMAR
Result:
Thus the one dimensional character array concept is tested successfully.
39
Flow Chart
Start
Read m,n,p,q;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
Read a[i][j];
for(i=0;i<p;i++)
for(i=0;i<q;i++)
Read b[i][j];
40
Ex No : 13
Date :
MATRIX ADDITION
Aim:
Write a C program to add two matrices.
Algorithm:
1.
2.
3.
4.
5.
6.
7.
8.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[25][25],b[25][25],c[25][25],i,j,k,m,n,p,q;
clrscr();
printf("\n Enter the no of rows and columns of matrix A : ");
scanf("%d%d",&m,&n);
printf("\n Enter the no of rows and columns of matrix B : ");
scanf("%d%d",&p,&q);
printf("\n Enter the elements of matrix A : ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf(" \n Enter the elements of matrix B : ");
for(i=0;i<p;i++)
41
for(i=0;i<m;i++)
for(i=0;i<n;i++)
c[i][j]=a[i][j]+b[i][j];
for(i=0;i<m;i++)
for(i=0;i<m;i++)
print c[i][j];
Stop
42
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
printf("%4d",c[i][j]);
}
}
getch();
}
Output:
Enter the no of rows and columns of matrix A : 2 2
Enter the no of rows and columns of matrix B : 2 2
Enter the elements of matrix A : 1 2 3 4
Enter the elements of matrix B : 1 2 3 4
2 4
6 8
Result:
Thus the matrices A and B are added successfully by using the above C program.
43
Flow Chart
Start
Read m,n,p,q;
if((m==p
) &&
(n==q))
Yes
for(i=0;i<m;i++)
for(j=0;j<n;j++)
Read a[i][j];
for(i=0;i<p;i++)
Print rows
& columns
are not
equal
for(i=0;i<q;i++)
Read b[i][j];
44
Ex No : 14
Date :
MATRIX MULTIPLICATION
Aim:
Write a C program to multiply two matrices.
Algorithm:
1.
2.
3.
4.
5.
6.
7.
8.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[25][25],b[25][25],c[25][25],i,j,k,m,n,p,q;
clrscr();
printf("\n Enter the no of rows and columns of matrix A : ");
scanf("%d%d",&m,&n);
printf("\n Enter the no of rows and columns of matrix B : ");
scanf("%d%d",&p,&q);
if((m==p) && (n==q))
{
printf("\n Enter the elements of matrix A : ");
45
for(i=0;i<m;i++)
for(i=0;i<n;i++)
c[i][j] = 0;
for(i=0;i<n;i++)
c[i][j]=c[i][j]+a[i][k]*b[k][j]
for(i=0;i<m;i++)
for(i=0;i<m;i++)
print c[i][j];
Stop
46
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf(" \n Enter the elements of matrix B : ");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=1;
for(k=0;k<m;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<n;j++)
{
printf("%4d",c[i][j]);
}
}
}
else
{
printf("\n Enter the equal no of rows and columns");
}
getch();
}
47
48
Output 1:
Enter the no of rows and columns of matrix A : 2 2
Enter the no of rows and columns of matrix B : 2 2
Enter the elements of matrix A : 1 2 3 4
Enter the elements of matrix B : 1 2 3 4
8 11
16 23
Output 2:
Enter the no of rows and columns of matrix A : 2 2
Enter the no of rows and columns of matrix B : 3 3
Enter the equal no of rows and columns
Result:
Thus the matrix multiplication program is written successfully.
49
Flow Chart
Start
Read name;
n=strlen(name)
;
Print n;
Stop
50
Ex No : 15
Date :
STRING LENGTH
Aim:
Write a C program to find the length of the string.
Algorithm:
1.
2.
3.
4.
5.
6.
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char name[25];
int n;
clrscr();
printf("\n Enter the string : ");
scanf("%s",name);
n=strlen(name);
printf("\n Length of the string is %d",n);
getch();
}
Output:
Enter the string : RAJKUMAR
Length of the string is : 8
Result:
Thus we can find the length of the string successfully.
51
Flow Chart
Start
Read name;
n=strrev(name);
Print n;
Stop
52
Ex No :16
Date :
STRING REVERSE
Aim:
Write a C program to reverse the given string.
Algorithm:
1.
2.
3.
4.
5.
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char name[25];
clrscr();
printf("\n Enter the string : ");
scanf("%s",name);
printf("\n The reversed string is : %s",strrev(name));
getch();
}
Output:
Enter the string : RAJI
The reversed string is : IJAR
Result:
Thus the given string is reversed by using the string handling function.
53
Flow Chart
Start
Read S1,S2;
n=strcmp(s1,s2);
no
yes
if(n==
0)
Print The
given strings
same
Print The
strings are
different
Stop
54
Ex No : 17
Date :
STRING COMPARISON
Aim:
Write a C program to compare the two given strings.
Algorithm:
1. Start the program.
2. Read the two strings to the variables say S1 and S2.
3. Compare the two strings by the function strcmp(), and assign the value to variable
n.
4. If n == 0 then, print, The given strings are same.
5. If n != 0 then, print the given strings are different.
6. Stop the program.
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[100],s2[100];
int n;
clrscr();
printf("\n Enter the first string : ");
scanf("%s",s1);
printf("\n Enter the second string : ");
scanf("%s",s2);
n=strcmp(s1,s2);
if(n==0)
{
printf("\n The given strings same");
}
else
{
printf("\n The strings are different");
}
getch();
}
55
56
Output 1:
Enter the first string : ram
Enter the second string : ram
The given strings same.
Output 2:
Enter the first string : raj
Enter the second string : ram
The strings are different.
Result:
Thus the two strings are compared successfully.
57
Flow Chart
Start
Read s1,s2;
strcpy(s1,s2);
Print s1,s2;
Stop
58
Ex No : 18
Date :
STRING COPY
Aim:
Write a C program to copy one string to another string.
Algorithm:
1.
2.
3.
4.
5.
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[100],s2[100];
int n;
clrscr();
printf("\n Enter the first string : ");
scanf("%s",s1);
printf("\n Enter the second string : ");
scanf("%s",s2);
strcpy(s1,s2);
printf("\n After string copy");
printf("\n First string is : %s",s1);
printf("\n Second string is : %s",s2);
getch();
}
Output:
Enter the first string : raj
Enter the second string : kumar
After string copy
First string is : kumar
Second string is : kumar
Result:
Thus second string is copied with first string successfully
59
Flow Chart
Start
Read s1,s2;
strcat(s1,s2);
Print s1;
Stop
60
Ex No : 19
Date :
STRING CONCATENATION
Aim:
Write a C program to concatenate two strings together.
Algorithm:
1.
2.
3.
4.
5.
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[100],s2[100];
int n;
clrscr();
printf("\n Enter the first string : ");
scanf("%s",s1);
printf("\n Enter the second string : ");
scanf("%s",s2);
printf("\n The concatenated string is : %s",strcat(s1,s2));
getch();
}
Output:
Enter the first string : raj
Enter the second string : kumar
The concatenated string is : rajkumar
Result:
Thus the two strings are joined successfully.
61
Flow Chart
main ( ) function
Start
Read n;
f = fact(n);
Print f;
Stop
fact( ) function
Start
Yes
No
if(n==0
|| n==1)
return(1);
return(n*fact(n-1));
Stop
62
Ex No : 20
Date :
Algorithm:
main() program
1.
2.
3.
4.
5.
6.
fact() function
1.
2.
3.
4.
Program:
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int n,f;
clrscr();
printf("\n Enter the number : ");
scanf("%d",&n);
f=fact(n);
printf("\n Factorial of %d is %d",n,f);
getch();
}
int fact(int n)
{
if(n==0 || n==1)
{
return(1);
}
else
{
return(n*fact(n-1));
}
}
63
Output:
Enter the number : 5
Factorial of 5 is 120
Result:
Thus the factorial of the given number is found successfully by using function
concept in C program.
64
Flow Chart
Start
struct std
int rno,m1,m2,m3,tot;
char name[25],grade;
float avg;
Read n
for(i=1;i<=n;i+
+)
Read
s[i].name,s[i].rno
,
s[i].m1,s[i].m2,
s[i].m3;
s[i].tot=s[i].m1+s[i].m2+s[
i].m3;
s[i].avg=s[i].tot/3;
65
Ex N0 : 21
Date :
STRUCTURE
Aim:
Write a C program to create students mark list by using the structure concept.
Algorithm:
1.
2.
3.
4.
5.
6.
7.
8.
9.
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct std
{
int rno,m1,m2,m3,tot;
char name[25],grade;
float avg;
}s[100];
void main()
{
int i,n;
clrscr();
printf("\n Enter the number of students : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\n Enter student %d's name :",i);
scanf("%s",s[i].name);
printf("\n Enter student %d's Roll No: ",i);
scanf("%d",&s[i].rno);
printf("\n Enter student %d's 3 marks : ",i);
scanf("%d%d%d",&s[i].m1,&s[i].m2,&s[i].m3);
s[i].tot=s[i].m1+s[i].m2+s[i].m3;
s[i].avg=s[i].tot/3;
if(s[i].m1<50 || s[i].m2<50 || s[i].m3<50)
66
A
B
Yes
if(s[i].m1<50
|| s[i].m2<50
|| s[i].m3<50)
No
s[i].grade='-';
s[i].grade='S'
;
for(i=1;i<=n;i+
+)
Print
s[i].name,s[i].rno,s[i
].tot,s[i].avg,s[i].gra
de
Stop
67
No
if(s[i].m1<50
|| s[i].m2<50
|| s[i].m3<50)
Yes
s[i].grade='F'
;
s[i].grade='-';
else
if(s[i].avg >= 75)
s[i].grade='F';
else if(s[i].avg >= 50)
s[i].grade='S';
}
printf("\n Name Roll No Total Avg Grade ");
for(i=1;i<=n;i++)
{
printf("\n %s\t%d\t%d\t%4.2f\t%c",s[i].name,s[i].rno,s[i].tot,s[i].avg,s[i].grade);
}
getch();
}
Output:
Enter the number of students : 2
Enter student 1's name :raj
Enter student 1's Roll No: 2
Enter student 1's 3 marks : 70 80 90
Enter student 2's name :kumar
Enter student 2's Roll No: 2
Enter student 2's 3 marks : 60 70 80
Name
raj
kumar
Roll No Total
2
2
240
210
Avg
80.00
70.00
Grade
F
S
Result:
Thus the student mark list is prepared successfully by using the structure in C
programming.
68
Flow Chart
Start
union std
char name[25];
int age;
Read s.name;
Print s.name;
Read s.age;
Print s.age;
Stop
69
Ex No : 22
Date :
UNION
Aim:
Write a C program to get and display your name and age by using union concept.
Algorithm:
1.
2.
3.
4.
5.
6.
Program:
#include<stdio.h>
#include<conio.h>
union std
{
char name[25];
int age;
}s;
void main()
{
clrscr();
printf("\n Enter your name :");
scanf("%s",s.name);
printf("\n Name : %s",s.name);
printf("\n Enter your age :");
scanf("%d",&s.age);
printf("\n Age : %d",s.age);
getch();
}
Output:
Enter your name : raj
Name: raj
Enter your age : 26
Age: 27
Result:
Thus the name and age of the student is read and displayed successfully.
70
71
72
Output 1:
Enter the number : 10
The given number 10 is even
Output 2:
Enter the number : 5
The given number 5 is odd
else
{
printf("\n The given year is not a leap year " );
}
getch();
}
Output 1:
Enter the year : 2006
The given year is leap year.
Output 2:
Enter the year : 2005
The given year is not a leap year.
Output 1:
Enter the three numbers : 30 20 10
A is the biggest no
74
Output 2:
Enter the three numbers : 20 30 10
B is the biggest no
Output 3:
Enter the three numbers : 20 10 30
C is the biggest no
75
Output1:
Enter a character : a
Drink for you : Appefizz
Output2:
Enter a character : g
Your unlucky
Output
Enter the number : 5
number & its square
1 : 1.00
2 : 1.41
3 : 1.73
4 : 2.00
5 : 2.24
76
Output:
Enter a number : 12345
The reversed no is : 54321
77
Output:
Enter the number : 5
1
2
3
4
5
Output:
Enter the Celsius value : 37
The Fahrenheit for the given Celsius is 98.60
t=(t*pow((double)(-1),(double)(2*i-1))*x*x)/(2*i*(2*i-1));
sum=sum+t;
}
printf("\n The value of COS(%d) = %6.2f\n",x,sum);
getch();
}
Output:
Enter the X value : 45
The value of COS(45) = 0.56
Output:
Enter the no of rows and columns : 2 2
Enter the elements if the matrix : 1 2 3 4
The matrix is
a. 2
79
Output:
Enter the no of rows and columns : 2 2
Enter the elements if the matrix : 1 2 3 4
The matrix is
1
2
3
4
The transpose of the matrix is
1
3
80
Output:
Enter the no : 5
The sum is 15
81
Output:
Enter the number : 5
1
12
123
1234
12345
{
int len=0,i,j;
char s[25];
clrscr();
printf("\n Enter the string : ");
scanf("%s",s);
while(s[len]!='\0')
len++;
printf("\n %d",len);
for(i=0,j=len-1;i<len/2;i++,j--)
{
if(s[i] != s[j])
{
printf("\n The given string is not palindrome");
}
else
printf("\n The given string is palindrome");
break;
}
getch();
}
Output:
Enter the string : madam
5
The given string is palindrome
Output2:
Enter the string : raj
3
The given string is not a palindrome
Output:
Enter two values : 10 20
Before swap
A = 10 B = 20
After swap
A = 20 B = 10
Output:
Reversing a string
Enter the string : c programming
gnimmargorp c
84
Output:
Enter the value : 10
The value is : 10
The address of the value is : 65524
The value in the address 65524 is 10
Write a C program to convert the given lower case character into upper
case character.
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
void main()
{
char c;
clrscr();
printf("\n Enter a character : ");
scanf("%c",&c);
printf("\n Upper case character : %c",toupper(c));
getch();
}
Output:
Enter a character : a
85
Output:
Global and Local variables
A = 100
A = 10
A = 100
{
a=20;
printf("\n A = %d",a);
}
void fun2(int a)
{
a=30;
printf("\n A = %d",a);
}
Output:
Auto variable
A = 10
A = 20
A = 30
Output:
Reading and writing strings
Enter the string ( 0 to exit ) : hi hello
87
Write a C program to append the string with the existing content of the
file.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[100],s2[100];
FILE *fp;
clrscr();
printf("\n Appending the strings");
printf("\n Content of the file before appending ");
fclose(fp);
fp = fopen("file.txt","r");
fgets(s2,50,fp);
printf("\n The string is : %s",s2);
fclose(fp);
fp=fopen("file.txt","a");
if(fp == NULL)
printf("\n Error in file operation");
else
{
printf("\n Enter the string ( 0 to exit) : ");
gets(s1);
fputs(s1,fp);
}
fclose(fp);
printf("\n Content of the file after appending");
fp = fopen("file.txt","r");
fgets(s2,50,fp);
printf("\n the string is : %s",s2);
fclose(fp);
getch();
}
Output:
Appending the strings
Content of the file before appending
The string is : hi hello
Enter the string ( 0 to exit ) : welcome to cse
Content of the file after appending
88
Output:
ASCII character set
! " # $ % & ' (
) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B
C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ]
^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x
y z { | } ~
89