Functions-Lucky String

Description:

Write a program to find whether the given string is Lucky or not. A string is said to be lucky if the sum of the ascii values of the characters in the string is even. Refer function specifications for the function details. The function accepts a pointer to a string and returns an int. The return value is 1 if the string is lucky and 0 otherwise. Input and Output Format: Input consists of a string. Assume that all characters in the string are lowercase letters and the maximum length of the string is 100. Refer sample input and output for formatting specifications. All text in bold corresponds to input and the rest corresponds to output. Test Case 1 Input (stdin) anitha Expected Output anitha is not lucky Test Case 2 Input (stdin) srm Expected Output srm is lucky

Program :


#include<stdio.h>

#include<string.h>

int checkLucky(char *a);

int main(){

  char s[100],c;

  scanf("%s",s);

  c=checkLucky(s);

  if(c==1)

    printf("%s is lucky",s);

  else if(c==0)

    printf("%s is not lucky",s);

  return 0;

}

int checkLucky(char *a)

{

  char *name;

  int i,sum=0,j;

  name=a;

  i=strlen(a);

  for(j=0;j<i;j++)

  {

    sum=sum+name[j];

  }

  if((sum%2)==0)

    return 1;

  else

    return 0;

}