Q. If sum of two integer is 14 and if one of them is 8 then find other integer. Ans: Well, this is very simple. Simply, one integer is 8 and sum of two integers is 14. So, we need to subtract the number 8 from their sum of 14 to get the second number. So, the second number is: 14 - 8 = 6 C-Program of this task Code---> #include<stdio.h> int main () { int num1 = 8 , num2 , sum = 14 ; num2 = sum - num1 ; printf ( "The second number is: %d" , num2 ); return 0 ; }
In this C program we will perform Radix Sort. The Number of elements and the highest length of the number will be taken from the user.
input:
- The number of the elements
- The highest length of the number
- The elements or values or data
output:
The sorted elements will displayed on the screen after Radix sorting.
CODE---->
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int a[20][10],b[20],top[10],len,i,j,k,n,p,pos;
printf("Enter the number of elements: ");
scanf("%d",&n);
printf("\nEnter the highest length of the number: ");
scanf("%d",&len);
printf("\nEnter the elements: ");
for(i=0;i<=n-1;i++)
scanf("%d",&b[i]);
//Radix Sort Technique//
for(i=0;i<len;i++)
{
for(j=0;j<10;j++)
top[j]=-1;
for(j=0;j<n;j++)
{
pos=(int)(b[j]/pow(10,i))%10;
a[pos][++top[pos]]=b[j];
}
for(j=0,p=-1;j<10;j++)
{
for(k=0;k<=top[j];k++)
b[++p]=a[j][k];
}
}
printf("\n After sorting the elements...\n");
for(i=0;i<=n-1;i++)
printf(" %d ",b[i]);
return 0;
}
Download the C-Program file of this Program.
RESULT :
Enter the number of elements: 10 Enter the highest length of the number: 100 Enter the elements: 100 90 8 56 63 81 90 99 0 34 After sorting the elements... 0 8 34 56 63 81 90 90 99 100 -------------------------------- Process exited after 82.78 seconds with return value 0 Press any key to continue . . .
Images for better understanding :
Comments
Post a Comment