Lab Programs
Lab Programs
Lab Programs
Aim
To write a C Program to solve towers of Hanoi using recursion.
Algorithm
Step1: Start
Sep4: Check the condition for each transfer of discs using recursion.
Step6: Stop
#include <stdio.h>
#include <conio.h>
void towerofhanoi(int n, char from, char to, char aux)
{
if (n == 1)
{
printf("\n Move disk 1 from pole %c to pole %c", from, to);
return;
}
int main()
{
int n;
printf("Enter the number of disks : ");
scanf("%d",&n);
towerofhanoi(n, 'A', 'C', 'B');
getch();
}
Output
Algorithm
Step 1:Start
Step 3:Read the Input for number of elements and each element.
Step 4:Develop a function to sort the array by passing reference
Step 5:Compare the elements in each pass till all the elements are sorted.
Step 6:Display the output of the sorted elements .
Step 7:Stop
Program
#include <stdio.h>
#include <conio.h>
void main()
{
int n,a[100],i;
void sortarray(int*,int);
printf("\nEnter the Number of Elements in an array : ");
scanf("%d",&n);
printf("\nEnter the Array elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sortarray(a,n);
printf("\nAfter Sorting....\n");
for(i=0;i<n;i++) printf("%d\n",a[i]);
getch();
}
for(i=0;i<num;i++)
for(j=i+1;j<num;j++)
if(arr[i] > arr[j])
{
temp=arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
Output
11
21
33
45
67
3. INTERNAL MARKS OF STUDENTS
Aim
To write a C Program to Compute internal marks of students for five different subjects
using structures and functions.
Algorithm
Step 1:Start
Program
#include<stdio.h>
#include<conio.h>
struct stud
{
char name[20];
}students[10];
void calcinternal(int);
int main()
{
int a,b,j,n;
clrscr();
printf("How many students : \n");
scanf("%d",&n);
for(a=0;a<n;++a)
{
printf("\n\nEnter the details of %d student : ", a+1);
scanf("%s", students[a].name);
for(a=0;a<n;++a)
printf("\n\n\t\t\t\tMark Sheet\n");
printf("\nName of Student : %s", students[a].name);
return(0);
}
void calcinternal(int n)
{
int a,b,j,total;
for(a=1;a<=n;++a)
for(b=0;b<5;b++)
total=0;
for(j=0;j<=2;++j)
{
total += students[a].marks[b,j];
}
students[a].i[b]=total/3;
}
}
}
Output
Mark Sheet
Name of Student : siva Roll No : 10466
------------------------------------------------------------------------
subject 1 internal : 59
subject 2 internal : 78
subject 3 internal : 74
subject 4 internal : 40
subject 5 internal : 60
------------------------------------------------------------------------