r23-Cp Lab Manual
r23-Cp Lab Manual
Regulations: R23
Year & Sem: I-I
COMPUTER PROGRAMMING
LAB
VISION
To evolve as a Premier Engineering Institution in the Country with its continues strive for
excellence in Education, Research and Technological Services.
MISSION
To generate the community of highly learned students with greater acquirement of knowledge
and to apply it professionally with due consideration for ecological, economic and ethical
issues.
To provide knowledge-based technological services at the best satisfaction of society and for
the industrial needs.
To foster the research and disseminate research findings.
To build in capabilities for advancing education, technology, values, management and research
at international standards.
VISION
To explore innovative approaches to enhance and expand learning opportunities through
the integration of various technologies.
To build a strong research and teaching environment that responds to the real-time
challenges of the industry
MISSION
To inculcate the blend of competence, aptitude of knowledge and investigate flair
through devising an ambient environment for sustainable learning.
To transform attitude, values, priorities by changing mindset and instill positive outlook
for socially conscious intellectual development.
Incubate, apply and spread innovative ideas to evolve the department as a centre of
excellence in thrust areas
PEO 4 Foster sustained professional development through life-long learning to adapt new
computing technologies
PSO1 Ability to apply their skills in the field of algorithms, networking, web design, cloud
computing and databases.
PSO2 Ability to develop and deploy software solutions for real world problems.
PSO3 Gain knowledge in diverse areas of Computer Science and experience an environment
conducivein cultivating skills for successful career, entrepreneurship, research and higher
studies.
.
Syllabus
UNIT I
WEEK 1
Objective: Getting familiar with the programming environment on the
computer and writing the first program.
Suggested Experiments/Activities:
Tutorial 1: Problem-solving using Computers.
Lab1: Familiarization with programming environment
i) Basic Linux environment and its editors like Vi, Vim & Emacs etc.
ii) Exposure to Turbo C, gcc
iii) Writing simple programs using printf(), scanf()
WEEK 2
Objective: Getting familiar with how to formally describe a solution to a
problem in a series of finite steps both using textual notation and graphic
notation.
Suggested Experiments /Activities:
Tutorial 2: Problem-solving using Algorithms and Flow charts.
Lab 1: Converting algorithms/flow charts into C Source code.
Developing the algorithms/flowcharts for the following sample programs
i) Sum and average of 3 numbers
ii) Conversion of Fahrenheit to Celsius and vice versa
iii) Simple interest calculation
WEEK 3
Objective: Learn how to define variables with the desired data-type, initialize
them with appropriate values and how arithmetic operators can be used with
variables and constants.
Suggested Experiments/Activities:
Tutorial 3: Variable types and type conversions:
Lab 3: Simple computational problems using arithmetic expressions.
i) Finding the square root of a given number
ii) Finding compound interest
functions
v) Reverse a string using built-in and without
built-in string functions
number.
iv) C Program to implement Ackermann function
using recursion.
v) recursive function to find the sum of series.
using pointer.
iv) C program to find no of lowercase,
uppercase, digits and other
characters using pointers.
i) C program to nd read text into a file.
ii) C program to nd read text into a binary file
using fread() and fwrite()
iii) Copy the contents of one file to another file.
iv) C program to merge two files into the third
14 file using command-line Projector 3
arguments.
v) Find no. of lines, words and characters in a
file
vi) C program to print last n characters of a
given file.
Total No. of hours: 42
Textbooks:
1. Ajay Mittal, Programming in C: A practical approach, Pearson.
2. Byron Gottfried, Schaum' s Outline of Programming with C, McGraw Hill
Reference Books:
1. Brian W. Kernighan and Dennis M. Ritchie, The C Programming Language, PrenticeHall of
India
2. C Programming, A Problem-Solving Approach, Forouzan, Gilberg, Prasad, CENGAGE
Date:
1.Aim:
Basic Linux environment and its editors like Vi, Vim & Emacs etc.
2.Software Required:
Linux
3.Theory:
Creating a basic Linux environment and installing text editors like Vi, Vim, and Emacs can be
done on a Linux-based system. Here's a step-by-step guide to set up a basic Linux environment
and install these text editors:
You can choose a Linux distribution that suits your preferences. Popular choices include
Ubuntu, Debian, Fedora, CentOS, and others. You can download the ISO image of the
distribution you prefer from the official website and install it on a virtual machine or a physical
computer.
2. **Install Linux**:
Follow the installation instructions for your chosen Linux distribution. During the installation,
you will be asked to create a user account and set a password. Ensure that you have internet
access.
After installation, open a terminal and update your system to ensure you have the latest
software packages. Use the package manager that comes with your distribution:
On Debian/Ubuntu:
```bash
```
On Fedora:
```bash
sudodnf update
```
- **Vi/Vim**:
Vi is usually pre-installed on most Linux distributions. You can also install Vim (an improved
version of Vi) if it's not already installed:
```bash
```
- **Emacs**:
```bash
```
5. **Usage**:
- To open a terminal, you can use the built-in terminal emulator in your Linux distribution.
You can typically find it in your applications or use a keyboard shortcut (e.g., Ctrl+Alt+T).
- To use Vi or Vim, open a terminal and type `vi` or `vim` followed by the name of the file you
want to edit. For example:
```bash
vi filename.txt
```
- To use Emacs, open a terminal and type `emacs` followed by the name of the file you want to
edit. For example:
```bash
emacs filename.txt
```
Vi, Vim, and Emacs have steep learning curves, especially if you're new to them. You can find
online tutorials, documentation, and books to help you get started and become proficient with
these editors.
Date:
1.Aim:
2. Software Required:
Turbo C
3. Theory:
Exposure to Turbo C and GCC (GNU Compiler Collection) can be valuable for individuals
interested in programming and software development, especially in the C and C++ programming
languages. These two development environments have been widely used for many years and
offer different advantages.
1. **Turbo C**:
- **Advantages**:
- **Disadvantages**:
- May not support all the features of the latest C/C++ standards.
- **Overview**: GCC is a powerful and widely used collection of compilers and tools for
various programming languages, including C, C++, and others. It is open-source software and
can be used on various platforms.
- **Advantages**:
- **Disadvantages**:
- May have a steeper learning curve for beginners due to its configurability.
Exposure to both Turbo C and GCC can provide a balanced understanding of the history and
evolution of C and C++ development tools:
- Turbo C can help beginners grasp the basics of C and C++ programming in a simple and user-
friendly environment.
- GCC can be essential for those who want to work on modern and cross-platform projects, as it
provides access to the latest language features and a wide range of development tools.
In the real world, many professional C and C++ developers primarily use GCC or other modern
IDEs like Visual Studio Code, CLion, or Xcode, depending on their platform and project
requirements. However, understanding the foundations and history of these tools can be
beneficial for a well-rounded knowledge of programming in C and C++.
Exp No:
Date:
1. Aim:
2. Software Required:
Turbo C
3. Theory:
The input and output functions used in C language.printf( ) is a output statement used to display
the output on the console deviece . scanf( ) is the input statement which is used to read the
information from the user. These functions can be used by including the header file “stdio.h” in
the program.
4. Program:
#include<stdio.h>
#include<conio.h>
main()
printf("######");
printf("\n#");
printf("\n#");
printf("\n####");
printf("\n#");
printf("\n#");
getch();
######
#
#
####
#
#
4. Program:
#include<conio.h>
#include<stdio.h>
main()
int a,b;
printf("Enter a value:");
scanf("%d",&a);
printf("\nEnter b value:");
scanf("%d",&b);
getch();
return 0;
Enter a value: 6
Enter b value: 34
a=6
b=34
6. Result:
Successfully Executed.
7.Reference:
https://www.programiz.com/c-programming/examples
Date:
1.Aim:
2.Software Required:
TURBO C
3.Theory:
After that created another variable named avg with the help of float data type.
In this avg variable, we will store the average of the number three and in the sum variable, we
in the x, y, z variables.
After this, we Calculate the sum of three numbers using the formula (sum = x + y + z ) and
After this, we Calculate the average of three numbers using the formula (average =
function.
4.Program:
#include <stdio.h>
#include<conio.h>
main()
int a,b,c;
Dept of IT, GIETEngineeringCollege, Rajahmundry
Calculating Marks
float sum,avg;
scanf("%d%d%d",&a,&b,&c),
sum=a+b+c;
avg=sum/3;
getch();
5.Algorithm:
6.Flow Chart:
8.Result:
Sum and average of three number executed Successfully.
9.Reference:
https://cstutorialpoint.com/c-program-to-find-the-sum-and-average-of-three-numbers/
Date:
1.Aim:
2.Software Required:
TURBO C
3.Theory:
Similarly, there is also a formula to convert Fahrenheit to Celsius, using which we will be able to
convert Fahrenheit to Celsius.
Celsius = ((Fahrenheit-32)*5)/9;
4.Program:
#include<stdio.h>
int main()
{
float t1, t2,c,f;
printf("Enter Temperature in Celsius : ");
scanf("%f",&t1);
printf("\nEnter Temperature in Fahrenheit : ");
scanf("%f",&t2);
5.Algorithm:
1. Program Start
2. Declaration of variable
3. Enter temperature in Celsius
4. Enter temperature in Fahrenheit
5. Converting conversion into Fahrenheit
6. Converting Fahrenheit into Celsius
7. Displaying result
8. Program End
6.FlowChart:
8.Result:
9.Reference:
https://cstutorialpoint.com/c-program-to-convert-temperature-from-celsius-to-fahrenheit-and-
fahrenheit-to-celsius/
Date:
2. Software Developed:
Turbo C
3.Theory:
Simple interest is a quick method of calculating the interest charge on a loan. In this article, we
will learn to calculate the simple interest in C programming language.
Simple interest is determined by multiplying the daily interest rate by the principal by the
number of days that elapse between payments. Divide the product of these three values to
convert the percentage value of the interest rate into decimals.
Si=p*t*r/100
Where P is the principal amount, T is the time, and, R is the interest rate
4. Program:
#include<stdio.h>
#include<conio.h>
int main()
float p,t,r;
float interest,amount;
scanf("%f",&p);
scanf("%f",&t);
scanf("%f",&r);
interest=(p*t*r)/100;
amount=p+interest;
printf("\nTime period=%f",t);
printf("\nRate of interest=%f=",r);
getch();
4. Algorithm:
Step 1 : START
Step 2 : Declare variables p , n , r and si .
Step 3 : Read the values of variable p ( principal ) , n ( Number of years ) , r ( Rate of Interest ) .
Step 4 : calculate the values of “ si = ( p * n * r )/100 “ .
Step 5 : Display si ( simple interest ) .
Step 6 : STOP
5. Flow Chart:
7.Result:
Successfully Executed
8.References:
https://www.geeksforgeeks.org/c-program-for-simple-interest/
2. Software Required:
Turbo C
3.Theory:
A Square root of a number is a value that, when multiplied by itself, gives the number.
4.Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int a;
float square ;
printf("Enter the value for which you want to find sqare root::");
scanf("%d",&a);
square=sqrt(a);
printf("\n The square root of %d is =%f",a,square);
getch();
}
6.Result:
Successfully Executed.
7.Reference:
https://www.codingbroz.com/c-program-to-find-square-root-of-a-number/
Compound Interest
Exp.No:
Date:
2.Software Required:
Turbo C
3.Theory:
Compound interest is the addition of interest to the principal sum of a loan or deposit,
or in other words, interest on interest. It is the result of reinvesting interest, rather than
paying it out, so that interest in the next period is then earned on the principal sum plus
previously-accumulated interest. Compound interest is standard in finance and
economics.
4.Program:
#include <stdio.h>
#include <math.h>
int main()
{
float principle, rate, time, CI;
return 0;
}
6.Result:
Successfully Executed
7.Reference:
https://www.geeksforgeeks.org/c-program-for-compound-interest/
Date:
1.Aim:
Implementing a C program to find area of triangle using heron’s formulae.
2.Software Required:
Turbo C
3.Program:
#include <stdio.h>
#include <math.h>
int main()
{
float s1, s2, s3, s, area;
printf("\nEnter the length of three sides of triangle");
scanf("%f %f %f", &s1, &s2, &s3);
s = (s1 + s2 + s3)/2;
area = sqrt(s*(s-s1)*(s-s2)*(s-s3));
printf("Area of triangle : %0.4f\n", area);
return 0;
}
5.Result:
Successfully completed.
6. References:
https://btechgeeks.com/c-program-to-calculate-area-of-any-triangle-using-herons-formula/
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
int main() {
float u,a,s;
int t;
scanf("%f%f",&a,&u);
scanf("%d",&t);
s=(u*t)+(a*t*t)/2;
printf("%f",s);
return 0;
14.000000
5.Result:
Successfully Executed.
6.Reference:
https://btechgeeks.com/c-program-to-calculate-area-of-any-triangle-using-herons-formula/
Evaluate Expressions
Exp.No:
Date:
1.Aim:
a. A+B*C+(D*E) + F*G
b. A/B*C-B+A*D/3
c. A+++B---A
d. J= (i++) + (++i)
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
int main()
int A = 5, B = 10, C = 2, D = 7, E = 3, F = 4, G = 6;
result_a = A + B * C + (D * E) + F * G;
result_b = A / B * C - B + A * D / 3;
j = (i++) + (++i);
return 0;
4.Algorithm:
6.Result:
Successfully Executed.
7.Reference:
https://www.educba.com/expression-evaluation-in-c
Date:
1.Aim:
Implementing a C program to find the maximum of three numbers using conditional operator.
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
int main()
max = (num1 > num2) ? ((num1 > num3) ? num1 : num3) : ((num2 > num3) ? num2 :
num3);printf("Maximum number is %d\n", max);
return 0;
4.Algorithm:
Step-3: Calculate max value using the conditional operator (ternary operator) to find the
maximum.
Maximum number is 6
6.Result:
Successfully Executed.
7.Reference:
https://www.geeksforgeeks.org/conditional-or-ternary-operator-in-c/
Calculating Marks
Exp.No:
Date:
1.Aim:
Implementing a C program for calculatingmarks of 5 subjects in integers, and find the total,
average in float
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
main()
scanf("%d", &marks[i]);
total += marks[i];
return 0;
56
35
50
70
5.Result:
Successfully Executed.
6.Reference:
https://w3codeworld.com/article/72/c-program-to-enter-the-marks-of-five-subjects-and-
calculate-total--average--and-percentage
Date:
1.Aim:
Implement a C program to find the max and min of four numbers using if-else.
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
main()
{
int n1, n2, n3, n4;
int max, min;
printf("Enter four numbers: ");
scanf("%d %d %d %d", &n1, &n2, &n3, &n4);
if (n1 >= n2 && n1 >= n3 && n1 >= n4)
{
max = n1;
}
else if (n2 >= n1 && n2 >= n3 && n2 >= n4)
{
max = n2;
}
else if (n3 >= n1 && n3 >= n2 && n3 >= n4)
{
max = n3;
}
else
{
max = n4;
}
if (n1 <= n2 && n1 <= n3 && n1 <= n4)
{
min = n1;
}
else if (n2 <= n1 && n2 <= n3 && n2 <= n4)
{
min = n2;
}
else if (n3 <= n1 && n3 <= n2 && n3 <= n4)
{
min = n3;
}
else
{
min = n4;
}
printf("Maximum is: %d\n", max);
printf("Minimum is: %d\n", min);
return 0;
}
4.Sample Input and Output:
Enter four numbers: 56 8 0 90
Maximum is: 90
Minimum is: 0
5.Result:
Successfully Executed.
6.Reference:
https://www.w3resource.com/c-programming-exercises/basic-declarations-and-expressions/c-
programming-basic-exercises-58.php
Date:
1.Aim:
}
sur_charge = amt * 0.20;
total_amt = amt + sur_charge;
printf("Electricity Bill = Rs. %.2f", total_amt);
return 0;
}
4.Sample Input and Output:
Enter total units consumed: 500
5.Result:
Successfully Executed.
6.Reference:
https://codeforwin.org/c-programming/c-program-to-calculate-electricity-bill
Date:
1.Aim:
}
else
{
double realPart = -b / (2 * a);
double imaginaryPart = sqrt(-discriminant) / (2 * a);
printf("Two complex roots:\n");
printf("Root 1 = %.2lf + %.2lfi\n", realPart, imaginaryPart);
printf("Root 2 = %.2lf - %.2lfi\n", realPart, imaginaryPart);
}
return 0;
}
4.Sample Input and Output:
Enter the coefficients of the quadratic equation (a, b, c): 4
5.Result:
Successfully Executed.
6.Reference:
https://www.programiz.com/c-programming/examples/quadratic-roots
Date:
1.Aim:
break;
default:
printf("Error! operator is not correct");
}
return 0;
}
4.Sample Input and Output:
Enter an operator (+, -, *, /): *
5.Result:
Successfully Executed.
6.Reference:
https://www.programiz.com/c-programming/examples/calculator-switch-case
Date:
1.Aim:
5.Result:
Successfully Executed.
6.Reference:
https://www.tutorialspoint.com/learn_c_by_examples/leap_year_program_in_c.htm
Date:
1.Aim:
Implement a C program to find the factorial of given number using any loop.
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
main()
{
int i=1, f = 1, n;
printf("Input the number : ");
scanf("%d", &n);
while (i<= n)
{
f = f * i;
i++;
}
printf("The Factorial of %d is: %d\n", n, f);
return 0;
}
4.Sample Input and Output:
Input the number : 6
5.Result:
Successfully Executed.
6.Reference:
https://www.w3resource.com/c-programming-exercises/for-loop/c-for-loop-exercises-15.php
Prime Or Not
Exp.No:
Date:
1.Aim:
5.Result:
Successfully Executed.
6.Reference:
https://www.programiz.com/c-programming/examples/prime-number
Date:
1.Aim:
sinX += term;
if (i % 2 == 0) {
// For cosine, the terms with even exponents are added
cosX += term;
}
}
// Display the results
printf("sin(x) = %.6lf\n", sinX);
printf("cos(x) = %.6lf\n", cosX);
return 0;
}
4.Sample Input and Output:
Enter the angle in radians (x): 4
Enter the number of terms in the series: 4
sin(x) = -1.384127
cos(x) = 12.533333
5.Result:
Successfully Executed.
6.Reference:
https://www.codingconnect.net/c-program-sine-series/
Number Palindrome
Exp.No:
Date:
1.Aim:
Successfully Executed.
6.Reference:
https://www.w3resource.com/c-programming-exercises/for-loop/c-for-loop-exercises-38.php
Pyramid Of Numbers
Exp.No:
Date:
1.Aim:
232
34543
4567654
567898765
5.Result:
Successfully Executed.
6.Reference:
https://www.programiz.com/c-programming/examples/pyramid-pattern
Date:
1.Aim:
Implement a C program to find the min and max of a 1-D integer array.
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
void main()
{
int arr1[100];
int i, mx, mn, n;
printf("\n\nFind maximum and minimum element in an array :\n");
printf("------------------------------------------------\n");
printf("Input the number of elements to be stored in the array :");
scanf("%d",&n);
printf("Input %d elements in the array :\n",n);
for(i=0;i<n;i++)
{
printf("element - %d : ",i);
scanf("%d",&arr1[i]);
}
mx = arr1[0];
mn = arr1[0];
for(i=1; i<n; i++)
{
if(arr1[i]>mx)
{
mx = arr1[i];
}
if(arr1[i]<mn)
{
mn = arr1[i];
}
}
printf("Maximum element is : %d\n", mx);
printf("Minimum element is : %d\n\n", mn);
}
4.Sample Input and Output:
Find maximum and minimum element in an array :
------------------------------------------------
element - 0 : 12
element - 1 : 35
element - 2 : 3
element - 3 : 90
element - 4 : 1
Maximum element is : 90
Minimum element is : 1
5.Result:
Successfully Executed.
6.Reference:
https://www.w3resource.com/c-programming-exercises/array/c-array-exercise-9.php
Date:
1.Aim:
}
4.Sample Input and Output:
Enter number of elements in array
Enter 4 integer(s)
12
90
-1
12
12 is present at location 1.
5.Result:
Successfully Executed.
6.Reference:
https://www.programmingsimplified.com/c/source-code/c-program-linear-search
Date:
1.Aim:
5.Result:
Successfully Executed.
6.Reference:
https://www.w3schools.in/c-programming/examples/reverse-array
Date:
1.Aim:
onesComp[SIZE] = '\0';
/*
* Add 1 to the ones complement
*/
for(i=SIZE-1; i>=0; i--)
{
if(onesComp[i] == '1' && carry == 1)
{
twosComp[i] = '0';
}
else if(onesComp[i] == '0' && carry == 1)
{
twosComp[i] = '1';
carry = 0;
}
else
{
twosComp[i] = onesComp[i];
}
}
twosComp[SIZE] = '\0';
Successfully Executed.
6.Reference:
https://codeforwin.org/c-programming/c-program-to-find-twos-complement-of-binary-number
Date:
1.Aim:
5.Result:
Successfully Executed.
6.Reference:
https://www.tutorialspoint.com/c-program-to-delete-the-duplicate-elements-in-an-array
Date:
1.Aim:
main()
scanf("%d", &r);
scanf("%d", &c);
scanf("%d", &a[i][j]);
scanf("%d", &b[i][j]);
if (j == c - 1)
printf("\n\n");
return 0;
13 5
6 6
5.Result:
Successfully Executed.
6.Reference:
https://www.programiz.com/c-programming/examples/add-matrix
Date:
1.Aim:
{
for (d = 0; d < q; d++)
{
for (k = 0; k < p; k++)
{
tot = tot + fst[c][k] * sec[k][d];
}
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;
}
4.Sample Input and Output:
Please insert the number of rows and columns for first matrix
22
11
11
Please insert the number of rows and columns for second matrix
22
22
22
4 4
4 4
5.Result:
Successfully Executed.
6.Reference:
https://www.w3schools.in/c-programming/examples/matrix-multiplication-in-c
Bubble Sort
Exp.No:
Date:
1.Aim:
TURBO C
3.Theory:
Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent
elements if they are in the wrong order. This algorithm is not suitable for large data sets as its
average and worst-case time complexity is quite high.
4.Program:
#include<stdio.h>
bubble(int *a,int n)
{
int tem,count, i,j;
for(i=0;i<n-1;i++)
{
count=0;
for(j=0;j<n-1-i;j++)
{
if(a[j]>a[j+1])
{
tem=a[j];
a[j]=a[j+1];
a[j+1]=tem;
count=1;
}
}
if(count==0)
break;
}
}
main()
{
int n,a[100],i;
printf("\nenter number of elements:");
scanf("%d",&n);
printf("\nenter array elements:");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nThe elements before sorting :");
for(i=0;i<n;i++)
printf(" %d ",a[i]);
bubble(a,n);
printf("\nThe elements after sorting are:");
for(i=0;i<n;i++)
printf(" %d ",a[i]);
return 0;
}
5.Algorithm:
Bubble(a,n)
Begin
Set tmp=a[j];
Set a[j]=a[j+1];
Set a[j+1]=tmp;
Endif
Endfor
endfor
end
7.Result:
6.Reference:
https://www.geeksforgeeks.org/bubble-sort/
Date:
1.Aim:
3.Program:
void main(void)
char str1[25],str2[25];
int i=0,j=0;
gets(str1);
gets(str2);
while(str1[i]!='\0')
i++;
while(str2[j]!='\0')
str1[i]=str2[j];
j++;
i++;
str1[i]='\0';
5.Result:
Successfully Executed.
6.Reference:
https://www.w3schools.in/c-programming/examples/concatenate-two-strings-without-using-
strcat
Date:
1.Aim:
Implement a C program toReverse a string using built-in and without built-in string functions
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void main()
{
char str[100];
int l, i;
printf("\n\nPrint individual characters of string in reverse order :\n");
printf(" \n");
printf("Input the string : ");
fgets(str, sizeof str, stdin);
l=strlen(str);
printf("The characters of the string in reverse are : \n");
for(i=l;i>=0;i--)
{
printf("%c ", str[i]);
}
printf("\n");
}
5.Result:
Successfully Executed.
6.Reference:
https://www.tutorialspoint.com/cprogramming/index.htm
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
void main()
int i, n;
scanf("%d", &n);
scanf("%d", a + i);
scanf("%d", b + i);
return 0;
12 23 34 1 2
13456
Resultant List is
13263868
5.Result:
Successfully Executed.
6.Reference:
https://www.sanfoundry.com/c-program-compute-sum-two-one-dimensional-arrays-using-
malloc/
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include<stdio.h>
struct student
char name[10];
float m1,m2,m3;
float avg,total;
};
void main()
int n,i;
float tavg,sum=0.0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%s",s[i].name);
scanf("%f%f%f",&s[i].m1,&s[i].m2,&s[i].m3);
s[i].total=s[i].m1+s[i].m2+s[i].m3;
s[i].avg=s[i].total/3;
for(i=0;i<n;i++)
if(s[i].avg>=35)
else
Enter Name=deepu
45 56 67
Enter Name=deepthi
78 45 78
5.Result:
Successfully Executed.
6.Reference:
https://www.vtuloop.com/program-13-c-programming-lab/
Date:
1.Aim:
Implement a C program to Enter n students data using calloc() and display failed students list.
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
#include <stdlib.h>
struct Student
char name[50];
int rollNumber;
float marks;
};
int main()
int n;
scanf("%d", &n);
printf("Name: ");
scanf("%s", students[i].name);
scanf("%d", &students[i].rollNumber);
printf("Marks: ");
scanf("%f", &students[i].marks);
if (students[i].marks<=40.0)
printf("\n");
free(students);
return 0;
Name: divitha
Roll Number: 1
Marks: 90
Name: deepu
Roll Number: 2
Marks: 40
Name: deepu
Roll Number: 2
Marks: 40.00
5.Result:
Successfully Executed.
6.Reference:
https://www.vtuloop.com/program-13-c-programming-lab/
Read student name and marks from the command line and display
the student details
Exp.No:
Date:
1.Aim:
Implement a C program to Read student name and marks from the command line and display the
student details along with the total
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
#include <stdlib.h>
struct Student {
char name[50];
int marks;
};
if (argc< 2) {
return 1;
int n = atoi(argv[1]);
if (students == NULL) {
return 1;
scanf("%s", students[i].name);
scanf("%d", &students[i].marks);
int total = 0;
int failedCount = 0;
total += students[i].marks;
if (students[i].marks< 40) {
failedCount++;
printf("\nStudent Details:\n");
if (failedCount> 0) {
if (students[i].marks< 40) {
} else {
free(students);
return 0;}
Total marks: 35
5.Result:
Successfully Executed.
6.Reference:
https://www.vtuloop.com/program-13-c-programming-lab/
Realloc() Function
Exp.No:
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
#include <stdlib.h>
int main()
int n = 4, i, *p, s = 0;
if(p == NULL)
exit(0);
scanf("%d", p + i);
s += *(p + i);
scanf("%d", p + i);
s += *(p + i);
return 0;
Sum : 14
Sum : 28
5.Result:
Successfully Executed.
6.Reference:
https://www.tutorialspoint.com/use-of-realloc-in-c
Date:
1.Aim:
Implement a C program to Create and display a singly linked list using self-referential structure.
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
#include <stdlib.h>
struct node
int data;
};
int main()
head->data = 1;
second->data = 2;
third->data = 3;
head->next = second;
second->next = third;
third->next = NULL;
current = current->next;
return 0;
123
5.Result:
Successfully Executed.
6.Reference:
https://www.prepbytes.com/blog/c-programming/self-referential-structure-in-c/
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
struct Person
char name[50];
int age;
};
union Data {
int integerData;
float floatData;
};
int main()
strcpy(person1.name, "John");
person1.age = 25;
data1.integerData = 42;
printf("Structure - Person:\n");
printf("\n");
printf("Union - Data:\n");
data1.floatData = 3.14;
return 0;
Structure - Person:
Name: John
Age: 25
Union - Data:
Integer Data: 42
5.Result:
Successfully Executed.
6.Reference:
https://www.vtuloop.com/program-13-c-programming-lab/
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
struct BitfieldRotation
};
int main()
bitfield.data = 0xC;
printf("Original Bitfield:\n");
displayBitfield(bitfield);
leftRotate(&bitfield);
displayBitfield(bitfield);
rightRotate(&bitfield);
displayBitfield(bitfield);
return 0;
Original Bitfield:
Bitfield Data: C
Bitfield Data: 9
Bitfield Data: C
5.Result:
Successfully Executed.
6.Reference:
https://www.vtuloop.com/program-13-c-programming-lab/
Date:
1.Aim:
Implement a C program to copy one structure variable to another structure of the same type.
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
struct Student
char name[50];
int age;
float marks;
};
strcpy(dest->name, src->name);
dest->age = src->age;
dest->marks = src->marks;
int main()
copyStruct(&student2, &student1);
printf("Original Student:\n");
displayStudent(&student1);
printf("\nCopied Student:\n");
displayStudent(&student2);
return 0;}
Original Student:
Age: 20
Marks: 85.50
Copied Student:
Age: 20
Marks: 85.50
5.Result:
Successfully Executed.
6.Reference:
https://www.vtuloop.com/program-13-c-programming-lab/
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
void main()
int n, r, ncr;
int fact(int z)
int f = 1, i;
if (z == 0)
return(f);
else
f = f * i;
return(f);
52
5.Result:
Successfully Executed.
6.Reference:
https://www.sanfoundry.com/c-program-ncr/
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include<stdio.h>
#include<string.h>
int main() {
scanf("%s",str);
len = strlen(str);
return(0);}
5.Result:
Successfully Executed.
6.Reference:
https://www.codingninjas.com/studio/library/c-program-to-count-length-of-string-using-library-
function
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
#define N 4
int i, j;
B[i][j] = A[j][i];
int main()
int A[N][N] = { { 1, 1, 1, 1 },
{ 2, 2, 2, 2 },
{ 3, 3, 3, 3 },
{ 4, 4, 4, 4 } };
int B[N][N], i, j;
transpose(A, B);
printf("\n");
return 0;
Result matrix is
1234
1234
1234
1234
5.Result:
Successfully Executed.
6.Reference:
https://www.geeksforgeeks.org/c-transpose-matrix/
Euler’s method.
Exp.No:
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
return x + y;
printf("Euler's Method:\n");
printf("x\t\t y\n");
printf("%.4f\t%.4f\n", x, y);
y = y + h * equation(x, y);
x = x + h;
int main() {
double x0 = 0.0;
double y0 = 1.0;
double h = 0.1;
double xn = 1.0;
return 0;}
Euler's Method:
x y
0.0000 1.0000
0.1000 1.1000
0.2000 1.2200
0.3000 1.3620
0.4000 1.5282
0.5000 1.7210
0.6000 1.9431
0.7000 2.1974
0.8000 2.4872
0.9000 2.8159
1.0000 3.1875
5.Result:
Successfully Executed.
6.Reference:
https://www.vtuloop.com/program-13-c-programming-lab/
Fibonacci series
Exp.No:
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
if (num == 0)
return 0;
else if (num == 1)
return 1;
else
int main()
int num;
scanf("%d", &num);
int i;
return 0;
5.Result:
Successfully Executed.
6.Reference:
https://www.scaler.com/topics/fibonacci-series-in-c-using-recursion/
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
return (a * b);
int main() {
scanf("%d", &num1);
scanf("%d", &num2);
return 0;
5.Result:
Successfully Executed.
6.Reference:
https://codeforwin.org/c-programming/c-program-to-find-lcm-of-two-numbers-using-recursion
Factorial of a Number
Exp.No:
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
if (n == 0 || n == 1)
return 1;
else
int main()
int num;
scanf("%d", &num);
if (num < 0)
else
return 0;
5.Result:
Successfully Executed.
6.Reference:
https://www.programiz.com/c-programming/examples/factorial-recursion
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include<stdio.h>
main()
int m,n;
scanf("%d%d",&m,&n);
printf("\nOUTPUT :: %d\n",A(m,n));
if(m==0)
return n+1;
else if(n==0)
return A(m-1,1);
else
return A(m-1,A(m,n-1));
13
OUTPUT :: 5
5.Result:
Successfully Executed.
6.Reference:
https://www.codezclub.com/c-implement-ackermann-function/
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
double seriesSum(int n)
if (n == 0)
return 0;
else
int main()
int terms;
scanf("%d", &terms);
if (terms < 0)
else
return 0;
5.Result:
Successfully Executed.
6.Reference:
https://www.geeksforgeeks.org/c-program-to-find-sum-of-natural-numbers-using-recursion/
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
int main()
int a, b;
printf("\nBefore Swapping:\n");
swap(&a, &b);
printf("\nAfter Swapping:\n");
return 0;
int temp;
temp = *x;
*x = *y;
*y = temp;
Before Swapping:
a = 30
b = 49
After Swapping:
a = 49
b = 30
5.Result:
Successfully Executed.
6.Reference:
https://www.programming9.com/programs/c-programs/194-swapping-of-two-numbers-using-
call-by-reference-in-c-functions
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
#include <stdlib.h>
return arr;
int main()
arr[i] = i + 1;
printf("\n");
free(arr);
printf("\n");
return 0;
12345
0 0 35393552 0 5
5.Result:
Successfully Executed.
6.Reference:
https://www.prepbytes.com/blog/c-programming/dangling-pointer-in-c/
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include<stdio.h>
main()
gets(source);
copy_string(target, source);
return 0;
while(*source)
*target = *source;
source++;
target++;
*target = '\0';
saideepthi
5.Result:
Successfully Executed.
6.Reference:
https://www.w3schools.in/c-programming/examples/copy-string-using-pointers
Date:
1.Aim:
Implement a C program to find no of lowercase, uppercase, digits and other characters using
pointers.
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
#include <stdlib.h>
int main()
char str[100];
int i;
int upper=0,lower=0,num=0,special=0;;
gets(str);
upper++;
lower++;
num++;
else
special++;
printf("\nNumbers: %d",num);
getch();
Sai Deepthi @1
Numbers: 1
Special characters: 3
5.Result:
Successfully Executed.
6.Reference:
https://code4coding.com/program-to-count-uppercase-lowercasespecial-character-and-numeric-
values-in-c/
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
#include <stdlib.h>
int main()
FILE *file;
if (file == NULL)
return 1;
fclose(file);
if (file == NULL)
return 1;
char ch;
putchar(ch);
fclose(file);
return 0;
5.Result:
Successfully Executed.
6.Reference:
https://www.vtuloop.com/program-13-c-programming-lab/
write and read text into a binary file using fread() and fwrite()
Exp.No:
Date:
1.Aim:
Implement a C program to write and read text into a binary file using fread() and fwrite().
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
#include <stdlib.h>
struct Person
char name[50];
int age;
};
int main()
FILE *file;
if (file == NULL)
return 1;
fclose(file);
if (file == NULL)
return 1;
fclose(file);
return 0;
5.Result:
Successfully Executed.
6.Reference:
https://www.vtuloop.com/program-13-c-programming-lab/
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
#include <stdlib.h>
int main()
if (sourceFile == NULL)
return 1;
if (destinationFile == NULL)
fclose(sourceFile);
return 1;
char ch;
fputc(ch, destinationFile);
fclose(sourceFile);
fclose(destinationFile);
return 0;
5.Result:
Successfully Executed.
6.Reference:
https://www.vtuloop.com/program-13-c-programming-lab/
Merge two files into the third file using command-line arguments
Exp.No:
Date:
1.Aim:
Write a C program to merge two files into the third file using command-line arguments.
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
#include <stdlib.h>
if (argc != 4) {
return 1;
if (inputFile1 == NULL) {
if (inputFile2 == NULL) {
fclose(inputFile1);
if (outputFile == NULL) {
fclose(inputFile1);
fclose(inputFile2);
char ch;
fputc(ch, outputFile);
fputc(ch, outputFile);}
fclose(inputFile1);
fclose(inputFile2);
fclose(outputFile);
return 0; }
5.Result:
Successfully Executed.
6.Reference:https://www.vtuloop.com/program-13-c-programming-lab/
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
int ch;
int inWord = 0;
(*characters)++;
if (ch == '\n')
(*lines)++;
} else if (inWord == 0) {
(*words)++;
int main() {
FILE *file;
char fileName[50];
scanf("%s", fileName);
if (file == NULL) {
fclose(file);
return 0;
5.Result:
Successfully Executed.
6.Reference:
https://www.vtuloop.com/program-13-c-programming-lab/
Date:
1.Aim:
2.Software Required:
TURBO C
3.Program:
#include <stdio.h>
#include <stdlib.h>
fseek(file, 0, SEEK_END);
if (startPosition< 0)
startPosition = 0;
int ch;
putchar(ch);
int main()
FILE *file;
char fileName[50];
int n;
scanf("%s", fileName);
if (file == NULL)
return 1;
scanf("%d", &n);
printLastNCharacters(file, n);
fclose(file);
return 0;
5.Result:
Successfully Executed.
6.Reference:
https://www.vtuloop.com/program-13-c-programming-lab/