PC PDF
PC PDF
:202403103510377
Prac cal 1
AIM : Write a C program to show usage of prin func on.
Code:
#include <stdio.h>
int main()
{
return 0;
}
Output:
pg. 1
Programming with C Enrollment no.:202403103510377
Prac cal 2
AIM : Write a C program to print basic student details using library
func on - prin ().
************************************************
Student Name:
Branch:
Enrollment Number:
************************************************
Code :
#include <stdio.h>
int main() {
char name[] = "Aeshwarya Pa l";
char branch[] = "B.Tech-AI/ML";
long enrollment_number = 202403103510377;
prin ("************************************************\n");
prin ("Student Name: %s\n", name);
prin ("Branch: %s\n", branch);
prin ("Enrollment Number: %ld\n", enrollment_number);
prin ("************************************************\n");
return 0;
}
pg. 2
Programming with C Enrollment no.:202403103510377
Output:
pg. 3
Programming with C Enrollment no.:202403103510377
Prac cal 3
AIM : Write a C program that takes user-entered number and print
the same number on a terminal screen.
Code:
#include<stdio.h>
int main()
{
int number;
prin ("Enter a number: ");
scanf("%d", &number);
prin ("You entered: %d\n", number);
return 0;
}
Output :
pg. 4
Programming with C Enrollment no.:202403103510377
Prac cal 4
AIM : Write a C program to take two integers from the user and
perform arithme c opera ons (addi on, subtrac on, division and
mul plica on) of two numbers.
Code:
#include<stdio.h>
int main()
{
int num1, num2;
int sum, difference, product;
float division;
prin ("Enter first integer: ");
scanf("%d", &num1);
prin ("Enter second integer: ");
scanf("%d", &num2);
sum = num1 + num2;
difference = num1 - num2;
product = num1 * num2;
division = num1 / num2;
prin ("Addi on: %d\n", sum);
prin ("Subtrac on: %d\n", difference);
prin ("Mul plica on: %d\n", product);
prin ("division: %f\n", quo ent);
}
pg. 5
Programming with C Enrollment no.:202403103510377
Output :
pg. 6
Programming with C Enrollment no.:202403103510377
Prac cal 5
AIM : Write a C program to take temperature from the user in F and
display the temperature in C.
Code :
#include <stdio.h>
int main() {
float fahrenheit, celsius;
prin ("Enter temperature in Fahrenheit: ");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
prin ("Temperature in Celsius: %.f\n", celsius);
return 0;
}
Output :
pg. 7
Programming with C Enrollment no.:202403103510377
pg. 8
Programming with C Enrollment no.:202403103510377
Prac cal 6
AIM : Write a C program to display the area as an output of various
shapes (circle and rectangle) to the user. User will enter necessary
parameter values.
Code :
#include <stdio.h>
int main()
{
int choice,PI=3.141;
float area;
prin ("Select a shape to calculate the area:\n");
prin ("1. Circle\n");
prin ("2. Rectangle\n");
prin ("Enter your choice (1 or 2): ");
scanf("%d", &choice);
switch (choice)
{
case 1: // Circle
{
float radius;
prin ("Enter the radius of the circle: ");
scanf("%f", &radius);
area = PI * radius * radius;
prin ("Area of the circle: %.2f\n", area);
break;
pg. 9
Programming with C Enrollment no.:202403103510377
}
case 2: // Rectangle
{
pg. 10
Programming with C Enrollment no.:202403103510377
Output :
pg. 11
Programming with C Enrollment no.:202403103510377
Prac cal 7
AIM : Write a C program that scan an integer from the user and
check whether the number is divisible by 3 or not.
Code :
#include<stdio.h>
int main()
{
int number;
prin ("Enter an integer: ");
scanf("%d", &number);
if (number % 3 == 0)
{
prin ("%d is divisible by 3.\n", number);
}
else { prin ("%d is not divisible by 3.\n", number);
}
}
Output :
pg. 12
Programming with C Enrollment no.:202403103510377
pg. 13
Programming with C Enrollment no.:202403103510377
Prac cal 8
AIM : Write a C program to take inputs of Month and Year from the
user and modify it in such a way that prints month name given the
month number by the user. (e.g. Input: Month: 03, Year: 2023
Output: Month: March)
Code :
#include<stdio.h>
int main()
{
int month, year;
prin ("Enter Month (1-12): ");
scanf("%d", &month);
prin ("Enter Year: ");
scanf("%d", &year);
prin ("Month: ");
switch (month)
{
case 1:
prin ("January\n");
break;
case 2:
prin ("February\n");
break;
case 3:
prin ("March\n");
break;
pg. 14
Programming with C Enrollment no.:202403103510377
case 4:
prin ("April\n");
break;
case 5:
prin ("May\n");
break;
case 6:
prin ("June\n");
break;
case 7:
prin ("July\n");
break;
case 8:
prin ("August\n");
break;
case 9:
prin ("September\n");
break;
case 10:
prin ("October\n");
break;
case 11:
prin ("November\n");
break;
case 12:
prin ("December\n");
pg. 15
Programming with C Enrollment no.:202403103510377
break;
default: prin ("Invalid Month!\n");
}
return 0;
}
Output :
pg. 16
Programming with C Enrollment no.:202403103510377
Prac cal 9
AIM : Write a C program to take three integers from the user and
print the largest among them.
Code :
#include<stdio.h>
int main()
{
int num1, num2, num3;
prin ("Enter first integer: ");
scanf("%d", &num1);
prin ("Enter second integer: ");
scanf("%d", &num2);
prin ("Enter third integer: ");
scanf("%d", &num3);
if (num1 >= num2 && num1 >= num3)
{
prin ( “The largest number is : %d”,num1);
}
else if (num2 >= num1 && num2 >= num3)
{
prin (“The largest number: %d”,num2);
}
Else
{
pg. 17
Programming with C Enrollment no.:202403103510377
Output :
pg. 18
Programming with C Enrollment no.:202403103510377
Prac cal 10
AIM : Write a C program that display the grade of the student given
the marks.
#include<stdio.h>
int main()
{
float marks;
prin ("Enter the marks obtained (0-100): ");
scanf("%f", &marks);
if (marks >= 90 && marks <= 100)
{
prin ("Grade: A\n");
}
else if (marks >= 80 && marks <=90)
{
prin ("Grade: B\n");
}
else if (marks >= 70 && marks<=80)
{
prin ("Grade: C\n");
}
pg. 19
Programming with C Enrollment no.:202403103510377
pg. 20