-
Notifications
You must be signed in to change notification settings - Fork 14
/
uppercase.c
37 lines (37 loc) · 1.16 KB
/
uppercase.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h> //header files
#include <string.h>
#include <math.h>
int main() //main function
{
char S[1000]; //declaring variables and string
int test;
int i=1;
printf("Enter the no. of test cases = "); //taking no. of test case as input
scanf("%d",&test);
start: printf("Enter a string (Uppercase) = "); //taking string as input and string must be those whose integer form lies in range of long long
scanf("%s",S);
int len=strlen(S);
for(int j=0; j<len; j++) //to check string is lower case or not
{
if(S[j]>=97 && S[j]<=122)
{
printf("String must be in uppercase.\n");
i++;
goto start;
}
}
int temp=len;
long long sum=0;
while(len--) //loop to calculate integer form of string
{
char c=S[len];
sum=sum+(pow(26,temp-(len+1))*(c-64));
}
printf("%lld\n",sum);
if(i!=test) //when test case is not equal to counter i, then it goes to start statment
{
i++;
goto start;
}
return 0;
}