I am trying to create a program in C, in which a user inserts random strings into a matrix. The program then uses this formula to evaluate each string and the rest of the code to display the string with the highest value. Every subsequent letter has a bigger value than the previous one.
I would be very glad if someone could point me in the right direction with this, currently the program displays some random letters from the strings.
Formula: Sum=(t*26^(n-1))
t = number of the letter, n = number of letters remaining
Example: abc -> 1*26^2+2*26^1+3*26^0
The rest of the code:
#include <stdio.h>
#include <string.h>
void insert(int, char[10][10], int num[]);
int computing(char[10]);
void sort(int, int num[], char[10][10]);
int main(){
int x;
char arr[10][10];
int num[x];
printf("How many words do you wish to enter: \n");
scanf(" %d", &x);
insert(x, arr, num);
sort(x, num, arr);
return 0;
}
void insert(int x, char arr[10][10], int num[]){
int i, r;
for(i=0; i<x; i++){
printf("Insert %d. word: ", i+1);
scanf("%s", &arr[i][0]);
num[i] = computing(arr[i]);
}
}
int computing(char arr[10]){
int n, i, t=1, m=0, k;
n = strlen(arr);
k = n;
for(i=0; i<n; i++){
m += (t*26^(k-1));
t++;
k = k - 1;
}
return m;
}
void sort(int x, int num[], char arr[10][10]){
int i, temp;
char ch;
for(i = 0; i < x - 1; i++){
if(num[i] > num[i+1]){
temp = num[i];
num[i] = num[i+1];
num[i+1] = temp;
ch = arr[i][0];
arr[i][0] = arr[i+1][0];
arr[i+1][0] = ch;
}
}
printf("Word with the biggest sum is: %s\n", &arr[x-1][0]);
}