Can someone please explain me how can I create different patterns with numbers in c++ using for loop. Because I cant understand the logic. Thank you. For example 55555 54444 54333 54322 54321 or
12345 23455 34555 45555 55555 this is the code of an example
#include <iostream>
using namespace std;
int main()
{
int i, j, n;
cout << "\n Jepe n (numrin e reshtave dhe kolonave)";
cin >> n;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
if (i % 2 != 0)
cout << "1" << " ";
else cout << "0" << " ";
cout << endl;
}
}
Aucun commentaire:
Enregistrer un commentaire