Sathish
Sathish
Date:
Dear Sir / Mam,
I would like to express my sincere gratitude for the effort you have put
forth. Your dedication and hard work have not gone unnoticed, and I truly
appreciate the time and energy you have invested. Thank you for your
support and commitment.
Program:
#include<stdio.h>
int main() {
float radius, area,circumference;
printf("\nEnter the radius of Circle : ");
scanf("%f", &radius);
area = 3.14 * radius * radius;
circumference=2*3.14*radius;
printf("\nArea of Circle : %.2f", area);
printf("\nCircumference of Circle : %.2f", circumference);
return 0;
}
Output:
Result:
Date :
Aim:
To write C program to calculate simple interest.
Algorithm:
Step 1: Start
Step 2: Declare Variables for Principal amount, Rate of interest, time
Step 3: Read Principal amount, Rate of interest, time
Step 4: Calculate interest amount using the expression amt=(p*r*t)/100
Step 5: Print amt
Step 6: Stop
Program:
#include<stdio.h>
int main()
{
int p,r,t,amt;
printf("Enter Principle amount, Rate of interest & time to find simple interest: \n");
scanf("%d%d%d",&p,&r,&t);
amt=(p*r*t)/100;
printf("Simple interest = %d",amt);
return 0;
}
Output:
Enter Principle amount, Rate of interest & time to find simple interest:20000
6
2
Simple interest = 2400
Result:
Thus, the C program to calculate Simple Interest was written executed andthe output
was verified successfully.
GE4110-Programming in C Laboratory 2024-2025
Algorithm:
Step 1: Start
Step 2: Read the values of x, y and z.
Step 3: If x is greater than y and x is greater than z then print x is greatest,otherwise go to step
3.
Step 4: If y is greater than z then print y is greatest, otherwise go to step 4.
Step 5: Display z is greatest.
Step 6: Stop
Program:
#include<stdio.h>
void main()
{
int x,y,z;
printf("Enter the values for x,y and z \n");scanf("%d%d%d",&x,&y,&z);
if((x>y)&& (x>z))
printf(" %d is greatest",x);
else if (y>z)
printf ("%d is greatest",y);
else
printf("%d is greatest",z);
}
Output:
Enter the values for x, y and z25
46
22
46 is greatest
Result:
Thus, the C program to find the largest of three numbers using if...else ifwas written
executed and the output was verified successfully.
GE4110-Programming in C Laboratory 2024-2025
Program:
#include <stdio.h>
int main()
{
int year;
printf("Enter a year: ");
scanf("%d",&year);
if(year%4 == 0)
{
if( year%100 == 0)
{
// year is divisible by 400, hence the year is a leap year
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);
return 0;
}
Output:
Enter a year: 1900 1900
is not a leap year.
Result:
Thus, the C program to find whether the given year is leap year or not waswritten
executed and the output was verified successfully.
GE4110-Programming in C Laboratory 2024-2025
Aim:
To check whether a given number is Armstrong number or not.
Algorithm:
Program:
#include <stdio.h>
int main()
{
int num, originalNum, rem, res = 0;
printf("Enter a integer: ");
scanf("%d", &originalNum);
num = originalNum;
while (num != 0)
{
rem = num%10; res+= rem*rem*rem; num /= 10;
}
if(res == originalNum)
printf("%d is an Armstrong number.",originalNum);
else
printf("%d is not an Armstrong number.",originalNum);
return 0;
}
Output:
Enter a integer:
153
153 is an Armstrong number
Result:
Thus, the C program check whether a given number is Armstrong number or not was
written executed and the output was verified successfully.
GE4110-Programming in C Laboratory 2024-2025
Aim:
To check whether a given number is Armstrong number or not.
Algorithm:
Step 1: Start
Step 2: Declare Variable sum, temp, num
Step 3: Read num from User
Step 4: Initialize Variable sum=0 and temp=num
Step 5: Repeat Until num>=0
rem=num %10
sum=sum * 10 +rem
num=num//10
Step 6: IF (sum==temp)
Print( " The given number is palindrome!!") ELSE
Print ("The given number is Not a palindrome!")
Step 7: Stop
Program:
#include <stdio.h>
int main() {
int n, reversed = 0, remainder, original;
printf("Enter an integer: ");
scanf("%d", &n);
original = n;
// reversed integer is stored in reversed variable
while (n != 0) {
remainder = n % 10;
n /= 10;
}
// palindrome if orignal and reversed are equal
if (original == reversed)
printf("%d is a palindrome.", original);
else
GE4110-Programming in C Laboratory 2024-2025
Output:
Enter an integer: 1001
1001 is a palindrome.
Result:
Thus, the C program check whether a given number is Palindrome or
not was written executed and the output was verified successfully.
GE4110-Programming in C Laboratory 2024-2025
Program:
#include<stdio.h>
#include<conio.h>
int main()
{
int n, x, y, k;
printf("Enter the number of rows to show number paatern: ");
scanf("%d",&n);
for(x = 1; x <= n; x++)
{
for(y = x; y <n; y++)
{
printf(" ");
}
for(k = 1; k < (x*2); k++)
{
printf("%d",k);
}
GE4110-Programming in C Laboratory 2024-2025
printf("\n");
}
for(x = 4; x >= 1; x--)
{
for(y = n; y > x; y--)
{
printf(" ");
}
for(k = 1; k < (x*2); k++)
{
printf("%d",k);
}
printf("\n");
}
return 0;
}
Output:
Result:
Thus, the C program to generate mentioned pattern was written executedand the output
was verified successfully.
GE4110-Programming in C Laboratory 2024-2025
Algorithm:
Step 1: Start
Step 2: Read Number of Column to print
Step 3: Use outer loop for maintaining Number of rows
Step 4: Use Inner Loop appropriately for required Coolum output
Step 5: Print required symbol link space or *
Step 6: Stop
Program:
#include <stdio.h>
int main(void) { int
n;
printf("Enter the number of columns"); scanf("%d",&n);
for(int i=0;i<n;i++)
{
for(int j=0;j<i;j++)
{
printf(" ");
}
for(int k=1;k<=n-i;k++)
{
printf("*");
}
printf("\n");
}
GE4110-Programming in C Laboratory 2024-2025
for(int i=1;i<n;i++)
{
for(int j=1;j<n-i;j++)
{
printf(" ");
}
for(int k=1;k<=i+1;k++)
{
printf("*");
}
printf("\n");
}
return 0;
}
Output:
Result:
Thus, the C program to generate mentioned pattern was written executedand the output
was verified successfully.
GE4110-Programming in C Laboratory 2024-2025
Algorithm:
Step 1: Start
Step 2: Read Number of lines to print
Step 3: Use outer loop for maintaining Number of rows
Step 4: Use Inner Loop appropriately for required Coolum output
Step 5: Print required letter
Step 6: Stop
Program:
#include<stdio.h>
void main()
{
int i,n,j;
printf("Enter the no of lines\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("%c",(char)(j+64));
}
for(j=i-1;j>=1;j--)
{
printf("%c",(char)(j+64));
}
printf("\n");
}
}
GE4110-Programming in C Laboratory 2024-2025
Output:
Result:
Thus, the C program to generate mentioned pattern was written executedand the output
was verified successfully.
GE4110-Programming in C Laboratory 2024-2025
Algorithm:
Step 1: Start
Step 2: Read Number of elements in the array as n
Step 3: Read n elements and store it in a array called a, using for loop
Step 4: Read element to be insert and position in num and pos
Step 5: From the end of the array, Using for loop start moving the elements one index
ahead till the required index reach.
Step 6: increase number of elements n by one
Step 7: Insert the element in the required index.
Step 8: Print all the elements.
Step 9: Stop
Program:
#include<stdio.h>
void main()
{
int i,n,pos,num, a[10];
printf("Enter the number of element :\n");
scanf("%d",&n);
printf("Enter element:\n");
for(i=0;i<n;i++)
{
printf("a[%d]=",i);
scanf("%d",&a[i]);
}
printf("\nEnter the pos where the no. is to be inserted :");
scanf("%d",&pos);
printf("\nEnter the the no. is to be inserted :");
scanf("%d",&num);
for(i=n-1;i>=pos;i--)
a[i+1]=a[i];
n=n+1;
a[pos]=num;
printf("\n Display array after insertion:\n");
for(i=0;i<n;i++)
{
printf("a[%d]=%d\n",i,a[i]);
}
}
GE4110-Programming in C Laboratory 2024-2025
Output:
Result:
Thus, the C program to Insert an Element in an Array was written executedand the output
was verified successfully.
GE4110-Programming in C Laboratory 2024-2025
Step 1: Start
Step 2: Declare variables m,n,p,q for storing number of rows and columns of two matrix.
Step 3: Read Number of rows and columns of first matrix as m,n
Step 4: Read Number of rows and columns of second matrix as p,q
Step 5: Check whether m==p and n==q if so go to step 6 else print matrix addition not
possible and stop the program.
Step 6: Using two nested for loop read elements of first matrix
Step 7: Using two nested for loop read elements of second matrix
Step 8: Using two nested for loop add first matrix element and second matrix element
and store it in third matrix.
Step 9: Using two nested for loop print third matrix.
Step 10: Stop.
Program:
#include<stdio.h>
#include <stdlib.h>
void main()
{
int i,j,m,n,p,q;
int a[10][10], b[10][10], c[10][10];
printf("\nEnter no of rows and column of matrixA:");
scanf("%d%d",&m,&n);
printf("\nEnter no of rows and column of matrixB:");
scanf("%d%d",&p,&q);
if(m!=p && n!=q)
{
printf("\n Matrix cannot be added.");
exit(0);
}
printf("\n Matrix can be added");
printf("\n Enter elements of matrix A:");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("\n Enter elements of matrix B:");
GE4110-Programming in C Laboratory 2024-2025
for(i=0;i<p;i++)
for(j=0;j<q;j++)
scanf("%d",&b[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
c[i][j]=a[i][j]+b[i][j];
printf("\n Display matrix A:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
printf("\n Display matrix B:\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
printf("%d\t",b[i][j]);
printf("\n");
}
printf("\n Display matrix C:\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
printf("%d\t",c[i][j]);
printf("\n");
}
}
Output:
Display matrix A:
1 2
3 4
Display matrix B:
5 6
7 8
Display matrix C:
6 8
10 12
Result:
Thus, the C program to Add two Matrix was written executed and theoutput was
verified successfully.
GE4110-Programming in C Laboratory 2024-2025
Step 1: Start
Step 2: Declare variables m,n,p,q for storing number of rows and columns of two matrix.
Step 3: Read Number of rows and columns of first matrix as m,n
Step 4: Read Number of rows and columns of second matrix as p,q
Step 5: Check whether n==p if so go to step 6 else print matrix multiplication notpossible and stop
the program.
Step 6: Using two nested for loop read elements of first matrix
Step 7: Using two nested for loop read elements of second matrix
Step 8: Using three nested for loop multiply first matrix element and second matrix element
and store it in third matrix.
Step 9: Using two nested for loop print third matrix.
Step 10: Stop.
Program:
#include<stdio.h>
#include <stdlib.h>
void main()
{
int i,j,m,n,p,q,k;
int a[10][10], b[10][10], c[10][10];
printf("\nEnter no of rows and column of matrixA:");
scanf("%d%d",&m,&n);
printf("\nEnter no of rows and column of matrixB:");scanf("%d%d",&p,&q);
printf("\n Enter elements of matrix A:\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("\n Enter elements of matrix B:\n");
for(i=0;i<p;i++)
for(j=0;j<q;j++)
scanf("%d",&b[i][j]);
if(n==p)
{
for(i=0;i<m;i++)
for(j=0;j<q;j++)
GE4110-Programming in C Laboratory 2024-2025
{
c[i][j]=0;
for(k=0;k<n;k++)
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
}
else
{
printf("\n Matrix cannot be multiplied");
exit(1);
}
printf("\n Display matrix A:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
printf("\n Display matrix B:\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
printf("%d\t",b[i][j]);
printf("\n");
}
printf("\n Display Product:\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
printf("%d\t",c[i][j]);
printf("\n");
}
}
Output:
4
5
6
Display matrix A:
1 2 3
4 5 6
Display matrix B:
7 8
9 10
11 12
Display Product:
58 64
139 154
Result:
Thus, the C program to Multiply two Matrix was written executed and theoutput was
verified s
GE4110-Programming in C Laboratory 2024-2025
Program:
#include <stdio.h>
void swap(int , int);
int main()
{
int a,b;
printf("Enter Two Values:\n"); scanf("%d%d",&a,&b);
printf("Before swapping the values in main a = %d, b = %d\n",a,b);
swap(a,b);
printf("After swapping values in main a = %d, b = %d\n",a,b);
}
void swap (int a, int b)
{
int temp;
temp = a;
a=b;
b=temp;
printf("After swapping values in function a = %d, b = %d\n",a,b);
}
Output:
Enter Two Values:
10
20
Before swapping the values in main a = 10, b = 20After
swapping values in function a = 20, b = 10 After swapping
values in main a = 10, b = 20
Result:
Thus, the C program to Swap Two Numbers using call by Value Method
was written executed and the output was verified successfully.
GE4110-Programming in C Laboratory 2024-2025
Program:
Output:
Enter Two Values:
10
20
Before swapping the values in main a = 10, b = 20After
swapping values in function a = 20, b = 10 After swapping
values in main a = 20, b = 10
Result:
Thus, the C program to Swap Two Numbers using call by Reference
Method was written executed and the output was verified successfully.
GE4110-Programming in C Laboratory 2024-2025
Aim:
Step 1: Start
Step 2: Define a function named mySort(), It will take a integer array and number of values in a
array as input
Step 3: Inside mySort() function Using two nested for loops check elements and swap
elements to sort array.
Step 4: Print the sorted array
Step 5: In main function declare a array
Step 6: Read total number of elements in the array as n
Step 7: Using for loop read n elements one by one
Step 8: call mySort() function to sort array
Step 9: Stop
Program:
#include<stdio.h>
void mySort(int[],int);
void main ()
{
int arr[10],n,i;
printf("Enter Number of elements in the array\n"); scanf("%d",&n);
printf("Enter Elements one by one\n");
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
mySort(arr,n);
}
void mySort(int a[],int n)
{
int i, j,temp;
for(i = 0; i<n; i++)
{
for(j = i+1; j<n; j++)
{
if(a[j] < a[i])
{
temp = a[i];
a[i] = a[j];
GE4110-Programming in C Laboratory 2024-2025
a[j] = temp;
}
}
}
printf("Printing Sorted Element List ...\n");
for(i = 0; i<n; i++)
{
printf("%d\n",a[i]);
}
}
Output:
Result:
Thus, the C program to Sort an Array of Elements using Functions waswritten
executed and the output was verified successfully.
GE4110-Programming in C Laboratory 2024-2025
Aim:
Step 1: Start
Step 2: Read N value from user
Step 3: Call recursive function factorial(), by passing N and store the return value to fact
Step 4: In factorial() function if N==0 then return 1 else return N*factorial(N-1)
Step 5: Print fact value
Step 6: Stop
Program:
#include<stdio.h>
long factorial(int n)
{
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}
void main()
{
int number;
long fact;
printf("Enter a number: ");
scanf("%d", &number);
fact = factorial(number);
printf("Factorial of %d is %ld\n", number, fact);
}
Output:
Enter a number: 6
Factorial of 6 is 720
Result:
Thus, the C program to find Factorial of a Number using RecursiveFunctions was written
executed and the output was verified successfully.
GE4110-Programming in C Laboratory 2024-2025
Aim:
Step 1: Start
Step 2: Read Number of terms from user as n
Step 3: Using a for loop call recursive function fibonacci(), n times and each time print the
return value
Step 4: In fibonacci() function if n==0 or n==1 then return n else return fibonacci(n-1)
+ fibonacci(n-2)
Step 5: Stop
Program:
#include<stdio.h>
int fibonacci(int);
int main()
{
int n, m= 0, i;
printf("Enter Total terms:\n");
scanf("%d", &n);
printf("Fibonacci series terms are:\n");
for(i = 1; i <= n; i++)
{
printf("%d\n", fibonacci(m));
m++;
}
return 0;
}
int fibonacci(int n)
{
if(n == 0 || n == 1)
return n;
else
return(fibonacci(n-1) + fibonacci(n-2));
}
GE4110-Programming in C Laboratory 2024-2025
Output:
Result:
Thus, the C program to generate Fibonacci Series using Recursive Functionswas written
executed and the output was verified successfully.
GE4110-Programming in C Laboratory 2024-2025
Aim:
Step 1: Start
Step 2: Read Number of disks from user as num
Step 3: Call recursive function towers(),by passing number of disks num and nameof the
source, destination, auxiliary towers
Step 4: In towers() function if n==1 then print move disk 1 from source to destination and go to
step 8 else go to step 5
Step 5: Call recursive function towers() with arguments num-1, source, auxiliary, destination
Step 6: Print Move num from source to destination
Step 7: Call recursive function towers() with arguments num-1, auxiliary,destination, source
Step 8: Stop
Program:
#include <stdio.h>
void towers(int, char, char, char);
int main()
{
int num;
printf("Enter the number of disks : ");
scanf("%d", &num);
printf("The sequence of moves involved in the Tower of Hanoi are :\n"); towers(num,
'A', 'C', 'B');
return 0;
}
void towers(int num, char frompeg, char topeg, char auxpeg)
{
if (num == 1)
{
printf("\n Move disk 1 from peg %c to peg %c", frompeg, topeg);
return;
}
towers(num - 1, frompeg, auxpeg, topeg);
printf("\n Move disk %d from peg %c to peg %c", num, frompeg, topeg);
towers(num - 1, auxpeg, topeg, frompeg);
}
GE4110-Programming in C Laboratory 2024-2025
Output:
Result:
Thus, the C program to solve Tower of Hanoi using Recursive Functionswas written
executed and the output was verified successfully.