ICP BCSA104C Labmanual 261224
ICP BCSA104C Labmanual 261224
Lab Manual
Course code: BCSA104C Credits: 03
Hours/Week (L:T:P) : CIE Marks : 50
2:0:2 Course Title:
Total Hours of Introduction to C Programming SEE 50
Pedagogy Course Type: Integrated Marks :
(Theory+Lab): 40
Course Objectives:
CLO1 Elucidate the basic architecture and functionalities of a Computer
CLO2 Apply programming constructs of C language to solve the real-world
problems
CLO3 Explore user-defined data structures like arrays, and structures in
implementing solutions to problems
CLO4 Design and Develop Solutions to problems using modular programming
constructs such as functions and procedures
Course Outcomes:
Elucidate the basic architecture and functionalities of a computer and also
CO1
recognize the hardware parts
CO2 Apply programming constructs of C language to solve the real world
problem
CO3 Explore user-defined data structures like arrays in implementing solutions
to problems like searching and sorting
CO4 Explore user-defined data structures like structures in implementing
solutions
CO5 Design and Develop Solutions to problems using modular programming
constructs using functions
CO and PO Mapping
Textbook:Chapter1.1-1.9,2.1-2.2,8.1–8.6,9.1-9.14
Module-2 6 Hrs.
Module-3 6 Hrs.
Functions
Introduction using functions, Function definition, function declaration, function call,
return statement, passing parameters to functions, scope of variables, storage classes,
recursive functions.
Arrays: Declaration of arrays, accessing the elements of an array, storing value sin arrays,
Operations on arrays, Passing arrays to functions,
Textbook:Chapter11.1-11.13,12.1-12.6
Module-4 6 Hrs.
Page | 2
Practical Module
1. C program to find mechanical energy of a particle using e = mgh+1/2 mv2.
2. C program to convert kilometers into meters and centimeters.
3. C program to check the given character is lowercase or uppercase or special
character.
4. To find reverse of a number and check for palindrome
5. To print prime numbers between two numbers
6. To compute factorial of an input number using recursive function
7. Sort the given set of n numbers using bubble sort.
8. Implement matrix multiplication and validate the rules of multiplication.
9. Write functions to implement string operations such as compare, concatenate, string
length. Convince the parameter passing techniques.
10. Use structures to read, write and compute average- marks of N students. Also, list
the students scoring above and below the average marks.
Page | 3
Programs
Page | 4
2) Write a C program to convert kilometers into meters and centimeters.
/*C pgm to convert kilometers into meters and centimeters*/
#include<stdio.h>
main()
{
float km, m, c;
printf("C pgm to convert km into meter and centimeters:\n");
/*Accepting input*/
printf("Enter distance in kilometers:\n");
scanf("%f",&km);
/*Converting to metre and centimetre*/
m=km*1000;
c = km*100000;
/*printing the result*/
printf("In metre = %0.2f m\n",m);
printf("In centimetre = %0.2f cm",c);
}
Page | 5
3) C program to check the given character is lowercase or uppercase or special character
/*C program to check the given character is lowercase or uppercase or special character*/
#include <stdio.h>
int main()
{
char ch;
printf(“C prog to check input char is lower or upper case or spl char:”)
/*Accepting input*/
printf("Ente a character:\n");
scanf("%c",&ch);
/*checking ASCII value of char*/
if(ch>=65 && ch<=90)
printf("Input char is an Upper-case Alphabet \n");
else if(ch>=97 && ch<=122)
printf("Input char is a lower-case Alphabet \n");
else
printf("Input char is a special character");
}
Output:
1) 2) 3)
Ente a character: Ente a character: Ente a character:
D a ?
Input char is an Upper-case Input char is a lower-case Input char is a special
Alphabet Alphabet character
Page | 6
4) To find reverse of a number and check for palindrome
/*C program to find reverse of a number and check for palindrome*/
#include <stdio.h>
int main()
{
int n, rev, rem, m;
printf("C program to find reverse of a number and check for palindrome:\n");
/*Accepting input*/
printf("Enter an integer:\n");
scanf("%d",&n);
m=n;
/*Finding reverse*/
rev=0;
while(n!=0)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;
}
printf("Reverse = %d\n",rev);
Page | 7
5) To print prime numbers between two numbers
/*Printing prime numbers in a range*/
#include <stdio.h>
int main()
{ int i, j, flag, m, n;
printf("C program to print prime nos in a range\n");
/* Accepting input */
printf("Enter range(num1 and num2):\n");
scanf("%d%d",&m,&n);
Page | 8
6) To compute factorial of an input number using recursive function.
/* To compute factorial of an input number using recursive function */
#include <stdio.h>
int main()
{
int n, fact;
/* Function declaration*/
int find_fact(int m);
printf("factorial of N using recursive function: \n");
/* Accepting input */
printf("Enter an integer :\n");
scanf("%d",&n);
if(n<0)
printf("Negative no: factorial not defined!");
else
{
/* Function call*/
fact=find_fact(n);
printf("Factorial = %d",fact);
}
}
Page | 9
7) Sort the given set of n numbers using bubble sort.
/*To sort n values using bubble sort in ascending order*/
#include<stdio.h>
int main() {
int n, a[20], i, j, temp;
/* Accepting input */
printf("Hown many numbers?\n");
scanf("%d",&n);
printf("Enter %d numbers: \n",n);
for(i = 0; i < n; i++)
{
scanf("%d",&a[i]);
}
printf("Numbers before sorting: \n");
for(i = 0; i < n; i++)
{
printf("%d ",a[i]);
}
/*Bubble sort begins*/
for(i = 0; i < n; i++)
{
for(j = 0; j<n-1-i; j++)
if(a[ j ] > a[ j + 1 ])
{
temp = a[ j ];
a[ j ] = a[ j + 1 ];
a[ j + 1 ] = temp;
}
}
printf("\n After sorting: \n");
for(i = 0; i < n; i++)
{
printf("%d ",a[i]);
} }
Page | 10
9. Write functions to implement string operations such as compare, concatenate, string
length. Convince the parameter passing techniques.
/* UDFs to compare, concatenate, find length of /* UDFs */
string */ int s_length(char s1[])
#include<stdio.h> {
int main() int i,len;
{ for(i=1; s1[i]!='\0';i++)
int s_length(char s1[]); {
int s_compare(char s1[],char s2[]); ;
void s_concat(char s1[],char s2[], int len1, int len2); }
char s1[20], s2[20]; return(i);
int len1, len2, flag; }
printf("UDFs to compare, concat, find len: \n");
printf("Enter string-1:"); int s_compare(char s1[], char s2[])
scanf("%s",s1); {
printf("Enter string-2: "); int i;
scanf("%s",s2); for(i=1; s1[i]!='\0';i++)
{
/*function call of s_length*/ if(s1[i]!=s2[i])
len1=s_length(s1); {
len2=s_length(s2); return(1);
printf("Length of string-1: %d \n",len1); }
printf("Length of string-2: %d \n",len2); }
return(0);
/*function call of s_compare*/ }
flag=s_compare(s1,s2); void s_concat(char s1[],char s2[],
if(flag==0) int len1, int len2)
printf("input strings are same \n"); {
else int i=len1, j=0;
printf("Input strings are not same \n"); for(j=0; j<len2; j++)
{
/*function call of s_concat*/ s1[i]=s2[j];
s_concat(s1,s2, len1, len2); i++;
printf("After concatenation: %s",s1); }
} s1[i]='\0';
}
Page | 11
L10. Use structures to read, write and compute average- marks of N students. Also, list the
students scoring above and below the average marks.
/* structures to read, write and compute printf("Input marks of %d students: \n",n);
average- marks of N students, list the for(i=0; i<n; i++)
students above and below the average marks {
*/ printf("%s: ",s[i].name);
#include<stdio.h> printf("%0.1f\n",s[i].marks);
int main() }
{
avg_marks=sum/n;
struct student
printf("Average marks of students= %0.1f \n",avg_marks);
{
char name[40]; printf("List of students with above average marks: \n");
float marks; for(i=0; i<n; i++)
}; {
struct student s[100]; if(s[i].marks>avg_marks)
int n, i; {
float sum=0,avg_marks; printf("%s: ",s[i].name);
printf("%0.1f\n",s[i].marks);
printf("structures to list students scoring }
above and below average marks: \n"); }
printf("How many students?:"); printf("List of students with below average marks: \n");
scanf("%d",&n); for(i=0; i<n; i++)
{
printf("Enter name and marks of %d students: if(s[i].marks<avg_marks)
\n",n); {
for(i=0; i<n; i++) printf("%s: ",s[i].name);
{ printf("%0.1f\n",s[i].marks);
scanf("%s",s[i].name); }
scanf("%f",&s[i].marks); }
sum=sum+s[i].marks; }
}
Page | 12
Page | 13