Basic Output, Input Statement, Defining constant

OUTPUT STATEMENT:

printf("string",arguments);

In printf(), f stands for function. This statement is used for printing messages as well as values of variable, expression can be printed on the output screen. It can also contain the control strings to indicate the type of value to be printed. We can also include arguments (i.e. variables or expressions)  whose value has to be printed. 

/* WAP (WRITE A PROGRAM) TO PRINT MESSAGE. */

#include< stdio.h >
#include< conio.h >
main()
{
clrscr(); /*Function to clear output screen */
printf(" DICE");
printf(" Gadag Road");
printf(" Koppal");
getche(); /* Output will be paused until you press any key*/
}

o/p: DICE Gadag Road Koppal

/*WAP TO PRINT MESSAGE IN DIFFERENT LNES */

#include < stdio.h >
#include< conio.h >
main()
{
clrscr();
printf("\n DICE");
printf("\n Gadag Road");
printf("\n Koppal");
getche();
}
o/p:
DICE
Gadag Road
Koppal


·         wap to print your address.
·         wap to print your college address.
·         wap to print any 5 friend names.
·         wap to print your subject names.
·         wap to print any 10 state names.
·         wap to print any 10 historical places.
·         wap to print any 10 names of kingdoms.
·         wap to print computer part names.
·         wap to print any 10 college names present in your city.
·         wap to print any top 10 companies of mobile.



INPUT STATEMENT:


        scanf() statement is used to make the user to input values and these values will be stored into specified arguments and later these can be used in program for different purposes.

  scanf("control strings",arguments);

where control strings are special character to denote the type of value like


%d for integer type

%f for floating point number

%c for character

%s for string

%ld for long integer

%u for unsigned integer

etc.,

& arguments are variable names. These values are stored in memory locations. These locations are accessed by these variable name.

/* Example for reading and printing a single integer number*/

#include< stdio.h >
#include < conio.h >
main()
{
int a;
clrscr();

printf("\nEnter the value for a");
scanf("%d",&a);

printf("\nvalue of a is %d",a);
getche();
}

/* Example for reading and printing a single real number*/

#include< stdio.h >
#include< conio.h >
main()
{
float a;
clrscr();

printf("\nEnter the value for a");
scanf("%f",&a);

printf("\nvalue of a is %f",a);
getche();
}

In the above program you can observe that int is replaced by float and all %d are replaced by %f control string. Similarly you can try for reading and printing a character by replacing int by char and %d by %c.

Some more simple programs, 

/* wap to add two numbers c=a+b*/
#include < stdio.h >
main()
{
int a,b,c;


printf("\nEnter the value for a and b ");
scanf("%d%d",&a,&b);

c=a+b;

printf("\na=%d\nb=%d\nc=%d",a,b,c);

}

In the above program initially 3 variables including two input (a and b) and output (c) are declared as integers. Then we are accepting input values from the user and these values are substituted into the formula c=a+b and output is printed.
 



Similarly you can try following,
 

c=a-b
c=a*b
c=a/b
d=a+b+c
e=a*b*c*d


Defining constants: 

It means providing a symbolic name for a constant value so that the reader feels comfortable to read programs. There are two ways for defining constants namely

1. #define symbolicname constantvalue

2. const type symbolicname=constantvalue;

Ex:

#define pi 3.142

const float pi=3.142;

Solve the following problem,
area=pi*r^2




Comments