Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program, which takes a string as an input and then generates a numeric

ID: 3620156 • Letter: W

Question

Write a C program, which takes a string as an input and then generates a numeric value for that using the following formula:
?(10*position of the digit*digit)+5*(total number of non-digits).
Here digits mean (0,1,2...8,9).
Example: If the input is "ed2r4" then the numeric value is (10*1*4+10*3*2+5*3=115).
Provide the code and output for a sample input.

This is what i have done so far below:

#include <stdio.h>

void main () {

char string[3] = {'e', 'd', 'r'};

int e = 1, d = 3, r= 3;
int i;
int total = 0;

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

total += ((10*string[i]*4)+ (5*3));

}
printf("total is %d ", total);


getchar();
}

Explanation / Answer

please rate - thanks message me if there is anything you don't understand #include <stdio.h>
#include <conio.h>
#include<string.h>
int main () {
char string[30] ;
int e = 1, d = 3, r= 3;int i;
int total = 0;
int len,non=0;
printf("enter a string: ");
scanf("%s",&string);
len=strlen(string);
for(i = len-1;i >=0; i--) {
      if(string[i]<'0'||string[i]>'9')
           non++;
      else
          {
          total+=10*(string[i]-'0')*(len-i);
          }
}
total+=non*5;
printf("total is %d ", total);
getch();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote