Generation

generate functionMon, 19 Dec 2022

#include <stdio.h> #include <stdlib.h> #include <time.h> typedef struct{ int no; int age; int height; int weight; int bmi; }person; int main() { srand((unsigned)time(NULL)); int i; person member[10]; for(i = 0; i < 10; i++){ member[i].no = i; member[i].age = rand() % 51 + 10; member[i].height = rand() % 41 + 140; member[i].weight = rand() % 31 + 40; member[i].bmi = calc(member[i].height, member[i].weight); } } } } int calc(int shincho, int taiju) { return taiju * 10000 / (shincho * shincho); } キーボードから入力された値より大きい bmi の配列要素の no を表示するプログラムを追加.

#include <stdio.h> #include <stdlib.h> #include <time.h> typedef struct{ int no; int age; int height; int weight; int bmi; }person; int main() { srand((unsigned)time(NULL)); int i; person member[10]; for(i = 0; i < 10; i++){ member[i].no = i; member[i].age = rand() % 51 + 10; member[i].height = rand() % 41 + 140; member[i].weight = rand() % 31 + 40; member[i].bmi = calc(member[i].height, member[i].weight); printf("%d %d %d %d %d\n", member[i].no, member[i].age, member[i].height, member[i].weight, member[i].bmi); } printf("please input bmi\n"); int

Questions about programming?Chat with your personal AI assistant