simple example of one if statement. Another If statement is the if -else statement. This can be shown as this
example-6
if(cost >40000)
{
luxury=cost*0.005;
printf("The luxury tax is %.2f",luxury);
}
else
{
puts("There is no luxury tax for the items");
luxury=0.0;
}
Now the format a do statement is as follows:
do
{
instruction;
instruction
}
while(condition);
The format for a FOR statement is as follows:
for(initial=value;condition;increment)
instruction;
Now for an example:
example-7
main()
{
int row,column;
puts("\t\tMY Handy multipication table");
for(row=1;tow<=10;row++)
{
for(column=1;column<=10;column++)
printf("%6d", row*column);
putchar('\n');
}
}
The output is a multipication table of 10x10 size.
example-8
main()
{
int temp;
float celsius;
char repeat;
do
{
printf("Input a temperature:");
scanf("%d", &temp);
celsius=(5.0/9.0)*(temp-32);
printf(%d degrees F is %6.2f degrees celsius\n",temp, celsius);
printf(("do you have another temperature?");
repeat=getchar();
putchar('\n');
}
while(repeat=='y'|| repeat=='y');
}
This shows you to how to use the do command for conditional programming in c.
example-8
main()
{
int temp;
float celsius;
char repeat;
do
{
printf("Input a temperature:");
scanf("%d", &temp);
celsius=(5.0/9.0)*(temp-32);
printf(%d degrees F is %6.2f degrees celsius\n",temp, celsius);
printf(("do you have another temperature?");
repeat=getchar();
putchar('\n');
}
while(repeat=='y'|| repeat=='y');
}
This shows you to how to use the do command for conditional programming in c.
No comments:
Post a Comment