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;
}
Because you can't use built in PHP functions to sort the array, you need to loop through the array and find the second largest number.
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).
Not possible. Let's not forget than in C the followings are all operators:+, -+=, -=++, --=&, *, []function-call
Can be. (Meaning: you can merge sorted files without loading them entirely into the main memory.)
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++
9,876,543,210 9876543210
9875.
It is 987654321.
9,876 since these are the largest single digit numbers that can be done without repeat.
Sorting that is accomplished entirely in memory without using disks or tapes for temporary files.
Prime numbers are pure numbers, without units or dimensions.
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
sorting means arranging a list of numbers or elements in an order (ascending or descending).
93876