アットウィキロゴ

C

最も有名なプログラミング言語の一つ。計算速度の速さならあのFORTRANに並ぶ速さでありながらそのFORTRANに比べ環境をとても用意しやすいことから当サークルでは計算にCを利用することを推奨している。

Hello world

皆大好きHello world!プログラミングのプの字も知らない画面前の君もHello worldに挑戦だ!
#include <stdio.h>
 
int main(void) {
 printf("Hello, World!");
 return 0;
} 

リファレンス(入門)

コメント文

#include<stdio.h>
 
main(){
  //これはコメントです
}; 

変数宣言

整数 int %d
小数 double %f
文字列 char %s
#include<stdio.h>
main(){
  int a = 1;
  int b = 2;
}; 

文字を出力する

#include<stdio.h>
main(){
  int a = 1;
  int b = 2;
  printf("%d\n%d\n", a, b);
}; 

簡単な計算をする

a+bを計算する例

#include<stdio.h>
main(){
  int a = 1;
  int b = 2;
  int solution = a + b;
  printf("%d", solution);
}; 

aのb乗を計算する例

#include<stdio.h>
#include<math.h>
main(){
  int a = 2;
  int b = 3;
  int solution = pow(a, b);
  printf("%d", solution);
}; 

端末から値を入力する

#include<stdio.h>
main(){
  int a, b;
  scanf("%d %d", &a, &b);
  printf("%d\t%d", a, b);
}; 

繰り返し文

for文

#include<stdio.h>
main(){
  int a = 0;
  int i;
  for(i = 0; a <= 10; i++){
    a = a + 1;
    printf("%d\n", a);
  };
}; 

while文

#include<stdio.h>
main(){
  int a = 0;
  while(a <= 10){
    a = a + 1;
    printf("%d\n", a);
  };
}; 

do文

#include<stdio.h>
main(){
int a = 0;
  do{
    a = a + 1;
    printf("%d\n", a);
  }while(a <= 10);
}; 

条件分岐

if文

#include<stdio.h>
main(){
  int a;
  scanf("%d", &a);
  if(a < 10){
    printf("入力した値は10より小さい数値です。\n");
  }else{
    printf("入力した値は10以上の数値です。\n");
  };
}; 

参考

  • 初心者のためのポイント学習C言語
  • 苦しんで覚えるC言語
  • c言語関数辞典

タグ:

+ タグ編集
  • タグ:
最終更新:2013年11月15日 18:42