#include <stdio.h>
struct syain_dt { /* 社員情報構造体 */
long no; /* 社員番号 */
char name[20]; /* 氏名 */
char yaku[20]; /* 役職 */
int nensu; /* 勤続年数 */
long kihon; /* 基本給 */
};
int main( void )
{
struct syain_dt syomu[20]= { /* 庶務課 */
{ 78027, "神保直樹", "課長", 21, 346780 },
{ 84004, "相原彰子", "主任", 15, 223640 },
{ 87022, "本郷幸子", "", 12, 208760 },
{ 93042, "三上葵", "", 6, 176530 },
{ 95005, "佐々木翠", "", 4, 166700 },
{ 99009, "長崎宏美", "", 1, 150140 },
{ 0, "", "", 0, 0 },
};
int i;
printf( "社員番号 氏名 役職 勤続年数 基本給\n" );
for ( i=0; syomu[i].no != 0; i++ ) {
printf( "%5ld %-12s %5s %6d %6ld\n",
syomu[i].no, syomu[i].name, syomu[i].yaku,
syomu[i].nensu, syomu[i].kihon );
}
return 0;
}
#include <stdio.h>
/* #defineについては第18章参照 */
#define NINZU 5 /* 学生の人数 */
#define KAMOKU 4 /* 科目数 */
struct seiseki { /* 成績データ */
int no; /* 学生番号 */
int ten[4]; /* 点数 */
double avg; /* 平均点 */
char hyouka; /* 評価 */
};
int main( void )
{
struct seiseki mycls[NINZU] = {
{ 1001, 85, 74, 63, 90, 0.0, '?' },
{ 1002, 78, 65, 70, 62, 0.0, '?' },
{ 1003, 89, 92, 88, 76, 0.0, '?' },
{ 1004, 32, 48, 66, 25, 0.0, '?' },
{ 1005, 92, 76, 81, 98, 0.0, '?' },
};
int i, j;
printf( "番号 国語 数学 理科 社会 平均 評価\n" );
for ( i = 0; i < NINZU; i++ ) {
/*** 平均点を求める ***/
for ( j = 0; j < KAMOKU; j++ ) {
mycls[i].avg = mycls[i].avg + mycls[i].ten[j];
}
mycls[i].avg = mycls[i].avg / KAMOKU;
/*** 評価を求める ***/
if ( mycls[i].avg < 60.0 )
mycls[i].hyouka = 'D';
else if ( mycls[i].avg < 70.0 )
mycls[i].hyouka = 'C';
else if ( mycls[i].avg < 80.0 )
mycls[i].hyouka = 'B';
else
mycls[i].hyouka = 'A';
}
/*** 結果の表示 ***/
for ( i = 0; i < NINZU; i++ ) {
printf( "%4d %4d %4d %4d %4d %8.2f %c\n",
mycls[i].no, mycls[i].ten[0], mycls[i].ten[1],
mycls[i].ten[2], mycls[i].ten[3],
mycls[i].avg, mycls[i].hyouka );
}
return 0;
}
▼戻る▼
「初心者のためのポイント学習C言語」 Copyright(c) 2000-2004 TOMOJI All Rights Reserved