Skip to content

Commit

Permalink
Day 2 (Reverse + Palindrome) - C (#28)
Browse files Browse the repository at this point in the history
* Create Reverse.py

* Create Palindrome.py

* Update README.md

* Create Reverse.c

* Create Palindrome.c

* Update Reverse.c

* Update Palindrome.c

* Update README.md
  • Loading branch information
ashwek authored and MadhavBahl committed Dec 21, 2018
1 parent 72e13e8 commit c535fb5
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Day2/C/Palindrome.c
@@ -0,0 +1,33 @@
/**
* @author : ashwek
* @date : 21/12/2018
*/

#include<stdio.h>
#include<string.h>

void reverse(char Str[]){
char temp;
int i;

for(i=0; i<(strlen(Str)/2); i++){
temp = Str[i];
Str[i] = Str[strlen(Str)-i-1];
Str[strlen(Str)-i-1] = temp;
}
}

void main(){

char Str[50], Rev[50];
printf("Enter a string = ");
scanf("%s", Str);

strcpy(Rev, Str);
reverse(Rev);

printf("%s is ", Str);
if( strcmp(Str, Rev) != 0)
printf("not ");
printf("palindrome\n");
}
30 changes: 30 additions & 0 deletions Day2/C/Reverse.c
@@ -0,0 +1,30 @@
/**
* @author : ashwek
* @date : 21/12/2018
*/

#include<stdio.h>
#include<string.h>

void reverse(char Str[]){
char temp;
int i;

for(i=0; i<(strlen(Str)/2); i++){
temp = Str[i];
Str[i] = Str[strlen(Str)-i-1];
Str[strlen(Str)-i-1] = temp;
}
}

void main(){

char Str[50], Rev[50];
printf("Enter a string = ");
scanf("%s", Str);

strcpy(Rev, Str);
reverse(Rev);

printf("Reverse = %s", Rev);
}
76 changes: 76 additions & 0 deletions Day2/README.md
Expand Up @@ -267,7 +267,42 @@ int main()
return 0;
}
```
## C Implementation
### [Solution 1](./C/Reverse.c)
```c
/**
* @author : ashwek
* @date : 21/12/2018
*/
#include<stdio.h>
#include<string.h>
void reverse(char Str[]){
char temp;
int i;
for(i=0; i<(strlen(Str)/2); i++){
temp = Str[i];
Str[i] = Str[strlen(Str)-i-1];
Str[strlen(Str)-i-1] = temp;
}
}
void main(){
char Str[50], Rev[50];
printf("Enter a string = ");
scanf("%s", Str);
strcpy(Rev, Str);
reverse(Rev);
printf("Reverse = %s", Rev);
}
```

<hr />

Expand Down Expand Up @@ -453,3 +488,44 @@ if( Str != Str[::-1] ):

print("Palindrome")
```

## C Implementation

### [Solution 1](./C/Palindrome.py)

```c
/**
* @author : ashwek
* @date : 21/12/2018
*/

#include<stdio.h>
#include<string.h>

void reverse(char Str[]){
char temp;
int i;

for(i=0; i<(strlen(Str)/2); i++){
temp = Str[i];
Str[i] = Str[strlen(Str)-i-1];
Str[strlen(Str)-i-1] = temp;
}
}

void main(){

char Str[50], Rev[50];
printf("Enter a string = ");
scanf("%s", Str);

strcpy(Rev, Str);
reverse(Rev);

printf("%s is ", Str);
if( strcmp(Str, Rev) != 0)
printf("not ");
printf("palindrome\n");
}

```

0 comments on commit c535fb5

Please sign in to comment.