Created
September 25, 2014 20:52
-
-
Save bfb/d6054af373e73a7278fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(int argc, char* argv[]) { | |
int n, c, k, space = 1; | |
FILE *ptr_file; | |
char buf[1000]; | |
ptr_file =fopen(argv[1], "r"); | |
if (!ptr_file) | |
return 1; | |
fgets(buf, 1000, ptr_file); | |
n = atoi(buf); | |
fclose(ptr_file); | |
space = n - 1; | |
for (k = 1; k <= n; k++) | |
{ | |
for (c = 1; c <= space; c++) | |
printf(" "); | |
space--; | |
for (c = 1; c <= 2*k-1; c++) | |
printf("*"); | |
printf("\n"); | |
} | |
space = 1; | |
for (k = 1; k <= n - 1; k++) | |
{ | |
for (c = 1; c <= space; c++) | |
printf(" "); | |
space++; | |
for (c = 1 ; c <= 2*(n-k)-1; c++) | |
printf("*"); | |
printf("\n"); | |
} | |
return 0; | |
} | |
// SORT STRING | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
void sort_string(char*); | |
int main(int argc, char* argv[]) { | |
char string[100]; | |
FILE *ptr_file; | |
ptr_file =fopen(argv[1], "r"); | |
if (!ptr_file) | |
return 1; | |
fgets(string, 100, ptr_file); | |
fclose(ptr_file); | |
sort_string(string); | |
printf("%s\n", string); | |
return 0; | |
} | |
void sort_string(char *s) { | |
int c, d = 0, length; | |
char *pointer, *result, ch; | |
length = strlen(s); | |
result = (char*)malloc(length+1); | |
pointer = s; | |
for ( ch = 'a' ; ch <= 'z' ; ch++ ) { | |
for ( c = 0 ; c < length ; c++ ) { | |
if ( *pointer == ch ) { | |
*(result+d) = *pointer; | |
d++; | |
} | |
pointer++; | |
} | |
pointer = s; | |
} | |
*(result+d) = '\0'; | |
strcpy(s, result); | |
free(result); | |
} | |
// ODD OR EVEN | |
#include<stdio.h> | |
int main(int argc, char* argv[]) { | |
int n; | |
FILE *ptr_file; | |
char buf[1000]; | |
ptr_file =fopen(argv[1], "r"); | |
if (!ptr_file) | |
return 1; | |
fgets(buf, 1000, ptr_file); | |
n = atoi(buf); | |
fclose(ptr_file); | |
if ( n%2 == 0 ) | |
printf("Even\n"); | |
else | |
printf("Odd\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment