[go: up one dir, main page]

0% found this document useful (0 votes)
20 views13 pages

ICP BCSA104C Labmanual 261224

The document is a lab manual for the Introduction to C Programming course at Basaveshwar Engineering College, detailing course objectives, outcomes, and practical modules. It includes a structured curriculum with five modules covering topics such as C programming basics, functions, arrays, strings, and structures, along with practical exercises. Suggested textbooks and reference materials are also provided for further learning.

Uploaded by

anushak8404
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views13 pages

ICP BCSA104C Labmanual 261224

The document is a lab manual for the Introduction to C Programming course at Basaveshwar Engineering College, detailing course objectives, outcomes, and practical modules. It includes a structured curriculum with five modules covering topics such as C programming basics, functions, arrays, strings, and structures, along with practical exercises. Suggested textbooks and reference materials are also provided for further learning.

Uploaded by

anushak8404
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

BVVS

Basaveshwar Engineering College, Bagalkote


Department of Computer Science and Engineering

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

Faculty in-charge: Dr Veerendrakumar C M

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

Course Programme Outcomes


Outcomes 1 2 3 4 5 6 7 8 9 10 11 12
CO1 3
CO2 2 3 2 1 2 2 1
CO3 2 3 2 1 2 2 1
CO4 1 2 3 1 2 1 1
Page | 1
CO5 1 2 3 2 2 1 1
Contents:
Module-1 6 Hrs.

Introduction to C: Introduction to computers, input and output devices, designing


efficient programs. Introduction to C, Structure of C program, Files used in a C program,
Compilers, Compiling and executing C programs, variables, constants, Input/output
statements in C

Textbook:Chapter1.1-1.9,2.1-2.2,8.1–8.6,9.1-9.14

Module-2 6 Hrs.

Operators in C, Type conversion and typecasting.


Decision control and Looping statements: Introduction to decisioncontrol, Conditional
branchingstatements, iterative statements, nested loops, break and continue statements,
goto statement.
Textbook:Chapter9.15-9.16,10.1-10.6

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.

Two dimensional arrays, operations on two-dimensional arrays, two-dimensional arrays


to functions, multidimensional arrays.
Applications of arrays: Applications of arrays, case study with sorting techniques.
Introduction to strings: Reading strings, writing strings, summary of functions used to
read and write characters.
Textbook:Chapter12.7-12.12
Module-5 6 Hrs.

Strings: String-handling functions, operations on strings, Miscellaneous string and


character functions, arrays of strings.
Structures: Introduction to structures, Defining a structure, declaring structure variables,
Initialization, Accessing structure members. Arrays of structure,
Textbook:Chapter13.1-13.6,14.1-14.3,15.1

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.

Suggested Learning resources


Textbooks
1. Computer fundamentals and programming in C, “Reema Thareja”, Oxford
University, Second edition, 2017.
ReferenceBooks:
1. E. Balaguruswamy, Programming in ANSIC, 7th Edition,TataMcGraw-Hill.
2. Brian W.Kernighan and Dennis M.Ritchie,The ‘C’ Programming Language,
Prentice Hall of India.

Page | 3
Programs

1) Write a C program to find mechanical energy of a particle using e = mgh + (1/2) mv 2.


/*C pgm to find mechanical energy of a particle using e = mgh+1/2 mv2*/
#include<stdio.h>
main()
{
float m, h, v, e;
printf("C program to compute mechanical energy of a particle\n");
/*Accepting input*/
printf("Enter mass(kg), height(m) and velocity(m/s) of particle\n");
scanf("%f%f%f",&m,&h,&v);
/*Calculating mechanical energy*/
e=m*9.81*h+0.5*m*v*v;
/*printing the result*/
printf("Mechanical energy of a particle=%0.2f\n",e);
}

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);

/*check for palindrome*/


if(m==rev)
printf("Input number is Palindrome");
else
printf("Input number is not a Palindrome");
}
1)
C program to find reverse of a number and check for palindrome:
Enter an integer:
454
Reverse = 454
Input number is Palindrome
2)
C program to find reverse of a number and check for palindrome:
Enter an integer:
1234
Reverse = 4321
Input number is not a Palindrome

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);

/* Checking and printing prime nos in range */


printf("Prime numbers in range:\n");
for(i = m; i <= n; i++)
{
flag = 0;
for(j = 2; j <= i/2; j++)
{
if(i%j == 0)
{
flag = 1;
break;
}
}
if(flag == 0)
printf("%3d",i);
}
}

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);
}
}

/* Recursive Function definition*/


int find_fact(int m)
{
if(m==0)
return(1);
else
return(m*find_fact(m-1));
}

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

You might also like