techhipbettruvabetnorabahisbahis forumutaraftarium24edusedueduseduseduedueduedusedusedus 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 forumutaraftarium24eduedueduedusedueduseduseduseduedu
x

Check Also

C Program To Print Number Of Days In A Month | Java Tutoring

C program to input the month number and print the number of days in that ...

betwoonhacklink satın albets10 girişakcebet uyeliksupertotobet1xbet girişmelbet girişbetwinnerpinup uyelikbtcbahis girişmostbet girişbetwinner girişxslotskyloft uyelikmegapari uyeliktipobetgrandpashabetradissonbetmariobett.mebetandreasenbetcasivalmisbahismyhitbetonbahistipobetbahsinevavepasgolgrandpashabetmarsbahispusulabetcasibomcasibom girişcasibom güncel girişcasibomcasibom girişdeneme bonusu veren sitelerhttps://mobilebarhawaii.com/ballettea tropazjokerbet güncel girişmatadorbetbets10betturkeycasibomkingroyalcasibom girişbets10 girişcasibommaldives casinohacklinkgrandpashabetbetmatik girişmelbetmostbetmegapari üyelikistanbul escortmatadorbetimajbetJojobetcasibompinco girisonwinonwin girişcasibom güncel girişselcuksportshdcasibomjojobetatakoy escortatakoy escortsisli escortgalatabahisliste paris sportifjeux casino gratuit avec bonusSimsinos CasinojojobetCashimashi AvisWunderWinsparier sur les cornersGamdomCasibomSekabet güncel girişmadridbet girişpinbahisemiratesbettrbetcasibomcratosroyalbetpalacebetcasinokaliprensbetrestbetcasibomrestbetgrandpashabetgrandpashabetmatadorbetmaltcasinoholiganbetholiganbetmatadorbetmarsbahisonwinsahabetmostbet guncel girisbetandyou guncel girisromabet guncel giris7slots guncel girisbizbet guncel girisrocksroyalbetkazandradeneme bonusu veren sitelergrandpashabettipobetonwintempobet güncel girişprincessbethttp://nakanakadining.com/betkanyonpinup yeni girismatadorbet yeni girisroketbet yeni girisskyloft yeni girismegapari yeni girisjojobet girişsavoybettingcasinomhubligobetmavibetenobahisJojobetcoinbartempobetcoinbarmariobettarafbetcasibomkalebetjetbetbetturkeyjojobetmavibetarnavutköy escortkingroyalmaltcasinoholiganbet girişsahabetmobilbahishttps://www.escortbayanlariz.net/beylikdüzü escortfikstürbetmisliwinbetciosahabetonwinsekabetvbetholiganbetjojobetonwinmatbetmatbetimajbetimajbetsahabetJojobet Girişmariobettarafbetodeonbetbetwoonbets10sahabetbets10matadorbet güncel girişjojobet güncel girişmavibetartemisbetkingroyalcasibomcasibom girişmeritbetpinbahiszbahissekabetcasinometropolarnavutköy escortMarmaris escortmarsbahis girişpinbahiscasinometropolbetebetotobetimajbetcasibomvaycasinobakırköy escortjojobetkulisbetsüperbetin güncel girişsekabetpusulabetMavibetOnwinbets10 girişmarsbahiscasibomxslot girişdeneme bonusu veren sitelermarsbahisbetturkey girişbetturkeyhalkali escortcasinomaxitarafbetcasibom girişbetwoonholiganbet güncel girişjojobetjojobet girişholiganbetmeritking güncel girişmatadorbet güncel girişmatadorbet güncel girişgrandpashabet girişsahabet girişonwin girişsekabet girişholiganbet girişjojobet girişmatbetmarsbahis güncel girişmarsbahis girişxslotjojobetpadişahbetcasibom girişcasibomjojobetselçuksportsSekabetholiganbethttps://www.gvscolombia.com/güvenilir casino siteleri antalya escortmatbetimajbet güncel girişmarsbahis güncel girişjojobetjojobet girişcasibom girişjojobetsonbahisjojobet girişankara escort bayanbetparkcasibomgrandpashabetcasibom girişmarsbahismatadorbetultrabet girişJojobetmaldives betcasibom güncel girişjojobetbetcio girişbets10grandpashabet girişbahiscasinojokerbet güncel girişSüpertotobetxslotbetpipocasibomtaraftarium24holiganbetholiganbetholiganbetjojobetimajbetbets10Sekabet güncel girişcasibomjojobetonwinextrabetmatadorbet güncel girişextrabet girişbetciobetwoonmarsbahissahabetTipobetholiganbetSekabetcasibomesenyurt anal escortrus escortartemisbetPusulabet güncel girişjojobetcasinometropolcasibom girişgüvenilir casino siteleri grandpashabetİstanbul Escortbetciohttps://www.gvscolombia.com/jojobetcasinomaxideneme bonusu veren sitelergrandpashabet girişgrandpashabetCasibomstarzbetjojobetjojobet girişbetkanyonbetkanyonJojobetsahabetjojobetjojobet girişgooglecasibomkucukcekmece escort