C言語メモ1


HelloWorld
#include <stdio.h>

main()
{
    printf("Hello World
"); getch(); }

 
FahrShiftCelsius1.0
#include <stdio.h>

/*   fahr= 0,20,...,300 ,  
           -         */
main()
{
    int fahr, celsius;
    int lower, upper, step;

    lower = 0;    /*        */
    upper = 300;  /*        */
    step = 20;    /*    */

    fahr = lower;
    while (fahr <= upper){
        celsius = 5 * (fahr - 32) / 9;
        printf("%d\t%d
", fahr, celsius); fahr = fahr + step; } getch(); }

 
FahrShiftCelsius2.0
#include <stdio.h>

/*   fahr= 0,20,...,300 ,  
           -        
         */
main()
{
    float fahr, celsius;
    int lower, upper, step;

    lower = 0;    /*        */
    upper = 300;  /*        */
    step = 20;    /*    */

    fahr = lower;
    while (fahr <= upper){
        celsius = (5.0 / 9.0) * (fahr - 32);
        printf("%3.0f\t%6.1f
", fahr, celsius); fahr = fahr + step; } getch(); }

 
CelsiusShiftFahr
#include <stdio.h>

/*         -     */
main()
{
    float fahr, celsius;
    int lower, upper, step;

    lower = 0;    /*        */
    upper = 300;  /*        */
    step = 20;    /*    */

    celsius = lower;
    while (celsius <= upper){
        fahr = (9.0 / 5.0) * celsius + 32;
        printf("%3.0f\t%6.0f
", celsius, fahr); celsius = celsius + step; } getch(); }

 
FahrShiftCelsius3.0
#include <stdio.h>

/*       -     for */
main()
{
    int fahr;

    for (fahr = 0; fahr <= 300; fahr = fahr + 20){
        printf("%3d %6.1f
", fahr, (5.0/9.0) * (fahr-32)); } getch(); }

 
FahrShiftCelsius4.0
#include <stdio.h>

/*       -     for   */
main()
{
    int fahr;

    for (fahr = 300; fahr >= 0; fahr = fahr - 20){
        printf("%3d %6.1f
", fahr, (5.0/9.0) * (fahr-32)); } getch(); }

 
FahrShiftCelsius5.0
#include <stdio.h>

#define LOWER 0     /*      */
#define UPPER 300   /*      */
#define STEP  20    /*    */

/*       -    */
main()
{
    int fahr;

    for (fahr = LOWER; fahr <= UPPER; fahr = fahr + STEP){
        printf("%3d %6.1f
", fahr, (5.0/9.0) * (fahr-32)); } getch(); }