Showing posts with label beginner. Show all posts
Showing posts with label beginner. Show all posts

Saturday, May 3, 2008

still stupid

its seems to be that most of my brain cells are unreachable at this moment so here are some stupid c code i have created.hehe.

1. to determine if a string is a palindrome:

/*
determines if a string is a palindrome
*/

#include
#include
#include

int isPalindrome(char string[],int length);

main()
{
int length;
char text[80];

printf("please enter the text:");
gets(text);
length=strlen(text);

if(isPalindrome(text, length))
printf("yes it is a palindrome.\n");
else
printf("sorry its not a palindrome.\n");
return EXIT_SUCCESS;
}


int isPalindrome(char string[], int length)
{
int ctr=length-1;
int i;
int value=0;
for(i=0;i<=ctr/2;i++)
{
if(string[i] != string[ctr])
break;
else value=1;
}

return value;
}

2. to reverse a string without using the strrev

/*
to reverse a string
*/
#include
#include
#include

void stringReverse(char string[],int length);

main()
{
int length;
char text[80];

printf("please enter the text:");
gets(text);
length=strlen(text);
return EXIT_SUCCESS;
}


void stringReverse(char string[], int length)
{
int ctr=length-1;

while(ctr>=0)
printf("%c", string[ctr]);
printf("\n");
return;
}

obviously the teacher will doubt if the code if its really yours when they saw the statement return EXIT_SUCCESS so if your a beginner just like me try something else so that your teacher wont bother you. :)