News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

A Weight Conversion Program

Started by jayanthi mandhalapu, Jul 27, 2009, 08:18 AM

Previous topic - Next topic

jayanthi mandhalapu


#include <stdio.h>
#define KILOS_PER_POUND .45359
main()
{       int pounds;

        printf(" US lbs      UK st. lbs       INT Kg\n");

        for(pounds=10; pounds < 250; pounds+=10)
        {       int stones = pounds / 14;
                int uklbs = pounds % 14;
                float kilos = pounds * KILOS_PER_POUND;
                printf("   %d           %d   %d        %f\n",
                                   pounds, stones, uklbs, kilos);
        }
}

Again notice that the only function is called main.

int pounds; Creates a variable of integer type called pounds.

float kilos; Creates a floating point variable (real number) called kilos.

#define KILOS_PER_POUND .45359
defines a constant called KILOS_PER_POUND. This definition will be true throughout the program. It is customary to use capital letters for the names of constants, since they are implemented by the C preprocessor.

for(pounds=10; pounds < 250; pounds+=10)
This is the start of the loop. All statements enclosed in the following curly brackets will be repeated. The loop definition contains three parts separated by semi-colons.

    * The first is used to initialise variables when the loop is entered.
    * The second is a check, when it proves false, the loop is exited.
    * The third is a statement used to modify loop counters on each loop iteration after the first.

The effect of pounds += 10 is to add 10 to the value of the variable pounds. This is a shorthand way of writing pounds = pounds + 10.

The printf statement now contains the symbols %d and %f. These are instructions to print out a decimal (integer) or floating (real) value. The values to be printed are listed after the closing quote of the printf statement. Note also that the printf statement has been split over 2 lines so it can fit onto our page. The computer can recognise this because all C statements end with a semicolon.
Be Happy And Always Remain So

KeithBes

Слушай, приятель! Я в курсе, что ты раздумываешь, зачем тебе лазить по нашему веб-сайту, хотя давай-ка я поведаю для тебя почему это круто, а?
http://moldova.sports.md/football/europa_league/news/01-12-2023/154635/le_vse_goly_pervoj_vechernej_sessii_chetverga_mihael_gregorich_kroshit_oboronu_olimpiakosa/
 
 
 
 
 
Во-1-х, здесь ты найдешь вагон полезной инфы! Что бы ты ни искал - от советов по саморазвитию до лайфхаков для совершенствования обстановки - у нас есть все, что для тебя надо(надобно) для становления и вдохновения.
 
Хотя далеко не все! У нас здесь целое сообщество, как клуб "Без Карантина", где тебе предоставляется возможность общаться с крутыми ребятами, делиться своими идеями и получать поддержку в каждой ситуации.
 
А еще на нашем веб-сайте всегда что-то происходит! Промоакции, состязания, онлайн-мероприятия - в общем, все, дабы ты не заскучал и всегда оставался в курсе самых новых направленностей.
 
Так что, старина, не тяни кота за хвост! Загляни на наш вебсайт и давай совместно развиваться, общаться и веселиться! Я уверен, ты тут отыщешь себе на самом деле крутых друзей и море позитива!