Last active
March 5, 2016 06:09
-
-
Save motoso/3533aacb8ae5d3dbb99a to your computer and use it in GitHub Desktop.
2010年にC言語プログラミングレッスンを読んだときつくった解答
This file contains hidden or 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(void); | |
| void reverse_string(char *p); | |
| int count_string(char *p); | |
| int main(void) | |
| { | |
| char a[] = "This is Japan."; | |
| reverse_string(a); | |
| printf("%s\n", a); | |
| return (0); | |
| } | |
| void reverse_string(char *p) | |
| { | |
| int i,count; | |
| char tmp; | |
| count = count_string(p); | |
| for(i=0; i< count/2 ;i++){ | |
| tmp = *(p+i); | |
| *(p+i) = *(p+count-1-i); | |
| *(p+count-1-i)=tmp; | |
| } | |
| } | |
| /* | |
| *count_string関数は文字列から文字の数を数える | |
| */ | |
| int count_string(char *p) | |
| { | |
| int count=0; | |
| while(*p != '\0'){ | |
| count++; | |
| p++; | |
| } | |
| return (count); | |
| } |
This file contains hidden or 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> | |
| # include <stdlib.h> | |
| # define MAXLINE 256 | |
| int main(void); | |
| void graph(int x); | |
| /* | |
| 関数graph()は変数に対して二乗のグラフを描くプログラムだよお兄ちゃん | |
| 考えるのに2時間かかった | |
| */ | |
| void graph(int x){ | |
| int i,j; | |
| /* | |
| xを常に正となるようにする(|x|) | |
| */ | |
| if (x >= 0){ | |
| x = x; | |
| } | |
| else{ | |
| x = - x; | |
| } | |
| /* | |
| jは-|x|<j<|x|を動き,各々の段階で x^2 回 printf("*") を繰り返し改行する | |
| */ | |
| for(j = -x; j <= x ; j++){ | |
| for (i = 0; i < j * j; i++){ | |
| printf("*"); | |
| } | |
| printf("\n"); | |
| } | |
| } | |
| int main(void){ | |
| int A; | |
| char buffer[MAXLINE]; | |
| A = atoi(gets(buffer)); | |
| graph(A); | |
| return(0); | |
| } |
This file contains hidden or 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> | |
| #define MAX_DATA 10 | |
| /*最大値を求めるプログラムだぜ,オ兄ちゃん*/ | |
| int main(void); | |
| int main(void) | |
| { | |
| int i, max_data; | |
| int data[MAX_DATA] = { 31, 41, 59, 26, 53, 58, 97, 93, 23, 84 }; | |
| /*data[0]とdata[1],data[1]とdata[2]……と比較する. | |
| 番号の小さな変数に代入されている値が,大きな変数に代入されて | |
| いる値より大きければ,番号の大きな変数の中身を番号の小さな変 | |
| 数の中身(大きな値)にしてしまう.すると最大値(max_data)は | |
| data[9]と等しいので,data[9]を表示する.*/ | |
| max_data = data[0]; | |
| for (i = 0; i < MAX_DATA - 1; i++){ | |
| if(data[i] > data[i + 1]){ | |
| data[i + 1] = data[i]; | |
| } | |
| max_data=data[MAX_DATA - 1]; | |
| } | |
| printf("最大値は %d\n", max_data); | |
| return(0); | |
| } |
This file contains hidden or 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
| max_data = data[0]; | |
| for (i = 0; i < MAX_DATA; i++){ | |
| if (max_data < data[i];){ | |
| max_data = data[i]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment