Professional Documents
Culture Documents
Algorithm:
isprime(num)
void main()
{
int res,num;
clrscr();
printf("Enter the number:");
scanf("%d",&num);
res=isPrime(num);
if(res==0)
printf("%d is not a Prime Number\n",num);
else
printf("%d is a Prime Number\n",num);
}
Algorithm:
Step 1: [Start]
Begin
Step 2: [Input the number of elements in the array]
Read n
Step 3: [Input the n integer numbers]
For i = 1through n in steps of 1
Read a[ i ]
End for
Step 4: [Display the original array]
For i = 0 through n-1 in steps of 1
Print a[ i]
End for
Step 5: [Repeat step 5 for i varies from 0 thru n-1]
For j = 0 through n-1 in steps of 1
For i = 0 through n-j-1 in steps of 1
IF ( a[i] > a[i + 1] ) then
temp= a[i]
a[i] = a[i + 1]
a[i+1] = temp
End if
End for
End for
Step 6: [Output the sorted array]
For i = 0 thru n-1 in steps of 1
Print a[i]
End for
Flowchart:
Program:
#include<stdio.h>
void main()
{
int a[30],i,j,n,temp;
printf("Enter number of elements : ");
scanf("%d",&n);
printf("Enter %d elements : ",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Before sorting the elements :");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
for(j=0;j<n-1;j++)
{
for(i=0;i<n-j-1;i++)
{
if(a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
}
printf("\nAfter sorting the elements :");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
}