list of data type identifiers :
%f=float %c=char %s =s tring %e=inputs number in scientific notation.
As you saw in the first hour of our tutorial c is a language in which you program using functions. Functions are usually identified by the following characteristic:>> functionname() In c the main() function is essential. Think of it as a constant function for all your programs and all other functions can be accessed from the main().Before I show you how we do that let us have an example where we want to pause a program before the screen is changed. This would involve the foll- owing procedure:>> write a main function then use puts function to put statements on the screen like we did in section 1 above and then before the next set of puts statements declare a pause.
This is how it is done:
example-4
main()
{
puts("hello there");
puts("what is your name?")
pause()
puts("It is nice to meet you")
}
pause();
{
int move_on;
printf("press entere to continue");
move_on=getchar();
return(0);
}
This above will pause until a key is pressed on the keyboard. Granted that the above program makes no sense from a practical point of view but I want to show is the use of another function inside the main function.
C has many functions that comes with it. See your compiler manual to see what you have.Now we are going to look at conditions in c programming:>> the if command and do command.
Here is an example of th if command:
example-5
main()
{
float cost,tax,luxury,total;
luxury=0.0;
printf("Enter the cost of the item: ");
scanf("%f", &cost);
tax=cost*0.06;
if(cost>40000.0)
luxury=cost*0.005;
total=cost+tax+luxury;
printf("the total cost is %0.2f",total);
}
No comments:
Post a Comment