Monday, December 10, 2007

How to use variable and constant

How to use variable and constant

To use variable and constant

#include

#define GRAMS_PER_POUND 454

const int CENTURY = 2000;

long weight_grams, weight;

int year, age2000;

main()

{ printf("Enter your weight here : ");

scanf("%d", &weight);

printf("Enter your year of birth: ");

scanf("%d", &year);

weight_grams = weight * GRAMS_PER_POUND;

age2000 = CENTURY - year;

printf("\nYour weight in is = %ld", weight);

printf("\nIn 2000 you will be %d years old\n", age2000);

return 0;

}

Result :

How to compare number in C++ using If nested loop

How to compare number in C++ using If nested loop

To compare number in C++ using If nested loop

#include

int first, second;

int main()

{ printf("\nInput an integer value for 1st number : ");

scanf("%d", &first);

printf("\nInput an integer value for 2nd number : ");

scanf("%d", &second);

if (first == second)

printf("first number is equal to second number\n");

if (first > second)

printf("first number is greater than second number\n");

if (first <>

printf("first number is smaller than second number\n");

return 0;

}

Result :

How to differential x+ and ++x, yand --y

How to differential x+ and ++x, yand --y

To differential x+ and ++x, yand --y

#include

int x, y ;

main()

{x= y= 9;

printf("\n%d %d", x--, --y);

printf("\n%d %d", x--, --y);

printf("\n%d %d", x--, --y);

printf("\n%d %d", x--, --y);

printf("\n%d %d\n", x--, --y);

return 0;

}

Result :


How to do some calculation

How to do some calculation

To do some calculation

#include

int main( )

{ int x, y, z;

cout << "Please enter TWO numbers for the calculation :\n";

cout << "1st number is : ";

cin >> x;

cout << "2nd numbers is : ";

cin >> y;

(z = (x*y));

cout << "1st number is " <<>

cout << "\n"<<"So, when 1st number MULTIPLY by 2nd number...it equal to ";

cout<<>

return 0;

}

Result :