difficult codes

how to write te following codes in c++


1- Write the code for an algorithm to find the row with the largest variance in a matrix of any size.

2-Write the code for an algorithm to replace the most frequent element in the matrix with the geometric mean of its diagonal.

3- Find the largest palindrome made from the product of two 3-digit numbers.

4-What is the smallest number divisible by each of the numbers 1 to 20?
So are we supposed to solve your homework?

How about you give it a try, and we'll help you when you show us what you've done?
I'm just trying to learn c++

you don't have to solve it just help me to under stand it


this is my try for no. 4
#include <iostream>
int factorial ( );
using namespace std ;


int x, y ,z;
void main()
{

int r= factorial ();


for (x=1;x<= factorial ();x++)

{
for( x% r = 0 )

cout<<x<<endl;
}

system("pause");
}


int factorial ( )
{
for (z=1;z<20;z++)
{y= 20*(20-z);
}
return y;
}
If im not mistaken, these look like they're project euler questions. These questions are great for understanding and learning c++.
About your code:
1. what are the global variables supposed to be for? Get rid of them (by making them local).
2. your factorial function always returns 20. Even if it correctly calculated 20!, you'd still need at least a 64 bit integer (int64_t) to hold a number of that size.
3. You confused = with ==.
4. You don't exit the program when you find a number, so it takes ages to terminate.
5. The loop makes no sense. The only number that is evenly divisible by 20! is 20!.
6. There are numbers smaller than 20! that are divisible by 1...20.
7. main must return int.
Last edited on
Topic archived. No new replies allowed.