C Lab First 3 Exercise
C Lab First 3 Exercise
C Lab First 3 Exercise
I YEAR / II SEMESTER
2023-2024 (EVEN)
PREPARED BY:
Mrs.K.Rani,AP/IT(A Secition)
`
SYLLABUS
LIST OF PROGRAMS
OUTCOMES:
`
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;
RESULT:
Thus the program to find the GST Amount andthe total value of the product was
executed and the output was verified.
`
DATE:
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.
`
DATE:
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.
`
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:
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.
`
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.
`
DATE:
Aim:
Design a calculator to perform mathematical operations like addition Subtraction multiplication and division
ALGORITHM:
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.
`