c lab manual i it an
c lab manual i it an
FIRST YEAR
C PROGRAMMING LAB
STUDENT NAME :
REGISTER NO :
MADURAI KAMARAJ UNIVERSITY COLLEGE
ALAGAR KOVIL MAIN ROAD, MADURAI – 625 002
BONAFIDE
CERTIFICATE
Register Number: ______________________________
TABLE OF CONTENTS
1 Program to print a message "Hello World" on the screen
2 Program to Display Multiple Statements
3 Program to Initialize int, char, float data types
4 Program to accept the values of int, float, char data types and display them.
5 Program to accept characters and display them.
6 Program to accept 2 numbers and compute all arithmetic operations*/
7 Program to accept radius & calculate area, diameter and circumference of circle*/
8 Program to accept two numbers & swap the values using third variable*/
9 Program to accept two numbers & swap the values without using third variable*/
10 Program to accept marks and obtain total and percentage of marks*/
11 Program to evaluate the expressions*/
12 Program to check whether student is passed or failed*/
13 Program to check whether given number is even or odd*/
14 Program to find the largest of three numbers*/
15 Program to illustrate concept of else-if ladder to select color
16 Program to print words corresponding numbers below 9
17 Program to check number is positive, negative or zero*/
18 Program to check whether the given numbers are equal*/
19 Program to check whether the given character is vowel or consonant */
20 Program to calculate square of numbers whose least significant digit is 5.
21 Program to obtain electric bill as per meter reading*/
22 Program to check small,capital,digit or special*/
23 Program to check whether given letter is vowel or consonant*/
24 Program to calculate Arithmetic Operations depending on operator.
25 Program to print Multiplication Table without using looping statements*/
26 Program to Print 1 to 10 numbers*/
27 Program to display the largest of given numbers*/
28 Program to Calculate sum of 10 natural numbers*/
29 Program to Display numbers in the following format.
30 Program to print Multiplication Table using do..while statement*/
31 Program to print Fibonacci Series
32 Program to calculate factorial of given number*/
Program to take an array of 10 integers and accept values into it. Sort the array in
33 descending order.
34 Program to convert lowercase to uppercase and uppercase to lowercase.
35 Program to Concatenate of 2 Strings
36 Program to Illustrate the Concept of Pointers*/
37 Program to demonstrate how to use structure
38 Program to illustrate concept of unions.
39 Program to illustrate the concept of call by value
40 Program to find factorial of given number using recursion.
41 Program to illustrate fgets and fputs function.
Output:
Name: Sachin Tendulkar
Qualification: Degree
Address: Mumbai
Work: Cricket Player
4. To accept the values of int, float, char data types and display
them.
/*Program to accept values of int, char, float data types
Display them in the order of reading*/
#include<stdio.h>
#include<conio.h>
main()
{
char x;
int num;
float j;
clrscr();
/*Accept the values for data types from
user*/ printf("Enter Character: ");
scanf("%c",&x);
scanf("%d",&radius);
/*Compute the area, diameter and circumference*/
diameter = 2*radius;
area = PI*radius*radius;
circumference = 2*PI*radius;
/*Display the results*/
printf("Area of circle = %.2f",area);
printf("\nDiameter of circle = %d",diameter);
printf("\nCircumference of circle = %.2f",circumference);
getch();
}
Output:
Enter circle radius: 5 (Enter)
Area of circle = 78.50
Diameter of circle = 10
Circumference of circle = 31.40
num1 = num2;
num2 = temp;
printf("Numbers after swapping: %d %d",num1,num2);
getch();
}
Output:
Enter first number: 6
Enter second number: 5
Numbers before swapping: 6 5
Numbers after swapping: 5 6
Output:
(1) Enter student
marks: 55
Student Passed
(2) Enter student
marks: 40
Student Failed
Output:
(1) Enter
number: 53
53 is odd
number
(2) Enter student
marks: 42 42 is
even number
getch();
}
Output:
Enter number: 5 6 7
7 is largest
printf("Number is Negative");
if(n==0)
printf("Number is Zero");
}
Output:
Enter a number: -2
Number is Negative
Enter a number: 0
Number is Zero
Enter a number: 6
Number is Positive
else
printf("The character %c is a
consonant",x); getch();
}
Output:
Enter letter: p
The character p is a consonant
Enter letter: a
The character a is a vowel
Output:
Enter Character: a
Character a is Vowel
Enter Character: B
Character B is Consonant
Output:
The sum of 10 natural numbers is: 55
33. Take an array of 10 integers and accept values into it. Sort
the array in descending order.
#include<stdio.h>
#include<conio.h>
main()
{
int ar[10];
int i, j, temp;
clrscr();
for (i = 0 ; i < 10 ; i++)
{
printf("Enter number for [%d] element:
",i); scanf("%d", &ar[i]);
}
/* sort array in descending order
*/ for ( i = 0 ; i < 9 ; i++) {
{
/* interchange */
temp = ar[i];
ar[i] = ar[j];
ar[j] = temp;
}
} /* end of j loop
*/ } /* end of i loop */
/* display sorted array */
printf("\nSorted Numbers \n");
for ( i = 0 ; i < 10 ; i++)
{
printf("%d\n", ar[i]);
}
getch();
}
Output:
Enter number for [0] element: 35
Enter number for [1] element: 67
Enter number for [2] element: 98
Enter number for [3] element: 12
Enter number for [4] element: 6
Enter number for [5] element: 58
Enter number for [6] element: 49
Enter number for [7] element: 23
Enter number for [8] element: 71
Enter number for [9] element: 85
Sorted Numbers
6
12
23
35
49
58
67
71
85
98
34. : Program to convert lowercase to uppercase and uppercase
to lowercase.
#include<stdio.h>
#include<string.h>
main()
{
char name[100];
clrscr();
printf("Enter a string: ");
gets(name);
printf("\nUppercase String: ");
puts(strupr(name));
strlwr(name);
printf("\nLowercase String: ");
puts(name);
getch();
}
Output:
Enter a string: peter
Uppercase String: PETER
Lowercase String: peter
temp++;
}
string1[temp] = '\0';
printf("\nThe concatenated string is:\n");
puts(string1);
getch();
}
Output:
Enter the Value of String1:
C Language
Enter the Value of String2:
is good
The concatenated string is:
C Language is good
Address of a: 65494
Address of a: 65494
Address of p: 65496
Value of p: 65494
Value of a: 10
Value of a: 10
Value of a: 10
if(x.bs>15000)
hra = 1500;
else
hra = 1000;
printf("Details of employee\n");
printf("Employee Number: %d\n",x.eno);
printf("Employee Name: %s\n",x.ename);
printf("Employee Address: %s\n",x.eadd);
printf("Employee Basic Salary: %f\
n",x.bs); printf("Employee Salary: %f\
n",x.bs+hra);
}
38. : Program to illustrate concept of unions.
#include<stdio.h>
#include<conio.h>
main()
{
union number
{
int n1;
float n2;
char name[20];
};
union number x;
clrscr();
printf("\nEnter Name: ");
gets(x.name);
printf("Enter the value of n2: ");
scanf("%f", &x.n2);
printf("Enter the value of n1: ");
scanf("%d", &x.n1);
printf("\n\nValue of n1 = %d",x.n1);
printf("\nValue of n2 = %f",x.n2);
printf("\nName = %s",x.name);
getch();
}
Output:
Enter Name: Zaheer
Enter the value of n2: 3.23
Enter the value of n1: 6
Value of n1 = 6
Value of n2 = 3.218751
Name = ♠
long fact(int n)
{
int m;
if (n == 1)
return n;
else
return n * fact(n-1);
}