Hamda ushbu n ta complex sonlarni jadval ko‘rinishida har bir satrini o‘sish


Download 8.72 Kb.
Sana17.06.2023
Hajmi8.72 Kb.
#1530340
Bog'liq
4-Amaliy


N ta complex son berilgan. Ularning real qismlari tasodifiy takrorlanmas
sonlar bilan, mavhum qismlari 1 dan N gacha manfiy sonlar bilan to‘ldirilsin
hamda ushbu N ta complex sonlarni jadval ko‘rinishida har bir satrini o‘sish
tartibida saralab ekranga chiqarilsin.

#include


#include
#include
#include

using namespace std;

int main()
{
int n;
cout << "Enter the number of complex numbers: ";
cin >> n;

srand(time(0));

double real, imaginary;
int negativeCount = n/2;
int positiveCount = n - negativeCount;

cout << "\nList of Complex Numbers:\n";

for(int i=1; i<=n; i++)
{
real = rand() % 10;
imaginary = rand() % 10;

if(negativeCount > 0)


{
imaginary *= -1;
negativeCount--;
}
else
{
imaginary *= 1;
positiveCount--;
}

cout << i << ". " << real << " + " << imaginary << "i" << endl;


}

return 0;


}

Download 8.72 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling