Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

C Lab First 3 Exercise

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

`

K.L.N. COLLEGE OF ENGINEERING


(An Autonomous Institution, Affiliated to University, Chennai)
Pottapalayam.P.O, Sivagangai -630611.

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

20CS2L1-C PROGRAMMING LABORATORY MANUAL

I YEAR / II SEMESTER
2023-2024 (EVEN)

PREPARED BY:

Mrs.A.Thirunirai Selvi, AP/IT(B Section)

Mrs.K.Rani,AP/IT(A Secition)
`

SYLLABUS

20CS2L1 C PROGRAMMING LABORATORY LTPC


0042
OBJECTIVES:
 To develop programs in C using basic constructs.
 To develop applications in C using strings, pointers, functions, structures.
 To develop applications in C using file processing.

LIST OF PROGRAMS

1. Programs using I/O statements, expressions and decision-making constructs.


2. Program for finding given year is leap year or not and finding given number is Armstrong
number or not.
3. Design a calculator to perform the operations namely, addition, subtraction, multiplication,division
and square of a number.
4. Given a set of numbers like <10, 36, 54, 89, 12, 27>, find sum of weights based on the
following conditions.
 5 if it is a perfect cube.
 4 if it is a multiple of 4 and divisible by 6.
 3 if it is a prime number.
Sort the numbers based on the weight in the increasing order as shown below <10,itsweight>,<36,its
weight><89,its weight>
5. Matrix addition and subtraction
6. Matrix multiplication and transpose of a matrix
7. Program using string with and without using string functions: string copy and Reverse theString.
8. Convert the given decimal number into binary, octal and hexadecimal numbers using userdefined
functions.
9. From a given paragraph perform the following using built-in functions:
a. Find the total number of words.
b. Capitalize the first word of each sentence.
c. Replace a given word with another word.
10. Program using recursion – factorial and Fibonacci series
11. Sort the list of numbers using pass by reference.
12. Generate salary slip of employees using structures and pointers.
13. Insert, update, delete and append telephone details of an individual or a company into a
telephone directory using random access file.
14. Count the number of account holders whose balance is less than the minimum balanceusing
sequential access file.
15. Mini project (Any one project: Maximum 4 per Team)
 Railway reservation system
 Library Management System
 University Result Publication System
 Hospital Management System
 Student Automation System
 Payroll System
 Banking System
 Inventory System

PLATFORM NEEDED: Turbo C++ Compiler TOTAL: 60 PERIODS

OUTCOMES:
`

AT THE END OF THE COURSE, LEARNERS WILL BE ABLE TO:


 Develop simple programs using decision making and looping statements.
 Utilize array concepts to perform matrix addition, subtraction and multiplication.
 Utilize string operations and develop programs to show string copy and reverse.
 Develop programs using user defined functions, built-in functions and recursion.
 Design applications using sequential and random access files.
 Design simple real time projects using the concepts of structures and union.

STAFF INCHARGE HOD/CSE


`

EX.NO:1a
PROGRAM USING I/O STATEMENTS AND EXPRESSIONS
DATE:

(a) a given product with a GST OF 12%,find the GST amount and the total value of the
product.

AIM:
To find the discount value, GST amount and the total value of the product.

ALGORITHM:
1.Start the program.
2.Read the item Details.
3.Read discount and tax % details.
4.Calculate amount as quantity x value.
5.Calculate discount as (amount x discount)/100.
6.Calculate subtotal as amount-discount
7.Calculate tax as (subtotal x tax)/100
8.Calculate total amount as (subtotal + taxamt)
9.Print all Details
10.Stop the Program

PROGRAM:
#include<stdio.h>
#include<conio.h>
main()
{
float totamt, amount,subtot,disamt,taxamt,quantity,value,discount,tax;
clrscr();
printf("\n Enter the quantity of item sold:");
scanf("%f",&quantity);
printf("\n Enter the value of item:");
scanf("%f",&value);
printf("\n Enter the Discount percentage:");
scanf("%f",&discount);
printf("\n Enter the tax:");
scanf("%f",&tax);

amount=quantity * value;
disamt=(amount*discount)/100.0;
subtot=amount-disamt;
taxamt=(subtot*tax)/100.0;
totamt=subtot+taxamt;

printf("\n\n\n ******BILL****** ");


printf("\nQuantitysold: %f", quantity);
printf("\npriceperitem: %f", value);
printf("\nAmount: %f", amount);
printf(" \n Discount: - %f", disamt) ;
`

printf("\n Discounted Total: %f", subtot) ;


printf("\n Tax:=+ %f", taxamt);
printf("\n Total Amount %f", totamt);
getch();
}

RESULT:
Thus the program to find the GST Amount andthe total value of the product was
executed and the output was verified.
`

EX.NO:1b PROGRAM USING I/O STATEMENTS AND EXPRESSIONS

DATE:

(b) Write a C Program to find area and perimeter of Circle.

AIM:
To write a C Program to find area and perimeter of Circle.

ALGORITHM:
1.Start the program.
2.Read radius.
3.calculate Area as P1 * Radius * Radius ,
4.calculate perimeter as 2 * PI * Radius
5.Print area,Perimeter
6.Stop.

PROGRAM:
#include<stdio.h>
#include<conio.h>
#define pi 3.14
void main()
{
float r,area,perimeter;
clrscr();
printf("\n Enter r value:");
scanf("%f",&r);
area=pi*r*r;
printf(" area%f:",area);
perimeter=2*pi*r;
printf("perimeter%f:",perimeter);
getch();
}

RESULT:
Thus the program to find area and perimeter of Circle was executed and the output was
verified.
`

EX.NO:1(c) PROGRAMS USING DECISION-MAKING CONSTRUCTS

DATE:

(c) Write a C Program to Find the Eligibility of a Person to Vote or Not?

AIM:
To Write a C Program to find the eligibility of a Person to Vote or not?

ALGORITHM:
1. Start the program.
2. Read name, age of the person.
3. Check the age of the candidate.
4.If it is greater than or equal to 18 print “ Eligible”.
5.Otherwise print as “ Not Eligible”.
6.Stop the Program.

PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int age;
char name[50]; // or *name
clrscr();
printf("\n Type the Name of the candidate: ");
gets(name);
printf("\n Enter The Age : ");
scanf("%d",&age);
puts(name);
if(age>=18)
printf("\n %s is Eligible for Vote",name);
else
printf("\n %s is Not Eligible for Vote",name);
getch();
}

RESULT:
Thus the program to find the eligibility of a Person to Vote or not was executed and the
output was verified.
`

EX.NO:1(d) PROGRAMS USING DECISION-MAKING CONSTRUCTS

DATE:

(d) Write a C Program to find the Largest Numbers Among Three Numbers.

AIM:
To Write a C Program to find the Largest Numbers among Three Numbers.

ALGORITHM:

1.Start the program.


2.Read the numbers a, b ,c.
3.Compare first number a with b and c.
4.if it is greater print a as biggest number
5.otherwise, compare the remaining numbers b and c
6.print biggest number.
7.Stop the Program.

PROGRAM:

#include <stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
int big;
clrscr();
printf("Enter three numbers:");
scanf("%d%d%d",&a,&b,&c);
if(a>b && a>c)
big=a;
else if(b>a && b>c)
big=b;
else
big=c;
printf("Largest number is = %d",big);
getch();
}

