• 検索結果がありません。

‰ð“šPDF N‰Èî•ñƒlƒbƒgƒ[ƒN“±“üƒ†ƒjƒbƒg‡UiCŒ¾Œê‡Uj

N/A
N/A
Protected

Academic year: 2018

シェア "‰ð“šPDF N‰Èî•ñƒlƒbƒgƒ[ƒN“±“üƒ†ƒjƒbƒg‡UiCŒ¾Œê‡Uj"

Copied!
2
0
0

読み込み中.... (全文を見る)

全文

(1)

C言語Ⅱ 演習(4-2) ~構造体(2)~ 解答例 1

C

言語Ⅱ

演習(4-2)

~構造体(2)~

教科書

2

*以下 プログラム例 あ ,全く同 あ 必要 あ ません.プログラム作成 参考 確認 ください.

問題 .

// 演習( - ) 構造体 問題

#include<stdio.h>

struct

data{

char name[20];

int

hp;

int

str;

};

int main(void){

int i;

struct

data

monster[3] = {

{"Slime" , 200, 185 },

{"Skelton", 156, 144 },

{"Snake", 278, 77 }

};

for (i=0; i<3; i++) {

printf("

名前

=%s¥n",monster[i].name);

printf("

身長

=%d[cm]¥n", monster[i].hp);

printf("

体重

=%f[kg]¥n¥n", monster[i].str);

return 0;

}

問題 .

// 演習( - ) 構造体 問題

#include<stdio.h>

typedef struct{ char name[20]; //

int height; //

double weight; //

}data;

int main(void){ data student[100] = {

{"Jun" , 170, 65.0 }, {"Nero", 160, 51.2 } };

printf("名前=%s\n", student[1].name); //☆☆☆

printf("身長=%d[cm]\n", student[1].height); //☆☆☆

printf("体重=%4.1f[kg]\n", student[1].weight); //☆☆☆

return 0; }

問題 .

// 演習( - ) 構造体 問題

#include<stdio.h>

typedef struct{ char name[20]; int height; double weight; }data;

int main(void){ data student[100]; int i;

for(i=0; i<2; i++){ printf("名前:");

scanf("%s", student[i].name);

printf("身長:");

scanf("%d", &student[i].height);

printf("体重:");

scanf("%lf", &student[i].weight);

printf("\n"); }

for(i=0; i<2; i++){

printf("名前=%s\n", student[i].name);

printf("身長=%d[cm]\n", student[i].height);

printf("体重=%4.1f[kg]\n", student[i].weight);

printf("\n"); }

return 0; }

問題 .

// 演習( - ) 構造体 問題

#include<stdio.h> #include<stdlib.h>

typedef struct{

char num[7]; //\0に注意 char name[11]; //\0に注意 int ten;

}list;

int main(void){ FILE *fp; int i;

list student[4];

(2)

C言語Ⅱ 演習(4-2) ~構造体(2)~ 解答例 2 printf("ファイル 開けませ \n");

exit(1); //return 1; も可 }

for(i=0;i<4;i++){

fscanf(fp, "%s", student[i].num); fscanf(fp, "%s", student[i].name);

printf("学籍番号(%s) ", student[i].num);

printf("氏名(%s):", student[i].name);

scanf("%d", &student[i].ten); }

fclose(fp);

printf("\n");

printf("学籍番号 名前 成績\n");

for(i=0;i<4;i++){

printf("%8s", student[i].num); printf("%10s", student[i].name); printf("%6d", student[i].ten);

printf("\n"); }

return 0; }

参照

関連したドキュメント

Theorem 3 implies strong asymptotic stability results: the energy of strong solutions decays to zero, with an explicit decay rate

There is a bijection between left cosets of S n in the affine group and certain types of partitions (see Bjorner and Brenti (1996) and Eriksson and Eriksson (1998)).. In B-B,

Actually a similar property shall be first de- rived for a general class of first order systems including the transport equation and Schr¨odinger equations.. Then we shall consider

Hence, the degree theory constructed in [1] is an extension of the classical Leray–Schauder degree in Hilbert space.. It is unique, single-valued and has the usual properties of

Lair and Shaker [10] proved the existence of large solutions in bounded domains and entire large solutions in R N for g(x,u) = p(x)f (u), allowing p to be zero on large parts of Ω..

We prove a continuous embedding that allows us to obtain a boundary trace imbedding result for anisotropic Musielak-Orlicz spaces, which we then apply to obtain an existence result

This concludes the proof that the Riemann problem (1.6) admits a weak solution satisfying the boundary condition in the relaxed sense (1.6c).... The two manifolds are transverse and

This paper is a sequel to [1] where the existence of homoclinic solutions was proved for a family of singular Hamiltonian systems which were subjected to almost periodic forcing...