Intro C Manual
Intro C Manual
Intro C Manual
Lab Manual
II Semester ECE
Prepared by
Prof.Shilpa M N
Name:
USN:
Section: Batch:
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
To empower students through wholesome education and enable the students to develop into
highly qualified and trained professionals with ethics and emerge as responsible citizen with
broad outlook to build a vibrant nation.
To enable our students to develop into outstanding professionals with high ethical standards
to face the challenges of the 21st century.
To provide educational opportunities to the deprived and weaker section of the society, to
uplift their socio-economic status.
To shape the students as disciplined humane engineers who can build a strong, peaceful and
vibrant country and focus on mutual respect, tolerance and professional ethics.
To provide the best possible educational experience through excellence in teaching and
research activities for today’s students and professionals of tomorrow.
To hone young minds and train them to be conscientious individuals who will serve the
society as competent professionals in the field of Electronics and Communication
Engineering
Page 2 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
PEO-5: They will have a desire for continuous learning and R&D.
Program Outcomes
Page 3 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
PO-5: Modern Tool Usage: Create, select, and apply appropriate techniques,
resources, and modern engineering and IT tools including prediction and
modelling to complex engineering activities with an understanding of the
limitations.
PO-6: The Engineer and Society: Apply reasoning informed by the contextual
knowledge to assess societal, health, safety, legal, and cultural issues and the
consequent responsibilit ies relevant to the professional engineering practice.
PO-8: Ethics: Apply ethical principles and commit to professional ethics and
responsibilit ies and norms of the engineering practice.
Page 4 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
Introduction to C Programming
Course Code: BESCK104E/204E CIE Marks 50
Course Type (Theory/Practical /Integrated) Integrated SEE Marks 50 Total Marks 100
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
Course Objectives:
CLO 3. Explore user-defined data structures like arrays, structures and pointers in
implementing solutions to problems.
CLO 4. Design and Develop Solutions to problems using modular programming constructs
such as functions and procedures.
LAB Programs
Page 5 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
9. write a C Program to Implement structures to read, write and compute average marks and
the students scoring above and below the average marks for a class of N students.
10. Develop a C program using pointers to compute the sum, mean and standard deviation of all
elements stored in an array of N real numbers.
Course Outcomes (Course Skill Set)
At the end of the course the student will be able to:
CO1. Elucidate the basic architecture and functionalities of a computer and recognize the
hardware parts.
CO 2. Apply programming constructs of C language to solve the real-world problem.
CO 3. Explore user-defined data structures like arrays in implementing solutions to
problems like searching and sorting.
CO 4. Explore user-defined data structures like structures, unions, and pointers in
implementing solutions.
CO 5. Design and Develop Solutions to problems using modular programming constructs
using functions.
Page 6 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
Program 1
Write a C Program to find Mechanical Energy of a particle using E = mgh+1/2 mv2.
Program:
#include <stdio.h>
int main(void)
{
float m,h,v,p,k,e;
printf("Enter Mass of the body\n");
scanf("%f",&m );
printf("Enter displacement of the body\n");
scanf("%f",&h );
printf("Enter velocity of the body\n");
scanf("%f",&v );
p=m*9.8*h; //To calculate Potential energy
k=0.5*m*(v*v); //To calculate Kinetic energy
e=p+k;
printf("Potential energy of the body = %f\n",p );
printf("Kinetic energy of the body = %f\n",k );
printf("Mechanical energy of a body = %f\n" , e);
}
OUTPUT:
Page 7 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
Program 2
Program:
#include <stdio.h>
int main(void)
{
int a,b,c;
printf("Enter distance between two cities in km\n");
scanf("%d",&a);
b=a*1000; //To convert in meters
c=a*100000;//To convert in centimeters
printf("Total km in meters=%d\n",b );
printf("Total km in centimeters=%d",c );
return 0;
}
OUTPUT:
Page 8 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
Program 3
Write C Program to Check the Given Character is Lowercase or Uppercase or Special
Character.
PROGRAM
#include <stdio.h>
int main(void)
{
char ch;
printf("Enter any character: \n");
scanf("%c", &ch);
if(ch >= 'A' && ch <= 'Z')
{
printf(" '%c' is uppercase alphabet.", ch);
}
else
if(ch >= 'a' && ch <= 'z')
{
printf(" '%c' is lowercase alphabet.", ch);
}
else
if(ch >= '0' && ch <= '9')
{
printf(" '%c' is digit.", ch);
}
else
printf(" '%c' is special character.", ch);
return 0;
}
OUTPUT:
Page 9 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
Program 4
Page 10 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
b3=b3/temp;
}
printf(“the coefficients are b1=%d,b2=%d, b3=%d”, b1,b2,b3);
}
int gcd(int a, int b)
{
int hcf;
for(int i=1;i<=a && i<=b;i++)
{
if(a%i==0 && b%i==0)
{
hcf=i;
}
}
return hcf;
}
OUTPUT:
Page 11 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
Program 5
Write a C program to Implement Matrix multiplication and validate the rules of
multiplication.
PROGRAM
#include<stdio.h>
int main(void)
{
int c, d, p, q, m, n, k, tot = 0;
int fst[10][10], sec[10][10], mul[10][10];
printf(" Please insert the number of rows and columns for first matrix \n ");
scanf("%d%d", &m, &n);
printf(" Insert your matrix elements : \n ");
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
scanf("%d", &fst[c][d]);
printf(" Please insert the number of rows and columns for second matrix\n");
scanf(" %d %d", &p, &q);
if (n != p)
printf(" Your given matrices cannot be multiplied with each other. \n ");
else
{
printf(" Insert your elements for second matrix \n ");
for (c = 0; c < p; c++)
for (d = 0; d < q; d++)
scanf("%d", &sec[c][d] );
for (c = 0; c < m; c++) {
for (d = 0; d < q; d++) {
for (k = 0; k < p; k++) {
tot = tot + fst[c][k] * sec[k][d];
}
Page 12 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
mul[c][d] = tot;
tot = 0;
}
}
printf(" The result of matrix multiplication or product of the matrices is: \n ");
for (c = 0; c < m; c++) {
for (d = 0; d < q; d++)
printf("%d \t", mul[c][d] );
printf(" \n ");
}
}
return 0;
}
OUTPUT:
Page 13 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
Program 6
Write a C Program to compute Sin(x)/ Cos(x) using Taylor series approximation.
Compare your result with the built- in Library function. Print both the results with
appropriate messages.
Program:
#include<stdio.h>
#include<math.h>
void main()
{
float x,sum,nume,deno,term;
int degree, i;
printf("Enter degree:\n");
scanf("%d",°ree);
x=degree*(3.142/180);
sum=0;
nume=x;
deno=1;
i=1;
do
{
term=nume/deno;
sum=sum+term;
i=i+2;
deno=deno*(i-1)*i;
nume=-nume*x*x;
}while(fabs(term)>0.00001);
printf("Sin %d using Taylor's Series:%f\n",degree,sum);
printf("Sin %d using built-in Library function:%f\n",degree,sin(x));
getch();
}
OUTPUT:
Page 14 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
Program 7
Write a C Program to Sort the given set of N numbers using Bubble Sort.
Program:
void main()
intn,i,j,a[10],t;
printf("Enter n\n");
scanf("%d",&n);
printf("Enter elements\n");
for (i=0;i<=n;i++)
scanf("%d",&a[i]);
for (i=0;i<n-1;i++)
for (j=0;j<n-1;j++)
if (a[j]>a[j+1])
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
printf("Sorted Array\n");
for (i=0;i<n;i++)
printf("%d\n",a[i]);
getch();
}
OUTPUT:
Page 15 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
Program 8
Write functions to implement string operations such as compare, concatenate, string length.
Convince the parameter passing techniques.
Program:
#include <stdio.h>
#include<conio.h>
intlen_str(char s[50]);
void main()
char s1[50],s2[50],len,c;
clrscr();
scanf("%s",s1);
scanf("%s",s2);
len=len_str(s1);
len=len_str(s2);
c=comp_str(s1,s2);
if(c==0)
else
Page 16 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
concat_str(s1,s2);
getch();
intlen_str(char s[50])
int len = 0, i;
len++;
return len;
len1 = len_str(s1);
len2 = len_str(s2);
if (len1 != len2)
return 1;
if (s1[i] !=s2[i])
return 1;
return 0;
Page 17 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
int i=0,j;
j=len_str(s1);
while(s2[i]!='\0')
s1[j]=s2[i];
j++;
i++;
s1[j]='\0';
OUTPUT:
Page 18 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
Program 9
Write a C Program to Implement structures to read, write and compute average marks and
students scoring above and below the average marks for a class of N students.
PROGRAM
#include <stdio.h>
#include<stdio.h>
void main()
struct stud
char name[25];
char usn[25];
int marks;
};
int n,i,sum;
float average;
sum=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%s%s%d",s[i].name,s[i].usn,&s[i].marks);
sum=sum+s[i].marks;
Page 19 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
average=sum/(float)n;
printf("average marks=%f",average);
for(i=0;i<n;i++)
for(i=0;i<n;i++)
OUTPUT:
Page 20 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
Program 10
Develop a program using pointers to compute the sum, mean and standard deviation of all
elements stored in an array of n real numbers.
PROGRAM
#include<stdio.h>
#include<math.h>
void main()
float a[10],*ptr,mean,std,sum=0,sumstd=0;
intn,i;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%f",&a[i]);
ptr=a;
for(i=0;i<n;i++)
sum=sum+*ptr;
ptr++;
mean=sum/n;
ptr=a;
for(i=0;i<n;i++)
Page 21 of 22
HKBK College of Engineering BESCK104E/204E Introduction to C Programming
sumstd=sumstd+pow((*ptr-mean),2);
ptr++;
std=sqrt(sumstd/n);
printf("sum=%f\n",sum);
printf("Mean=%f\n",mean);
printf("standard deviation=%f\n",std);
getch();
OUTPUT:
Page 22 of 22