Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Sunday, July 10, 2022

Basic input output statement of C programming for SEE and NEB

 Basic Input/Output statement of C programming for SEE and NEB


Statements are special commands which are used to write the program.  There are some statements are used in C they are here as here:   

i) Comment statement : (/*…..*/  or //…..)

            This statement is used to put the remarks in the program.

            /* this is the test of the C program */

                                    or

            // This is the test of the C program

                                    or

            /* This is the test of

                C program */

 

ii) printf ( ) :

This command/function is used to display the formatted output on the screen. This statement is known as a formatted output statement.

Command Line:  printf( );

Syntax:

printf( “message”);

printf(“message control string”, variable);

Library: stdio.h

 

Control String:

C formatting commands that are used to input and output require control strings.  Different types of data types are represented by control strings.  Some of them are as follows:

Control string

Used for

%d

Integer type variable value

%u

Unsigned integer variable value

%f

Float type variable value

%c

Single char type

%s

String type char value

 

Example:

//Write a program to display “Well Come To C”

#include<stdio.h>

void main()

{

printf("Well Come To C ");

}

 

//Write a program to display the addition and average of two integers.

#include<stdio.h>

#include<conio.h>

void main()

{

int a=5;

int b=23;

int c;

float av;

c=a+b;

av=c/2;

clrscr();

printf("First number=%d",a);

printf("\n Second number=%d",b);

printf("\n Sum of two numbers=%d",c);

printf(\n Average of two numbers%f",av);

}

iii) scanf ( ): 

This command is used to accept the input from the standard input device such as a keyboard. It is also known as a formatted input statement.

Library:           stdio.h

Syntax:            scanf(“control string”, variable);

Note:   Use & before variable name if the variable is numeric (int, float, double) or single char type.

Example:

WAP to input principal amount, time, and rate of interest from the keyboard and display simple interest with the actual amount to be paid.

Using "C" Language

Using QBASIC

#include<stdio.h>

#include<conio.h>

void main()

{

int p,t,a;

float r,si;

clrscr();

printf("\n enter principle amount=");

scanf("%d",&p);

printf("\nenter rate=");

scanf("%f",&r);

printf("\n enter time=");

scanf("%d",&t);

si=p*t*r/100;

a=p+si;

printf("\n simple interest is=%f",si);

printf("\n Actual amount to be paid=%d",a);

getch();

}

CLS

INPUT "Enter principal amount";p

INPUT "Enter time";t

INPUT "Enter rate";r

Si=(p*t*r)/100

A=p+si

PRINT "Simple interest";si

PRINT "Actual amount to be paid";a

END

 

 

 

Output:

 


 

iii) clrscr( ) :

This statement/function is used to clear the screen.

Command line:            clrscr( );

Library :                      conio.h           

Syntax:                        clrscr( );

 

iv) getch ( )

This statement/ function is used to accept a single character from the keyboard but doesn’t display it on the screen.

Library:                       conio.h

Syntax:                        char c= getch( );

 

v) gets() and puts():

gets() statement is used to read strings or words. This statement is an unformatted input statement.

Syntax:            gets(string expression)

puts() statement is used to display the string or word in the monitor. This statement is an unformatted output statement.

Syntax:            puts(string expression)

           

Example:

            WAP to input your name and display it.

            #include<stdio.h>

            #include<conio.h>

            void main()

            {

                        char name[20];

                        printf("\n enter your name");

gets(name);

printf("\n Hello");

puts(name);

getch();

}         

 

vi) getchar() and putchar()

getchar(): This statement is used to read single character from the keyboard. This statement is unformatted input statement

Example Program

#include<stdio.h>

#include<conio.h>

 main()

{

   char ch;

   printf("\nEnter any character : ");

   ch = getchar();

   printf("\nYou have entered : %c\n",ch);  

}

 

putchar() : The putchar() statement  is used to display a single character on the screen. This statement is an unformatted output statement.

Syntax:

putchar(ch);

Example Program

#include<stdio.h>

#include<conio.h>

main()

{

   char ch = 'A';

   putchar(ch);  

}

 

 

 

 

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages