techhipbettruvabetnorabahisbahis forumutaraftarium24edueduseduseduseduseduedueduseduedus C Program : Maximum Scalar Product of Two Vectors
Latest :

C Program : Maximum Scalar Product of Two Vectors

Write a C program to find the maximum scalar product of the given two vectors. For this, we will represent vectors in the form of arrays and the inputs necessary are size of the two arrays and the data values or elements of the two arrays.

The resultant output is an integer representing the largest or maximum possible scalar product or dot product of the given two input arrays.

The first step to follow would be gathering the required inputs at runtime. To do so, in C language we have a predefined input function called scanf() which reads primitive datatype of any input at runtime from the keyboard.

Based on the format specifier we use, the datatype of the input will be decided. Here, all the inputs are of integer datatype so, we’ll use the ‘%d’ format specifier. We will first read the number or elements or size of the array (n). Then, we’ll create two arrays of the same size and read the data values of the two arrays by iterating and reading them individually.

printf(“\nEnter number of elements in two vectors:”);

scanf(“%d”,&n);

int vector1[n], vector2[n];

printf(“\nEnter %d elements in 1st vector:\n”,n);

for(i = 0;i < n;i++) {

scanf(“%d”,&vector1[i]);

}

printf(“\nEnter %d elements in 2nd vector:\n”,n);

for(i = 0;i < n;i++) {

scanf(“%d”,&vector2[i]);

}

To find the maximum scalar product in C, we’ll have to multiply the minimum value with the corresponding minimum value whereas maximum value with the maximum value. To do so, we’ll have to sort the two arrays first so, we call a user-defined function (sort) and pass the array along with its size as parameters. This function will sort the array passed as parameter in ascending order.

sort(vector1, n);

sort(vector2, n);

In the sort() function, we iteration from beginning (i=0) to the last but one index (n-2) and for every iteration we again iterate from starting (j=0) to the (n-i-1) index and check whether there exists a jth index such that a[j]>a[j+1].

If yes then, we swap the two data values using temporary variable (temp). We first assign the a[j] value to temp and then, assign the a[j+1] to a[j]. Then, we assign the original value of a[j] i.e., temp to the a[j+1]. This way the two values are swapped.

Output:

techhipbettruvabetnorabahisbahis forumutaraftarium24edusedusedusedueduedusedusedueduedu
x

Check Also

C Program To Left Rotate An Array | C Programs

C program to left rotate an array – In this article, we will brief in ...

grandpashabetgrandpashabetgrandpashabethttps://mobilebarhawaii.com/ballettea tropazcasibom girişcasibomhacklinkgrandpashabetbets10onwinonwin girişcasibom güncel girişselcuksportshdgrandpashabetholiganbetatakoy escortatakoy escortsisli escortjojobetCasibomtürk pornobetcup güncelcratosroyalbetdeneme bonusu veren sitelergrandpashabetonwinligobetmavibetJojobetsahabethttps://www.escortbayanlariz.net/betwoonsahabetcasibomcasibom girişÇeşme escortjojobetbakırköy escortdeneme bonusu veren sitelerhalkali escortgrandpashabet girişholiganbetankara escort bayangrandpashabetultrabetgrandpashabet girişholiganbetonwinsahabetbetwoonsahabet girişbetturkeypusulabetextrabetTipobetholiganbetGrandpashabetgrandpashabetesenyurt anal escortSekabetnakitbahiscasibomgrandpashabetİstanbul Escorthttps://www.gvscolombia.com/betebetdeneme bonusu veren sitelerJojobet GirişstarzbetsavoybettingsavoybettingjojobetfixbetBetturkey girişcasibom güncel girişkucukcekmece escortzbahissahabetsekabetotobetonwinmatadorbetmobilbahismeritbetmatbetmarsbahismadridbetsahabetimajbetholiganbetbetvolebetordercasinolevantPadişahbetmadridbetmavibetmeritbetotobetjojobetgrandpashabetholiganbetmarsbahisonwinonwinsahabetsekabetmatbetimajbetsahabet güncel girişbetcupbakırköy escortcanlı bahiscashbackstarzbetmegabahisbets10hipdrombetperabetromabetcasibom girişcasibom girişcasibom güncel girişjojobet girişCasibom girişvaycasinomarsbahisperabetperabet güncel girişcasinoroysdeneme bonusu veren sitelerbetebet güncel girişmarsbahissightcareipv6jojobetjojobetsahabetbets10,bets10 giriş,bets10 güncel giriş1xbet,1xbet girişmarsbahis,marsbahis güncel giriş , marsbahis giriş,marsbahis adresmarsbahis,marsbahis güncel giriş , marsbahis giriş,marsbahis adresmarsbahisartemisbetholiganbetjojobetjojobetmarsbahisjojobetmarsbahismarsbahiscasibomjojobetbets10atlasbetBostancı escort Bağcılar escortinterbahisholiganbetholiganbetjojobet,jojobet giriş,jojobet güncel girişholiganbetizmir escortcasibomkingroyalbelugabahisİstanbul EscortDeneme bonusu veren sitelercasibomjojobet girişJojobet Girişizmit escortcasibomcasibom girişcasibom güncel girişholiganbetimajbetperabetdeneme bonusu veren siteler 2025vaycasinocasinomaxizbahiscasinometropolmobilbahisbets10vaycasinocasibom girişbetturkeyholiganbet girişsahabet girişbets10betturkeyholiganbetdeneme bonusu veren sitelerholiganbetmarsbahiscasibombetoffice güncelkingroyalgrandpashabetgrandpashabet güncelcasibomcasibomonwinultrabettrendbettipobetrestbetnakitbahiskulisbetkralbetfixbetdumanbetdinamobetcratosslotbetkanyonbetebetbahsegelbahiscomcasibom girişholiganbet girişgrandpashabetjojobetjojobetmarsbahisholiganbetbetofficesahabetHoliganbet girişfixbetartemisbetholiganbetonwinhttps://sahipleniyorum.com/nakitbahisnakitbahis girişmegabahismatbetcasibomcasibom girişmaltepe escortpadişahbet girişmecidiyeköy escortdyziypayjojobettipobetkingroyal girişcasibomtipobetmatbetimajbetimajbet girişCasibommavibetmavibet güncelbets10 girişotobetotobet girişMavibetcasinomaximarsbahisselçuksportscasibom girişcasibom