Improved Solution to this problem would be able to find any first, second, third.. largest number...
here it is, in Java:
class Sam {
public static void main(String args[]) {
int[] nums = new int[] { 445, 43, 1045, 110, 209, 109, 33, 24, 1566 };
int cnt = 0;
int size = nums.length;
int temp;
int largest = 0;
int secondLargest = 0;
int thirdLargest = 0;
int fourthLargest = 0;
int fifthLargest = 0;
//the logic rests here
while (cnt < size) {
temp = nums[cnt];
if (temp > largest) {
secondLargest = largest;
largest = temp;
} else if (temp > secondLargest) {
thirdLargest = secondLargest;
secondLargest = temp;
} else if (temp > thirdLargest) {
fourthLargest = thirdLargest;
thirdLargest = temp;
} else if (temp > fourthLargest) {
fifthLargest = fourthLargest;
fourthLargest = temp;
} else if (temp > fifthLargest) {
fifthLargest = temp;
}
cnt++;
}
System.out.println("largest:" + largest);
System.out.println("secondLargest:" + secondLargest);
System.out.println("thirdLargest:" + thirdLargest);
System.out.println("fourthLargest:" + fourthLargest);
System.out.println("fifthLargest:" + fifthLargest);
}
}
// Regards,
// SwapniM
// mail me at: swap.masane@gmail.com
#include
using std::cin;
using std::cout;
using std::endl;
double maxFirst(const double data[], intindex);
double maxSecond(const double data[], intindex, double maxNumber1);
double sum(double max1, double max2);
int main()
{
double myArray[] = {
1.0,
4.6,
32.1,
9.7,
41.2,
41.3,
343,
23,
566.02,
345.8,
675.5,
654.4
};
int arraySize = (sizeof myArray)/(sizeof myArray[0]);
cout << "Your array is: ";
for (int k = 0; k < arraySize; k++)
{
cout << endl << myArray[k];
}
double max1 = maxFirst(myArray, arraySize);
double max2 = maxSecond(myArray, arraySize, max1);
cout << endl << "First biggest number is: " << max1;
cout << endl << "Second biggest number is: " << max2;
system("PAUSE");
return 0;
}
double maxFirst(const double data[], intindex)
{
double maxNumber1 = data[0];
for (int i = 0; i < index; i++)
{
if (maxNumber1 < data[i])
{
maxNumber1 = data[i];
}
}
return maxNumber1;
}
double maxSecond(const double data[], intindex, double maxNumber1)
{
double maxNumber2 = data[1];
for (int j = 0; j < index; j++)
{
if (data[j] == maxNumber1)
{
continue;
}
else if (maxNumber2 < data[j])
{
maxNumber2 = data[j];
}
}
return maxNumber2;
}
It is very easy. The program begins here..... /*Program to sum and print numbers without creating variables*/ #include<stdio.h> main() { clrscr(); printf("%d+%d=%d",5,2,5+2); getch(); } /*Program ends here*/ Now just by changing the numbers in the "printf" statement we can add, subtract, multiply and divide the numbers without using variables. Hence the problem is solved..........
sorting means arranging a list of numbers or elements in an order (ascending or descending).
Internal sorting refers to the process of sorting data that is entirely loaded into a computer's main memory (RAM). An example of internal sorting is using algorithms like QuickSort or MergeSort to arrange an array of integers stored in memory. Since all the data fits in RAM, these algorithms can operate efficiently without needing to access slower external storage. This is in contrast to external sorting, which involves sorting data that does not fit into memory and requires the use of disk-based storage.
Not possible. Let's not forget than in C the followings are all operators:+, -+=, -=++, --=&, *, []function-call
The required c program is given below /*Swapping(interchange) the two entered numbers*/ #include<stdio.h> main() { /*Without using third variable*/ int a,b,t; printf("Enter a:"); scanf("%d",&a); printf("Enter b:"); scanf("%d",&b); a=a+b; b=a-b; a=a-b; printf("\n After swapping without using third variable"); printf("\na=%d\nb=%d",a,b); }
Any number variable is extends the Number in java and it already implemented Comparable interface. So when you have a list of numbers, just use Arrays.sort().
plz as soon as possible give me the program for shorting an array in asscending order without using any sort function in c++
9875.
9,876,543,210 9876543210
It is 987654321.
9,876 since these are the largest single digit numbers that can be done without repeat.
Prime numbers are pure numbers, without units or dimensions.
Sorting that is accomplished entirely in memory without using disks or tapes for temporary files.
It is very easy. The program begins here..... /*Program to sum and print numbers without creating variables*/ #include<stdio.h> main() { clrscr(); printf("%d+%d=%d",5,2,5+2); getch(); } /*Program ends here*/ Now just by changing the numbers in the "printf" statement we can add, subtract, multiply and divide the numbers without using variables. Hence the problem is solved..........
93,876
93876
sorting means arranging a list of numbers or elements in an order (ascending or descending).