Programming Laboratory (BITAIC191)
Lab Sessional Report Submitted to
Maulana Abul Kalam Azad University of Technology, West Bengal
for
[Link].
in
Information Technology (Artificial Intelligence)
Submitted by
Aruk Bandyopadhyay
Roll - 30054622005
Course Faculty
Dr. Pabitra Pal
Department of Information Technology
Maulana Abul Kalam Azad University of Technology, West Bengal
Simhat, Haringhata, Nadia
Pin-741249
Feb, 2023
Table of Contents
SL Page Date Faculty Signature
Name of the Programs
no
No
1. C Program to calculate area and 1 29/11/2022
Perimeter of a Circle.
2. C program to print area and 2 29/11/2022
perimeter of a Triangle.
3. C Program to convert days into 3 29/11/2022
years months and days.
4. C Program to check whether an 4 09/12/2022
integer is odd or even.
5. C Program to find the largest number 5 09/12/2022
among three numbers.
6. C Program to Find the Largest 6 09/12/2022
Number using Conditional Operator.
7. C Program to find the Largest among 7 09/12/2022
Three Variables using Nested if.
8. C program to check leap year using 8 09/12/2022
conditional Operator.
9. C program to check alphabets using 9 09/12/2022
conditional operator.
10. C program to check number is 10 09/12/2022
positive, negative, or zero.
11. C program to check whether entered 11 09/12/2022
character is vowel or consonant.
12. C program to check whether a 12 09/12/2022
character is an alphabet, digit,
or special character.
13. C program to print the day name of 13-14 09/12/2022
the week.
14. C program to check uppercase or 15 09/12/2022
lowercase alphabets.
15. C program to accept two integers and 16 09/12/2022
check whether they are equal or not.
16. program to determine whether a 17 09/12/2022
candidate’s age is eligible for casting
a vote or not.
17. C program to calculate the total marks, 18 09/12/2022
percentage, and division of students.
18. C program to enter the month number 19 09/12/2022
and print the number of days in month.
19. C program to check whether a triangle 20 09/12/2022
can be formed by the given value for
the angles.
20. C program to find the sum of first 10 21 01/01/2023
natural numbers.
21. Write a program in C to read 10 22 01/01/2023
numbers from keyboard and find their
sum and average.
22. Write a program in C to display the 23 01/01/2023
pattern like right angle triangle with a
number.
23. Write a program in C to display the 24 01/01/2023
pattern like right angle triangle using
an asterisk.
24. Write a program in C to display the n 25 01/01/2023
terms of odd natural number and their
sum .
25. Write a program in C to display the n 26 01/01/2023
terms of natural number and their
sum .
26. Write a program in C to display the 27 01/01/2023
multiplication table of a given integer.
Page 1
Program No: 1
Program Name: C Program to calculate area and Perimeter of a Circle.
Source Code:
//C Program to calculate area and Perimeter of a Circle.
#include <stdio.h>
void main()
{
float radius, perimeter, area;
printf("Enter radius of the Circle: ");
scanf("%f", & radius);
perimeter = 2 * 3.14 * radius;
printf("Perimeter of the circle: %0.4f\n", perimeter);
area = 3.14 * radius * radius;
printf("Area of circle: %0.4f\n", area);
}
Output :
Page 2
Program No: 2
Program Name: C program to print area and perimeter of a Triangle.
Source Code:
//C program to print area and perimeter of a Triangle
#include <stdio.h>
void main()
{
int b, h, area, x,y,z, perimeter;
printf("Enter base and hight of a triangle\n");
scanf("%d %d", &b,&h);
area = (b*h)/2;
printf("Area of the triangle = %d\n", area);
printf("Enter sides of a triangle\n");
scanf("%d %d %d", &x, &y, &z);
perimeter= x+y+z;
printf("Perimeter of a triangle : %d", perimeter);
}
Output :
Page 3
Program No: 3
Program Name: C Program to convert days into years months and days
Source Code:
//C Program to convert days into years months and days
#include<stdio.h>
int main()
{
int number_of_days, years, months, days;
printf("Enter number of days: ");
scanf("%d", &number_of_days);
years = number_of_days / 365;
months = (number_of_days - years *365) / 30;
days = (number_of_days - years * 365 - months*30);
printf("%d Days = %d Years, %d Months and %d Days",number_of_days, years, months, days);
return 0;
}
Output :
Page 4
Program No: 4
Program Name: C Program to check whether an integer entered by the user is
odd or even
Source Code:
// C Program to check whether an integer entered by the user is odd or even
#include <stdio.h>
int main()
{
int num;
// Taking input from the user
printf("Enter an integer: ");
scanf("%d", &num);
// Checking if num is perfectly divisible by 2
if(num % 2 == 0)
printf("%d is even.", num);
else
printf("%d is odd.", num);
return 0;
}
Output :
Page 5
Program No: 5
Program Name: C Program to find the largest number among three numbers
Source Code:
// C Program to find the largest number among three numbers
#include <stdio.h>
int main()
{
int Num1, Num2, Num3;
// Taking input from the user
printf("Enter the three numbers : ");
scanf("%d %d %d", &Num1, &Num2, &Num3);
//Checking which number is largest
if (Num1 >= Num2 && Num1 >= Num2)
printf("%d is the largest number.", Num1);
if (Num2 >= Num1 && Num2 >= Num3)
printf("%d is the largest number.", Num2);
if (Num3 >= Num1 && Num3 >= Num2)
printf("%d is the largest number.", Num3);
return 0;
}
Output :
Page 6
Program No: 6
Program Name: C Program to Find the Largest Number using Conditional
Operator
Source Code:
// C Program to Find the Largest Number using Conditional Operator
#include<stdio.h>
int main()
{
int num1,num2,max;
// Taking input from the user
printf("Enter two numbers : ");
scanf("%d%d", &num1, &num2);
// Using the conditional Operator to calculate the Maximum
max = num1>num2 ? num1 : num2;
printf("Larger of %d and %d is %d \n", num1, num2, max);
return 0;
}
Output :
Page 7
Program No: 7
Program Name: C Program to find the Largest among Three Variables using
Nested if.
Source Code:
//C Program to find the Largest among Three Variables using Nested if
#include <stdio.h>
int main() {
int n1, n2, n3;
// Taking input from user
printf("Enter three numbers: ");
scanf("%d %d %d", &n1, &n2, &n3);
// outer if statement
if (n1 >= n2) {
// inner if...else
if (n1 >= n3)
printf("%d is the largest number.", n1);
else
printf("%d is the largest number.", n3);
}
// outer else statement
else {
// inner if...else
if (n2 >= n3)
printf("%d is the largest number.", n2);
else
printf("%d is the largest number.", n3);
}
return 0;
}
Output :
Page 8
Program No: 8
Program Name: C program to check leap year using conditional Operator
Source Code:
//C program to check leap year using conditional Operator
#include <stdio.h>
int main()
{
int year;
// Taking Input year from user
printf("Enter any year: ");
scanf("%d", &year);
// Checking Leap Year or not
(year%4==0 && year%100!=0) ? printf("LEAP YEAR") :
(year%400 ==0 ) ? printf("LEAP YEAR") : printf("COMMON YEAR");
return 0;
}
Output :
Page 9
Program No: 9
Program Name: C program to check alphabets using conditional operator
Source Code:
// C program to check alphabets using conditional operator
#include <stdio.h>
int main()
{
char ch;
//Taking Input from User
printf("Enter any character: ");
scanf("%c", &ch);
//Checking alphabet or not
(ch>='a' && ch<='z') || (ch>='A' && ch<='Z')
? printf("It is an ALPHABET")
: printf("It is not an ALPHABET");
return 0;
}
Output :
Page 10
Program No: 10
Program Name: C program to check number is positive, negative, or zero
Source Code:
//C program to check number is positive, negative, or zero
#include <stdio.h>
int main()
{
int Num;
//Taking Input
printf("Enter the number : ");
scanf("%d", &Num);
//Checking if Positive or Negative or Zero
if (Num > 0)
printf("%d is positive.", Num);
else if (Num < 0)
printf("%d is negative.", Num);
else if (Num == 0)
printf("%d is zero.", Num);
return 0;
}
Output :
Page 11
Program No: 11
Program Name: C program to check whether entered character is vowel or
consonant.
Source Code:
//C program to check whether entered character is vowel or consonant
#include <stdio.h>
int main() {
char ch;
//Inputting Character
printf("Enter a character: ");
scanf("%c", &ch);
//Checking if Vowel or Consonant
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||
ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
{
printf("\n %c is a VOWEL.", ch);
}
else
{
printf("\n %c is a CONSONANT.", ch);
}
}
else
{
printf("\n %c is not an alphabet.", ch);
}
return 0;
}
Output :
Page 12
Program No: 12
Program Name: C program to check whether a character is an alphabet, digit, or
special character.
Source Code:
//C program to check whether a character is an alphabet, digit, or special character
#include <stdio.h>
int main()
{
char ch;
//Inputting character
printf("Enter any character: ");
scanf("%c", &ch);
// Checking if Alphabet or Digit
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf("'%c' is alphabet.", ch);
}
else if(ch >= '0' && ch <= '9')
{
printf("'%c' is digit.", ch);
}
else
{
printf("'%c' is special character.", ch);
}
return 0;
}
Output :
Page 13
Program No: 13
Program Name: C program to print the day name of the week
Source Code:
//C program to print the day name of the week
#include <stdio.h>
int main()
{
int weekday;
printf(" Please Enter the Day Number 1 to 7 : ");
scanf("%d", &weekday);
if (weekday == 1)
{
printf("\n Day no %d is Monday",weekday);
}
if ( weekday == 2 )
{
printf("\n Day no %d is Tuesday",weekday);
}
if ( weekday == 3 )
{
printf("\n Day no %d is Wednesday",weekday);
}
if ( weekday == 4 )
{
printf("\n Day no %d is Thursday",weekday);
}
if ( weekday == 5 )
{
printf("\n Day no %d is Friday",weekday);
}
if ( weekday == 6 )
{
printf("\n Day no %d is Saturday",weekday);
}
if ( weekday == 7 )
{
printf("\n Day no %d is Sunday",weekday);
}
else
printf("\n Please enter Valid Number between 1 to 7");
return 0;
}
Page 14
Output :
Page 15
Program No: 14
Program Name: C program to check uppercase or lowercase alphabets.
Source Code:
// C program to check uppercase or lowercase alphabets
#include<stdio.h>
int main()
{
char c;
//Inputting Character
printf ("Enter a character n :");
scanf ("%c", &c);
//Checking Uppercase or Lowercase
if (c>='A' && c<='Z')
{
printf ("It is uppercase Alphabet");
}
else if (c>='a' && c<='z')
{
printf ("It is lowercase Alphabet");
}
else
{
printf ("It is not an Alphabet");
}
return 0;
}
Output :
Page 16
Program No: 15
Program Name: C program to accept two integers and check whether they are
equal or not.
Source Code:
//C program to accept two integers and check whether they are equal or not
#include <stdio.h>
int main()
{
int n1, n2;
printf("Enter the values for num1 and num2\n");
scanf("%d %d", &n1, &n2);
if (n1 == n2)
printf("num1 and num2 are equal\n");
else
printf("num1 and num2 are not equal\n");
return 0;
}
Output :
Page 17
Program No: 16
Program Name: C program to determine whether a candidate’s age is eligible for
casting a vote or not.
Source Code:
// program to determine whether a candidate’s age is eligible for casting a vote or not
#include <stdio.h>
int main()
{
int vote_age;
printf("Input the age of the candidate : ");
scanf("%d",&vote_age);
if (vote_age<18)
{
printf("Sorry, You are not eligible to caste your vote.\n");
}
else
{
printf("Congratulations! You are eligible to cast your vote.\n");
}
return 0;
}
Output :
Page 18
Program No: 17
Program Name: C program to calculate the total marks, percentage, and division
of students.
Source Code:
//C program to calculate the total marks, percentage, and division of students.
#include <stdio.h>
int main()
{
int sub1, sub2, sub3, sub4, sub5, total;
float per;
printf("Enter marks of 5 subjects:");
scanf("%d%d%d%d%d",&sub1,&sub2, &sub3, &sub4, &sub5);
total = sub1+sub2+sub3+sub4+sub5;
per = total/5;
printf("\n Total Marks: %d",total);
printf("\n Total Percentage: %.2f ", per);
if(per>=80)
printf("\n Distinction");
else if(per>=60)
printf("\n First Division");
else if(per>=50)
printf("\n Seocnd Division");
else if(per>=40)
printf("\n Third Division");
else
printf("\n Fail");
return 0;
}
Output :
Page 19
Program No: 18
Program Name: C program to enter the month number and print the number of
days in a month
Source Code:
//C program to enter the month number and print the number of days in a month
#include <stdio.h>
int main()
{
int month;
printf("Enter month number (1-12): ");
scanf("%d", &month);
if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
{
printf("31 days");
}
else if(month==4 || month==6 || month==9 || month==11)
{
printf("30 days");
}
else if(month==2)
{
printf("28 or 29 days");
}
else
{
printf("Invalid input! Please enter month number between (1-12).");
}
return 0;
}
Output :
Page 20
Program No: 19
Program Name: C program to check whether a triangle can be formed by
the given value for the angles
Source Code:
//C program to check whether a triangle can be formed by the given value for the angles
#include <stdio.h>
int main()
{
int angle1, angle2, angle3, sum;
printf("Enter three angles of triangle: \n");
scanf("%d%d%d", &angle1, &angle2, &angle3);
sum = angle1 + angle2 + angle3;
if(sum == 180 && angle1 > 0 && angle2 > 0 && angle3 > 0)
{
printf("Triangle is valid.");
}
else
{
printf("Triangle is not valid.");
}
return 0;
}
Output :
Page 21
Program No: 20
Program Name: C program to find the sum of first 10 natural numbers.
Source Code:
//C program to find the sum of first 10 natural numbers.
#include <stdio.h>
int main()
{
int i, sum = 0;
printf("The first 10 natural numbers are :");
for (i = 1; i <= 10; ++i)
{
printf("%d ", i);
sum = sum + i;
}
printf("\nThe Sum is : %d", sum);
return 0;
}
Output :
Page 22
Program No: 21
Program Name: C program to read 10 numbers from keyboard and find
their sum and average.
Source Code:
//C program to read 10 numbers from keyboard and find their sum and average.
#include <stdio.h>
int main()
{
int i,n,sum=0;
float avg;
printf("Input the 10 numbers : \n");
for (i=1;i<=10;i++)
{
printf("Number-%d :",i);
scanf("%d",&n);
sum +=n;
}
avg=sum/10.0;
printf("The sum of 10 no is : %d\nThe Average is : %f\n",sum,avg);
return 0;
}
Output :
Page 23
Program No: 22
Program Name: C program to display the pattern like right angle triangle
with a number.
Source Code:
//C program to display the pattern like right angle triangle with a number.
#include <stdio.h>
int main()
{
int i,j,rows;
printf("Input number of rows : ");
scanf("%d",&rows);
for(i=1;i<=rows;i++)
{
for(j=1;j<=i;j++)
printf("%d", j);
printf("\n");
}
return 0;
}
Output :
Page 24
Program No: 23
Program Name: C program to display the pattern like right angle triangle
with an asterisk.
Source Code:
//C Program to display the pattern like right angle triangle using an asterisk.
#include <stdio.h>
int main()
{
int i,j,rows;
printf("Input number of rows : ");
scanf("%d",&rows);
for(i=1;i<=rows;i++)
{
for(j=1;j<=i;j++)
printf("*");
printf("\n");
}
return 0;
}
Output :
Page 25
Program No: 24
Program Name: C program to display the n terms of odd natural number
and their sum .
Source Code:
//C program to display the n terms of odd natural number and their sum .
#include <stdio.h>
int main()
{
int i,n,sum=0;
printf("Input number of terms : ");
scanf("%d",&n);
printf("\nThe odd numbers are :");
for(i=1;i<=n;i++)
{
printf("%d ",2*i-1);
sum+=2*i-1;
}
printf("\nThe Sum of odd Natural Number upto %d terms : %d ",n,sum);
return 0;
}
Output :
Page 26
Program No: 25
Program Name: C program to display the n terms of natural number and
their sum .
Source Code:
//C program to display n terms of natural number and their sum.
#include <stdio.h>
int main()
{
int n , i, sum = 0;
printf("Input your choice:");
scanf("%d", &n);
printf("The first %d natural number is :", n);
for (i = 1; i <= n; ++i)
{
printf("%d ", i);
sum = sum + i;
}
printf("\nThe Sum of Natural Numbers upto %d terms : %d",n , sum);
return 0;
}
Output :
Page 27
Program No: 26
Program Name: C program to display the multiplication table of a given
integer.
Source Code:
//C program to display the multiplication table of a given integer.
#include <stdio.h>
int main()
{
int n, i;
printf("Enter an integer: ");
scanf("%d", &n);
for (i = 1; i <= 10; ++i)
{
printf("%d * %d = %d \n", n, i, n * i);
}
return 0;
}
Output :