c言語 練習ソースプログラム

[ リスト ]

NG・・・

合計が出ない・・・


イメージ 1




#include <stdio.h>
#define N 20
typedef struct {
	int b;		/*学生番号*/
	int t;		/*体重*/
	}Student;

int print_dt(Student *p);

int main( ){
	Student stu[N+1];
	int i = 0;
	int s = 0;

	printf("学生番号、体重を入力(終了条件:Ctrl+Z)\n");
	while( (scanf("%d %d",&stu[i].b,&stu[i].t)!=EOF) && i<N){
		i++;
		s += stu[i].t;
	}

	stu[i].b = 0;
	stu[i].t = 0;

	print_dt(stu);

	printf("学生の体重合計は%dです\n",s);

	return 0;
}


int print_dt(Student *p){
	printf("学生番号    体重\n");	
	while(p->b!=0 && p->t!=0){
		printf("%8d%12d\n",p->b,p->t);
		p++;
		}
	
	return 0;
}	
	

	



インクリメントの位置が間違ってましたっ で。OKです♪




イメージ 2


#include <stdio.h>
#define N 20
typedef struct {
	int b;		/*学生番号*/
	int t;		/*体重*/
	}Student;

int print_dt(Student *p);

int main( ){
	Student stu[N+1];
	int i = 0;
	int s = 0;

	printf("学生番号、体重を入力(終了条件:Ctrl+Z)\n");
	while( (scanf("%d %d",&stu[i].b,&stu[i].t)!=EOF) && i<N){
		s += stu[i].t;
                     i++;
	}

	stu[i].b = 0;
	stu[i].t = 0;

	print_dt(stu);

	printf("学生の体重合計は%dです\n",s);

	return 0;
}


int print_dt(Student *p){
	printf("学生番号    身長\n");	
	while(p->b!=0 && p->t!=0){
		printf("%8d%12d\n",p->b,p->t);
		p++;
		}
	
	return 0;
}	
	

	

閉じる コメント(1)

顔アイコン

かぎ//今見直してエラーがわかりました!!「i++;」の位置がダメだったんです。。。かぎさんのプログラムも参考にさせてもらいますね!ありがとうございます☆

2008/5/19(月) 午前 0:16 月夜


よしもとブログランキング

もっと見る

プライバシー -  利用規約 -  メディアステートメント -  ガイドライン -  順守事項 -  ご意見・ご要望 -  ヘルプ・お問い合わせ

Copyright (C) 2019 Yahoo Japan Corporation. All Rights Reserved.

みんなの更新記事