Introduction To C Programming Lab Manual For VTU (BESCK104E - 204E) - MyBlogosphere
Introduction To C Programming Lab Manual For VTU (BESCK104E - 204E) - MyBlogosphere
QuickPDFManuals
MYBLOGOSPHERE
Sharing my Inner Ramblings
In this blog post, you will find solutions for the Introduction to C
Programming Lab Manual (BESCK104E/204E) course work for the I year
students of VTU university. The academic syllabus has been changed for
the year 2022-23 in VTU. A new subject has been introduced titled
“Introduction to C Programming” (Sub Code: BESCK104E/204E) for first
year students of VTU. This subject has an integrated lab component.
Anybody can contribute and re-share this manual as it is distributed under
Creative Commons Attribution-NonCommercial-ShareAlike 4.0
International License. Also note the same subject is part of the
autonomous curriculum at Siddaganga Institute of technology with code
ESCO5.
All the programs have been compiled using the GNU GCC compiler
version 9.4.0 and has been tested on Ubuntu 22.04.4 LTS (Jammy
Jellyfish) 64-bit Kernel Linux 5.15.0-56-generic.
These programs can run on any GNU/Linux Operating system or any other
OS with GCC installed.
If you find the command line difficult to handle and looking for an GUI
based IDE to work with, the best choice is Code::Blocks. Code::Blocks uses
the GNU GCC compiler collection. Two other good IDEs that you can try or
Eclipse and Anjuta. I have provided links to this IDEs below you can click
and download the necessary software and instructions to set up a working
environment.
1. Code::Blocks
2. Anjuta DevStudio
9. Question 09 – C Structures
Question 1
Get 15% Off on CamPure Product
C Code
/************************************************************
*File : A01MechEnergy.c
*Description : C Program to find Mechanical Energy of a part
*Author : Prabodh C P
*Compiler : gcc compiler, Ubuntu 22.04
*Date : 02 December 2022
*************************************************************
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
/************************************************************
*Function : main
*Input parameters : no parameters
*RETURNS : 0 on success
*************************************************************
int main()
{
double dMass, dHeight, dVelocity;
double dPotEng, dKinEng, dEng;
printf("\n*************************************************
printf("\n*\tProgram to find Mechanical Energy of a body\t
printf("***************************************************
return 0;
}
Output
*************************************************************
* Program to find Mechanical Energy of a body *
*************************************************************
Enter the mass (in kg) of the body: 80
*************************************************************
Question 2
Distance Conversion
C Code
/************************************************************
*File : A02DistConvert.c
*Description : Program to convert Kilometers into Meters and
*Author : Prabodh C P
*Compiler : gcc compiler, Ubuntu 22.04
*Date : 02 December 2022
*************************************************************
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
/************************************************************
*Function : main
*Input parameters : no parameters
*RETURNS : 0 on success
*************************************************************
int main(void)
{
double dDistKm, dDistMtr, dDistCm;
printf("\n*************************************************
printf("\n*\tProgram to convert Kilometers into Meters and
printf("***************************************************
Output
*************************************************************
* Program to convert Kilometers into Meters and Centimeters
*************************************************************
Enter the distance in kilometers : 63
*************************************************************
Question 3
C Code
/************************************************************
*File : A03CheckCharacter.c
*Description : Program to check the given character is Lower
*Author : Prabodh C P
*Compiler : gcc compiler, Ubuntu 22.04
*Date : 10 August 2022
*************************************************************
#include<stdio.h>
#include<stdlib.h>
/************************************************************
*Function : main
*Input parameters : no parameters
*RETURNS : 0 on success
*************************************************************
int main(void)
{
char cChar;
printf("\nEnter a character to be checked : "); scanf("%c
return 0;
}
Output
***************************************
Enter a character to be checked : 1
Question 4
C Code
/************************************************************
*File : A04BalanceChemEqn.c
*Description : Program to balance the given Chemical Equatio
of the form b1*Ax + b2*By ==> b3(ApBq)
*Author : Prabodh C P
*Compiler : gcc compiler, Ubuntu 22.04
*Date : 26 December 2022
*************************************************************
#include<stdio.h>
#include<stdlib.h>
/************************************************************
*Function : main
*Input parameters : no parameters
*RETURNS : 0 on success
*************************************************************
int main(void)
{
int x, y, p, q;
int b1, b2, b3;
int iCommDivisor;
b1 = p * y;
b2 = q * x;
b3 = x * y;
b1 = b1 / iCommDivisor;
b2 = b2 / iCommDivisor;
b3 = b3 / iCommDivisor;
return 0;
}
/************************************************************
*Function : fnGCD
*Description : function to calculate GCD of two numbers
*Input parameters : iVal1 - non-negative integer
iVal2 - non-negative integer
*RETURNS : greatest common divisor of iVal1 and iVal2
*************************************************************
int fnGCD(int iVal1, int iVal2)
{
if (0 == iVal2)
return iVal1;
return fnGCD(iVal2, iVal1 % iVal2);
}
Output
***************************************
x = 2 y = 2 p = 2 q = 1
b1 = 2 b2 = 1 b3 = 2
x = 2 y = 3 p = 4 q = 5
b1 = 6 b2 = 5 b3 = 3
***************************************
Question 5
Matrix Multiplication
C Code
/************************************************************
*File : A05MatrixMul.c
*Description : Program to implement Matrix Multiplication
*Author : Prabodh C P
*Compiler : gcc compiler, Ubuntu 22.04
*Date : 10 August 2022
*************************************************************
#include<stdio.h>
#include<stdlib.h>
/************************************************************
*Function : main
*Input parameters : no parameters
*RETURNS : 0 on success
*************************************************************
int main(void)
{
int iM, iN, iP, iQ, i, j, k, iaMat1[10][10], iaMat2[10][10]
int iaProd[10][10] = {0};
printf("\n*************************************************
printf("\n*\tPROGRAM TO IMPLEMENT MATRIX MULIPLICATION\t*\n
printf("***************************************************
printf("\nEnter the order of Matrix1\n");
scanf("%d%d",&iM,&iN);
if( iN != iP)
{
printf("\nMatrix Multiplication not possible\n");
exit(0);
}
for(i=0;i<iM;i++)
{
for(j=0;j<iQ;j++)
{
for(k=0;k<iN;k++)
{
iaProd[i][j] += iaMat1[i][k] * iaMat2[k][j];
}
}
}
/************************************************************
|*| |*|
a00 a01 a02|*|b00 b01 b02|*|
|*| |*|
a10 a11 a12|*|b10 b11 b12|*|
|*| |*|
a20 a21 a22|*|b20 b21 b22|*|
|*| |*|
printf("\nMatrix 1\n");
for(i=0;i<iM;i++)
{
for(j=0;j<iN;j++)
{
printf("%d\t",iaMat1[i][j]);
}
printf("\n");
}
printf("\n");
printf("\nMatrix 2\n");
for(i=0;i<iP;i++)
{
for(j=0;j<iQ;j++)
{
printf("%d\t",iaMat2[i][j]);
}
printf("\n");
}
printf("\n");
for(i=0;i<iM;i++)
{
for(j=0;j<iQ;j++)
{
printf("%d\t",iaProd[i][j]);
}
printf("\n");
}
printf("\n");
return 0;
}
Output
*********************************************************
* PROGRAM TO IMPLEMENT MATRIX MULIPLICATION *
*********************************************************
Enter the order of Matrix1
2 3
*********************************************************
* PROGRAM TO IMPLEMENT MATRIX MULIPLICATION *
*********************************************************
Enter the order of Matrix1
2 3
Matrix 1
1 2 3
4 5 6
Matrix 2
1 2
3 4
5 6
*********************************************************
* PROGRAM TO IMPLEMENT MATRIX MULIPLICATION *
*********************************************************
Enter the order of Matrix1
2 2
Matrix 1
1 2
3 4
Matrix 2
1 0
0 1
Question 6
C Code
/************************************************************
*File : A06SineCosAngle.c
*Description : Program to calculate Sin(x)/Cos(x) using Tayl
*Author : Prabodh C P
*Compiler : gcc compiler, Ubuntu 22.04
*Date : 10 August 2022
*************************************************************
#include<stdio.h>
#include<stdlib.h>
#include <math.h>
/************************************************************
*Function : main
*Input parameters : no parameters
*RETURNS : 0 on success
*************************************************************
int main()
{
float fAngD, fAngR;
float fTerm, fNum, fDen, fSVal,fCVal;
int i,iNum;
printf("\nEnter the Angle : "); scanf("%f",&fAngD);
printf("\nEnter the Number of terms : "); scanf("%d",&iNu
printf("\nInput Angle = %g\n",fAngD);
printf("No of terms = %d\n",iNum);
fAngR= (fAngD*M_PI)/180 ;
return 0;
}
Output
***************************************
Question 7
Bubble Sort
Write a C program to sort the given set of N numbers using Bubble sort.
C Code
/************************************************************
*File : A07BubbleSort.c
*Description : Program to implement Bubble Sort Algorithm
*Author : Prabodh C P
*Compiler : gcc compiler, Ubuntu 22.04
*Date : 10 August 2022
*************************************************************
#include<stdio.h>
#include<stdlib.h>
/************************************************************
*Function : main
*Input parameters : no parameters
*RETURNS : 0 on success
*************************************************************
int main(void)
{
int iNum, i, j, iaArr[10], iTemp;
printf("\n*************************************************
printf("\n*\tPROGRAM TO IMPLEMENT BUBBLE SORT\t*\n");
printf("*************************************************")
printf("\nEnter no of elements\n");
scanf("%d",&iNum);
for(i=0;i<iNum;i++)
{
for(j=0;j<iNum-i-1;j++)
{
if(iaArr[j] > iaArr[j+1])
{
iTemp = iaArr[j];
iaArr[j] = iaArr[j+1];
iaArr[j+1] = iTemp;
}
printf("\n");
return 0;
}
Output
*************************************************
* PROGRAM TO IMPLEMENT BUBBLE SORT *
*************************************************
Enter no of elements
5
*************************************************
* PROGRAM TO IMPLEMENT BUBBLE SORT *
*************************************************
Enter no of elements
6
Question 8
String Operations
Write
functions to implement string operations such as compare,
C Code
/************************************************************
*File : A08StringFunctions.c
*Description : Program to implement string operations as fun
*Author : Prabodh C P
*Compiler : gcc compiler, Ubuntu 22.04
*Date : 10 August 2022
*************************************************************
#include<stdio.h>
#include<stdlib.h>
int fnMyStrCmp(const char*, const char*);
void fnMyStrCat(char*, const char*);
int fnMyStrLen(const char*);
/************************************************************
*Function : main
*Input parameters : no parameters
*RETURNS : 0 on success
*************************************************************
int main()
{
int iChoice;
char acStr1[30], acStr2[30];
int iLen;
printf("\n=====================\n");
printf("STRING OPERATIONS");
printf("\n=====================\n");
for(;;)
{
printf("\nEnter two strings\n");
printf("\nString 1 : "); scanf("%s", acStr1);
printf("\nString 2 : "); scanf("%s", acStr2);
printf("\n1.String Compare\n2.String Concatenate\n3.Strin
printf("\nEnter your choice : "); scanf("%d", &iChoice);
switch(iChoice)
{
case 1: if(fnMyStrCmp(acStr1, acStr2) == 0)
printf("\nTwo strings are equal");
else if(fnMyStrCmp(acStr1, acStr2) > 0)
printf("\nString %s is greater than String %s", a
else
printf("\nString %s is greater than String %s", a
break;
}
printf("\nPress 1 to continue and 0 to quit : ");
scanf("%d", &iChoice);
if(0==iChoice)
{
break;
}
}
return 0;
}
/************************************************************
*Function : fnMyStrCmp
*Description : Function that compares the two strings s1 a
*Input parameters :
* const char *s1, const char *s2 - two strings to be compar
*RETURNS :
* 1 if s1 is greater than s2.
* 0 if s1 matches s2.
* -1 if s1 is less than s2.
*************************************************************
/************************************************************
*Function : fnMyStrCat
*Description : function that appends the src string to the
*Input parameters :
* char *dest - first string
* const char *src - second string
*RETURNS : nothing
*************************************************************
/************************************************************
*Function : fnMyStrLen
*Description : function that calculates the length of a st
*Input parameters :
* const char *str - string whose length needs to be found
*RETURNS :
* integer which is the length of the string
*************************************************************
Output
***************************************
=====================
STRING OPERATIONS
=====================
String 1 : shiva
String 2 : shankar
1.String Compare
2.String Concatenate
3.String Length
Enter your choice : 2
Concatenated String is
shivashankar
Press 1 to continue and 0 to quit : 1
String 1 : ramesh
String 2 : sumesh
1.String Compare
2.String Concatenate
3.String Length
Enter your choice : 1
String sumesh is greater than String ramesh
Press 1 to continue and 0 to quit : 1
String 1 : sam
String 2 : samantha
1.String Compare
2.String Concatenate
3.String Length
Enter your choice : 3
Question 9
C Structures
C Code
/************************************************************
*File : A09StudentStructure.c
*Description : Program to implement structure and compute av
*Author : Prabodh C P
*Compiler : gcc compiler, Ubuntu 22.04
*Date : 10 August 2022
*************************************************************
#include<stdio.h>
#include<stdlib.h>
#define STRSIZE 30
typedef struct
{
char cName[STRSIZE];
char cUSN[11];
int iMarks;
}STUDENT_TYPE;
/************************************************************
*Function : main
*Input parameters : no parameters
*RETURNS : 0 on success
*************************************************************
int main(void)
{
STUDENT_TYPE students[100];
int iNum, i;
double dAvg = 0.0;
dAvg /= iNum;
for(i=0;i<iNum;i++)
{
printf("\n###############################");
printf("\nName\t: %s", students[i].cName);
printf("\nUSN\t: %s", students[i].cUSN);
printf("\nMarks\t: %d", students[i].iMarks);
if(students[i].iMarks < dAvg)
printf("\nThe student has scored below average\n");
else
printf("\nThe student has scored above average\n");
}
return 0;
}
Output
***************************************
Enter the number of students : 4
Enter the Student details
=========================================
Name : Raju
USN : 1SI17CS036
Marks : 67
=========================================
Name : Michael
USN : 1SI17CS045
Marks : 87
=========================================
Name : Sahana
USN : 1SI17CS405
Marks : 77
=========================================
Name : Jonathan
USN : 1SI17CS025
Marks : 83
=========================================
Name : Raju
USN : 1SI17CS036
Marks : 67
The student has scored below average
=========================================
Name : Michael
USN : 1SI17CS045
Marks : 87
The student has scored above average
=========================================
Name : Sahana
USN : 1SI17CS405
Marks : 77
The student has scored below average
=========================================
Name : Jonathan
USN : 1SI17CS025
Marks : 83
The student has scored above average
***************************************
Question 10
C Code
/************************************************************
*File : A10MeanVarianceSD.c
*Description : Program to compute Mean, Variance and Standar
using pointer to an array
*Author : Prabodh C P
*Compiler : gcc compiler, Ubuntu 22.04
*Date : 10 August 2022
*************************************************************
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
/************************************************************
*Function : main
*Input parameters : no parameters
*RETURNS : 0 on success
*************************************************************
int main(void)
{
int i,iNum;
float fMean = 0.0f, fVariance = 0.0f, fSd = 0.0f,faArray[
float *fptr;
printf("\n**************************************\n");
printf("\tSum\t = \t%g\n\tMean\t = \t%g\n\tVariance = \t%
printf("\n**************************************\n");
return 0;
}
Output
***************************************
Enter the number of Values : 4
Enter 4 values
1.1 2.2 3.3 4.4
**************************************
Sum = 11
Mean = 2.75
Variance = 1.5125
Standard Deviation = 1.22984
**************************************
============================================================
Enter the number of Values : 5
Enter 5 values
5.345 6.765 7.234 8.675 9.765
**************************************
Sum = 37.784
Mean = 7.5568
Variance = 2.34995
Standard Deviation = 1.53295
**************************************
If you are also looking for other subject Lab Manuals, head over to my
following blog :
Prabodh C P
Prabodh C P is a faculty in the Dept of CSE SIT, Tumkur and also currently
a Research Scholar pursuing PhD in IIT Hyderabad. He conducts online
classes for C, C++, Python. For more info call +919392302100
PREVIOUS POST
NEXT POST
RELATED POSTS
MongoDB Laboratory (BDS456B) In this blog post, you will find ...
In this blog post, you will find solutions for the ...
In this blog post, you will find solutions for the ...
LEAVE A REPLY
Your email address will not be published. Required fields are marked *
Comment*
Name*
Email*
Website
Post Comment