C++ dasturlash tilida massivlarni qo'shish
Bugun siz bilan C++ dasturlash tilida ikkita massivni qo'shishni sodda usulini o'rganib chiqamiz.
Quyida dastur kodi :
#include<iostream>
using namespace std;
int main()
{
int m, n, c, d,
first[10][10], second[10][10], sum[10][10];
cout <<
"Massiv uchun satr va ustunlarni sonini kiriting : ";
cin >> m
>> n;
cout <<
"Birinchi massiv elementlarini kiriting : \n";
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d
< n ; d++ )
cin >>
first[c][d];
cout <<
"Ikkinchi massiv elementlarini kiritng : \n";
for ( c = 0 ; c
< m ;c++ )
for ( d = 0 ; d
< n ; d++ )
cin
>> second[c][d];
for ( c = 0 ; c
< m ; c++ )
for ( d = 0 ; d
< n ; d++ )
sum[c][d] =
first[c][d] + second[c][d];
cout <<
"Ikkita massiv elementlari yig’indisi:-\n";
for ( c = 0 ; c
< m ; c++ )
{
for ( d = 0 ; d
< n ; d++ )
cout << sum[c][d] <<
"\t";
cout <<
endl;
}
return 0;
}
Ikkita massivni ko'paytmasini, bo'linmasini yoki ayirmasini olish uchun oddiy arfimetik operatorlardan foydalanishingiz mumkin.
Ikkita massivni ko'paytmasini, bo'linmasini yoki ayirmasini olish uchun oddiy arfimetik operatorlardan foydalanishingiz mumkin.
Comments
Post a Comment
Iltimos, fikrlaringizni yozib qoldiring !