/****************************/
/* 台形の面積の計算 */
/* coded by Y.Suganuma */
/****************************/
#include <stdio.h>
int main()
{
double t1, t2, h, men;
t1 = 3.5;
t2 = 1.0;
h = 0.7;
men = 0.5 * h * (t1 + t2);
printf("面積=%f\n", men);
return 0;
}
/****************************/
/* 円周と面積の計算 */
/* coded by Y.Suganuma */
/****************************/
#include <stdio.h>
int main()
{
double r, ens, men, pi;
/*
πの値
*/
pi = 3.141592654;
/*
半径の読込
*/
printf("円の半径は? ");
scanf("%lf", &r);
/*
円周と面積の計算
*/
ens = 2.0 * pi * r;
men = pi * r * r;
/*
出力
*/
printf("円周=%f 面積=%f\n", ens, men);
return 0;
}
/****************************/
/* 式の値の計算 */
/* coded by Y.Suganuma */
/****************************/
#include <stdio.h>
int main()
{
double s1, s2, x, x1;
/*
xの読込
*/
printf("xは? ");
scanf("%lf", &x);
/*
式の計算
*/
x1 = x + 3.0;
s1 = x * x * x + 3.0 * x * x + 2.0;
s2 = x1 * x1 / 3.0 + 5.0;
/*
出力
*/
printf("式1=%f 式2=%f\n", s1, s2);
return 0;
}
/****************************/
/* 商と余り */
/* coded by Y.Suganuma */
/****************************/
#include <stdio.h>
int main()
{
int n1, n2, sho, amari;
/*
データの読込
*/
printf("2つの整数を入力して下さい ");
scanf("%d %d", &n1, &n2);
/*
計算
*/
sho = n1 / n2;
amari = n1 % n2;
/*
出力
*/
printf("商=%d 余り=%d\n", sho, amari);
return 0;
}
/****************************/
/* 釣り銭の計算 */
/* coded by Y.Suganuma */
/****************************/
#include <stdio.h>
int main()
{
int kippu, turi, money, i500, i100, i50, i10;
/*
切符の値段の読込
*/
printf("切符の値段は? ");
scanf("%d", &kippu);
/*
釣り銭の額
*/
turi = 1000 - kippu;
money = turi;
/*
釣り銭の内訳の計算
500円
*/
i500 = money / 500;
money = money - 500 * i500;
/*
100円
*/
i100 = money / 100;
money = money - 100 * i100;
/*
50円
*/
i50 = money / 50;
money = money - 50 * i50;
/*
10円
*/
i10 = money / 10;
/*
結果の出力
*/
printf("釣り銭 %d\n", turi);
printf("500円 %d 100円 %d 50円 %d 10円 %d\n", i500, i100, i50, i10);
return 0;
}
/****************************/
/* 消費税の計算 */
/* coded by Y.Suganuma */
/****************************/
#include <stdio.h>
int main()
{
long nedan0, nedan1, nedan2, nedan3;
/*
値段の入力
*/
printf("商品の値段は? ");
scanf("%ld", &nedan0);
nedan0 = nedan0 * 103;
/*
切り捨て
*/
nedan1 = nedan0 / 100;
/*
切り上げ
*/
nedan2 = (nedan0 + 99) / 100;
/*
4捨5入
*/
nedan3 = (nedan0 + 50) / 100;
/*
出力
*/
printf("切り捨て %ld 切り上げ %ld 4捨5入 %ld\n", nedan1, nedan2, nedan3);
return 0;
}
| 菅沼ホーム | 演習解答例目次 | 本文目次 | 付録 | 索引 |