Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)
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:

x

Check Also

C Program To Count The Total Number Of Notes In A Amount | C Programs

C program to count the total number of notes in a given amount – In ...

bakırköy escortşişli escortsightcareDeneme Bonusu Veren SitelerDeneme Bonusu Veren SitelerDeneme Bonusu Veren SitelerDeneme Bonusu Veren Sitelerdeneme bonusu veren sitelergrandpashabetgrandpashabetGrandpashabetdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelercasinofastbetwoondeneme bonusu veren sitelerdeneme bonusugrandpashabetdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelergrandpashabetgrandpashabetbetgray güncel girişdeneme bonusu veren sitelerDeneme Bonusu Veren Sitelerbetgray günceljojobetcasibom güncelcasibom güncel girişhalkalı escortsakarya escortmatbetholiganbetdeneme bonususonbahisteosbetpusulabetjojobetbetnanobets10Jojobetjokerbettimebetnakitbahistrendbetjojobet girişjojobet girişultrabetartemisbettürk ifşaJojobetcasibom girişcasibomjojobetsolibetsolibet girişsolibet giriş adresisolibetsolibetcasibomcasibom girişgalabet girişbetpuanodeonbetodeonbetcasibomcasibomtürk ifşa girişholiganbetonwinpusulabetcasibom girişbetofficecasibombetnano girişmeritbetkatlaholiganbetJojobetpadişahbetvaycasino girişcasibom güncelcasibom güncel girişcasibom girişsohbet hattıbetasusgrandpashabetgrandpashabetkatlameritbetmeritbetmeritbettürk ifşa girişcasibommarsbahismarsbahisbetzulaalobet girişbetzula girişalobetalobet girişalobetmarsbahismeritkingcasibomcasibom girişJojobet girişasyabahisgrandpashabetholiganbet girişmarsbahismarsbahis güncel girişjojobetjojobet girişcasibomcasibom girişpadişahbet girişmarsbahistürk ifşa girişmarsbahismarsbahis girişgrandpashabetvaycasinocasibomcasibom girişgrandpashabetgrandpashabetgrandpashabetgrandpashabetcratosroyalbetbetwoonjojobetGrandpashabetyakabetbetkolikbetnanojojobet girişpadişahbetpadişahbetkalebetaresbetdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerdeneme bonusu veren sitelerromabetjojobetholiganbetvaycasinovaycasino girişKocaeli EscortelexbetelexbetbetciograndpashabetramadabetramadabetramadabetspincoLidyabetholiganbetholiganbetmarsbahismarsbahis girişpadişahbetparmabetbetkolikbetpuanbetpuanparmabetmarsbahis,marsbahis güncel girişholiganbetgrandpashabetpusulabetcasibommatbet girişjokerbetbahislioncasibom girişcasibomkavbetholiganbetholiganbetpusulabetmatbetcasibomgobahismatbetcasibomcasibom girişjojobetsekabetjojobet güncel girişRomabetmatbetBetnanoKulisbetKulisbetKulisbetholiganbetbetebet girişbetebetmatadorbet girişgrandpashabetmarsbahisonwin girişPusulabet yeni Girişsahabet girişmatbet girişsahabetimajbet girişonwinvdcasinoholiganbet girişholiganbetmatbetpusulabet girişgrandpashabetpusulabetBetsmovematbetjojobet girişmatbetbetboxmarsbahis girişmarsbahismatbet güncel girişpusulabet girişgrandpashabet girişholiganbet girişmarsbahis girişvdcasinovaycasinocasibom