Write a program in C using operators such as: {int, char, printf, ==, , +, -, =,
ID: 3565497 • Letter: W
Question
Write a program in C using operators such as: {int, char, printf, ==, , +, -, =, !=, while, if, else, &&, || }| The text entered will be a string of Alphanumeric Words without punctuation, except for spaces between any adjacent Alphanumeric Words and a single period as the final character. Alphanumeric Words, if present, consist of only Uppercase Letters {A,B,C Z} and/or Numeric Digits {0,1,2 9}. If and only if an entire Alphanumeric Word is a valid hexadecimal value, then it will be replaced with its equivalent decimal value. The program shall output the text with the corresponding substitutions to the console. Also, determine the largest valid hexadecimal value that is an entire Alphanumeric Word present in the string. Based on that value, determine the corresponding range in the left-hand column. Finally, output the String Digit Score listed in the right-hand column as a new line to the console. Table 1 : Mapping of String Digit Score. Consider sample input: I ACED THE EXAM AND EARNED AN A PLUS. Part A would provide the following output: I 44269 THE EXAM AND EARNED AN 10 PLUS. Part B would additionally provide the following output: IntermediateExplanation / Answer
#include<stdio.h>
#include<stdlib.h>
#include <math.h>
int main()
{
while(1)
{
char a[100],b;
printf("Enter the sentence ");
int i,f=0,j;
while(1)
{
i=0;
f=0;
int temp=0,max=0;
while((b=getchar())!=' ')
{
if (b==' ' ||b=='.')
break;
if (f==0 && b>'F')
f=1;
a[i++]=b;
}
if(f==0)
{
for (j=i-1;j>=0;j--)
{
int xx;
if (a[j]>='0' && a[j]<='9')
xx=a[j]-'0';
else if(a[j]>='A' && a[j]<='F')
xx=a[j]-'A'+10;
temp+=xx*pow(16,i-1-j);
}
printf("%d",temp);
if(temp>max)
max=temp;
}
else
{
for (j=0;j<i;j++)
putchar(a[j]);
}
putchar(b);
if(b==' ')
{
if(max==0 && max<=255)
printf("Sparse ");
else if(max>=256 && max<=65535)
printf("Intermediate ");
else if(max>=65536 && max<=268435455)
printf("Plentiful ");
printf("Enter the sentence ");
}
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.