「C言語」scanf()で数値を入力するサンプル
書式
scanf(“変換指定子”, &変数名)
変換指定子
int 整数型 %d
float 単精度実数)%f
double 倍精度実数)%lf
...
「C言語」算術演算子を利用するサンプル
算術演算子
+ 足し算
- 引き算。
* かけ算
/ 割り算
% 剰余算
サンプル
「C言語」配列を利用するサンプル
書式
変数の型 変数名;
例 int age
サンプルコード
#include <stdio.h> int main(void) { int cft; cft = 2; cft = 4; ...「C言語」エスケープシーケンス(特殊文字)を利用する方法
特殊文字
\n 改行
\r 行頭
\t タブ
\\ バックスラッシュ「\」
\’ シングルクォーテーション「’」
\? クエスチョンマーク「?」 ...
「C++」find()で文字列の位置を取得数方法
書式
対象文字列.find(検索する文字列)
説明
先頭から検索して引数に指定した文字列が出現した位置を返します。
使用例
string cft = “tokyo”; ...
「C言語」Switch文でenum値を出力するサンプル
サンプルコード
#include <stdio.h>#include <stdlib.h>int main(){ enum color { red=1, green, blue }; enum color ...「C言語」for文enumの要素をループするサンプル
サンプルコード
#include<stdio.h> enum DAY{ MON=1, TUE, WED, THU, FRI, SAT, SUN} day;int main(){//列挙型の要素 for (day = ...「C言語」列挙型(enum)を利用するサンプル
サンプルコード
#include<stdio.h> enum DAY{ MON=1, TUE, WED, THU, FRI, SAT, SUN}; int main(){ enum DAY day; day = WE ...「C言語」文字列をASCIIコードに変換するサンプル
サンプルコード
#include <stdio.h>int main(){ char c; printf("文字列を入力してください: ");//文字列の入力 scanf("%c", &c); printf( ...「C言語」breakでループから拔けるサンプル
サンプルコード
#include <stdio.h> int main(void){/* 変数の宣言 */int i;/* 繰り返し処理 */for(i=0;i<21;++i) { printf("値: %d\ ...「C言語」setlocale関数でロケールを設定するサンプル
サンプルコード
#include <stdio.h>#include <locale.h>int main(void){ char* tt = setlocale( LC_ALL, NULL ); put ...「C言語」acos()関数で逆余弦を計算するサンプル
サンプルコード
#include <stdio.h>#include <math.h>#define PI 3.14159265int main (){ double x, ret, cft; x = 0 ...「C言語」setlocale関数でロケールを設定するサンプル
サンプルコード
#include <locale.h>#include <stdio.h>#include <time.h> int main (){ time_t currtime; str ...「C言語」標準ヘッダlimits.hの定義マクロ
サンプルコード
#include <stdio.h>#include <limits.h>int main(){ printf("The number of bits in a byte %d\n", C ...「C言語」intからdoubleへの型のキャストをするサンプル
サンプルコード
#include <stdio.h> int main(){ int sum = 17, count = 5; double tt; tt = (double) sum/count; printf(" ...「C言語」for文で配列の要素を出力するサンプル
サンプルコード
int main(void) { int i; int a = {13, 14, 15,16,17};/* 配列の要素を出力 */for(i=0;i<5;++i){ printf("%d\n", a); } ...「C言語」for文で多次元配列の要素を出力するサンプル
サンプルコード
#include <stdio.h>
int main(void) {
int i, j;
int a = {106, 107, 108, 109};
「C言語」配列の要素を取得するサンプル
サンプルコード
#include <stdio.h>
int main ()
{
int n;
int i,j;
/* 初期化*/
for ( i = 0; ...