RESULT:
Thus the program to find the Largest Numbers among Three Numbers was executed and
the output was verified.
`

EX.NO:2(a) WRITE A PROGRAM TO FIND WHETHER THE GIVEN YEAR IS LEAP YEAR OR
NOT.
DATE:
`

AIM:
To Write a program to find whether the given year is leap year or not.

ALGORITHM:
1. Start the program.
2. Read Year.
3. Check IF Year%4=0.
Step-3.1 IF Year%100=0.
Step-3.1.1 IF Year%400=0.
Step-3.1.2 Print “Leap Year”.
Step-3.1.3 ELSE Print “Not Leap Year.
Step-3.2 ELSE Print “ Not a Leap Year”.
4. Print “Not Leap Year”.
5.Stop.

PROGRAM:
#include <stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf("Enter a year: ");
scanf("%d",&year);
if(year%4 == 0)
{
if( year%100 == 0)
{
if ( year%400 == 0)
printf("%d is a leap year.", year);
else
printf("%d is not a leap year.", year);
}
else
printf("%d is a leap year.", year );
}
else
printf("%d is not a leap year.", year);
getch();
}

RESULT:
Thus the program to find whether the given year is leap year or not was executed and the
output was verified.
`

EX.NO:2 b CHECK WHETHER A GIVEN NUMBER IS ARMSTRONG NUMBER OR NOT?

DATE:

Aim:
To write a C Program to Check whether a given number is Armstrong number or not .
ALGORITHM:
1. Start
2. Declare variables
3. Read the Input number.
4. Calculate sum of cubic of individual digits of the input.
5. Match the result with input number.
6. If match, Display the given number is Armstrong otherwise not.
7. Stop

PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int number, sum = 0, rem = 0, cube = 0, temp;
clrscr();
printf ("enter a number");
scanf("%d", &number);
temp = number;
while (number != 0)
{
rem = number % 10;
cube = pow(rem, 3);
sum = sum + cube;
number = number / 10;
}
if (sum == temp)
printf ("The given no is armstrong no");
else
printf ("The given no is not a armstrong no");
getch();
}

RESULT:
`

Thus a C Program for Armstrong number checking was executed and the output was
obtained.
`

EX.NO:3 DESIGN A CALCULATOR TO PERFORM THE OPERATIONS, NAMELY,


ADDITION,SUBTRACTION, MULTIPLICATION,

DATE:

Aim:
Design a calculator to perform mathematical operations like addition Subtraction multiplication and division
ALGORITHM:

1.Start the program.


2.Read numbers a, b ,c.
3.Display the menu for the Arithmetic operations
4.Get the choice of user for Arithmetic operations
5.Perform Addition in choice 1 and remaining vice versa using switch case
6.Display the Results
7.Stop the program

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,result,sq1,sq2,ch;
float divide;
clrscr();
printf("Enter two integers:");
scanf("%d%d",&a,&b);
printf("1.add,2.subtract,3.multiply,4.divide,5.square");
printf("\n Enter the choice;");
scanf("%d",&ch);
switch(ch)
`

{
case 1:
{
result=a+b;
printf("Sum=%d\n",result);
break;
}
case 2:
{
result=a-b;
printf("Difference=%d\n",result);
break;
}
case 3:
{
result=a*b;
printf("Multiplication=%d\n",result);
break;
}
case 4:
{
result=a/(float)b;
printf("Division=%.2f\n",result);
break;
}
case 5:
{
sq1=a*a;
printf("Square=%d\n",sq1);
sq2=b*b;
printf("Second square=%d\n",sq2);
break;
}

}
getch();
}

RESULT:
Thus the program to Design a calculator to perform the operation, namely, addition,
subtraction, multiplication, division and square of a number was executed and the output was
verified.
`

You might also like