階乗(factorial) 計算サンプルコード
サンプルコード
#include <stdio.h>
double factorial(unsigned int i)
{
if(i <= 1)
{
retur ...
「C言語」getchar関数とputchar関数の使い方
サンプルコード
#include <stdio.h>
int main( )
{
int c;
printf( “文字を入力してください :”); ...
「C言語」printf()で変換指定子を利用するサンプル
サンプル1.%dで整数を出力
#include <stdio.h>
int main()
{
int cftIntr = 8;
printf(“Number = %d ...
「C言語」define定数の定義方法
サンプルコード
#include <stdio.h>
#define TRUE 1
#define FALSE 0
int main( )
{
printf( ...
「C言語」構造体とtypedefを利用するサンプル
サンプルコード
#include <stdio.h>
#include <string.h>
typedef struct Books
{
char title; ...
「C言語」列挙型(enum)の使い方
サンプルコード
#include<stdio.h>
enum DAY
{
MON=1, TUE, WED, THU, FRI, SAT, SUN
};
int mai ...
「C言語」extern int errnoでエラーを確認する
サンプルコード
#include <stdio.h>
#include <errno.h>
#include <string.h>
extern int errn ...
「C++」配列の要素数を取得する
サンプルコード
#include <iostream>using namespace std; #include <iomanip>using std::setw; int main (){ int n; ...C言語で文字列を逆にするサンプル
サンプルコード
#include <stdio.h>void reverseSentence(); int main(){ printf("文字列を入力してください: "); reverseSentence(); r ...「C言語」fgets関数でファイルを読み込むサンプル
サンプルコード
#include <stdio.h> int main(){ FILE *fp = NULL; char buff; fp = fopen("/tmp/test.txt", "r"); fscanf( ...「C言語」fputs関数の使い方
サンプルコード
#include <stdio.h> int main(){ FILE *fp = NULL; fp = fopen("/tmp/demo.txt", "w+"); fprintf(fp, "This ...「C言語」アルファベット(A to Z)の連続を出力するサンプル
サンプルコード
#include <stdio.h> int main(){ char c; for(c = 'A'; c <= 'Z'; ++c) printf("%c ", c); return 0;}「C言語」配列の最大値を探すサンプル
サンプルコード
#include <stdio.h> int main() { int array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; int loop, largest; large ...「C言語」union共用体の使い方
サンプルコード
#include <stdio.h>#include <string.h> union Data{ int i; float f; char str;}; int main( ){ uni ...「C言語」struct構造体の使い方
サンプルコード
#include <stdio.h>struct Books{ char title; char author; char subject; int book_id;} book = {"C言語入門" ...「C言語」continueで繰り返し処理のループをスキップするサンプル
サンプルコード
#include <stdio.h> int main (){/* 変数の宣言 */int a = 10;/* do ループ*/do { if( a == 15) {//ループをスキップ a = a ...「C言語」typedef struct による構造体の定義サンプル
サンプルコード
#include <stdio.h>#include <string.h> typedef struct Books{ char title; char author; char subj ...「C言語」gets()とputs()関数の使い方
サンプルコード
#include <stdio.h> int main( ){ char str; printf( "Enter a value :"); gets( str ); printf( "\nYou en ...