Search This Blog

Monday, April 30, 2012

Standard Input


Standard Input

scanf() Function

scanf() function reads data from a standard input device into arguments specified by the format string.


scanf(format string, arguments)

1.


/* Input through the keyboard */
#include <stdio.h>
#include <conio.h>
void main()
{
int x,y,sum;
clrscr();
printf("Enter an Integer:");
scanf("%d",&x);
printf("Enter another:");
scanf("%d",&y);
sum = x + y ;
printf("sum =%d \n",sum);
}

2.



/* Floating point Numbers */
#include <stdio.h>
#include <conio.h>
main()
{
float x,y,sum;
clrscr();
printf("Enter a number:");
scanf("%f",&x);
printf("Enter another:");
scanf("%f",&y);
sum = x + y ;
printf("sum =%.2f \n",sum);
}

Friday, April 27, 2012

putchar()


putchar()

Try these codes........

putchar() - putchar() is a macro that outputs a character on stdout.

Eg:-1
/* Output a Character */
#include <stdio.h>
#include <conio.h>
#define msg "End of Program"
void main()
{
char a ;
clrscr();
a =100;
printf("%d\n",a);
putchar(a);
putchar(10);
putchar(13);
putchar(a+1);
puts(msg);
}


Eg :-2

/* Area of a circle */
#include <stdio.h>
#include <conio.h>
void main()
{
int r ;
float pi;
clrscr();
pi = 22/7.;
r = 7;
printf("%s%5.2f \n","The area of the circle =" ,pi*r*r);
}


Friday, April 13, 2012

Variable Declaration


Variable Declaration


some examples for you to try..........

Eg.1

 /* Adding two integers */
#include <stdio.h>
#define msg “End of Program”
void main()
{
int a,b,c;
clrscr();
a=2;
b=3;
c=a+b;
printf(“%d%s%d%s%d\n”,a,”+”,b,”=”,c);
puts(msg);
}



Eg:2

/* Adding Two Floating Point Numbers */
#include <stdio.h>
#define msg "End of Program"
#include <conio.h>
void main()
{ int a ;
float b;
clrscr();
a=123;
b=123;
printf("%5d\n",a);
printf("%+05d\n",a);
printf("%.5f\n",b);
puts(msg);
}

Saturday, April 7, 2012

Variable


Variable


 A variable is a named memory location in the computer’s memory where different values of a certain type of data can be stored.

Variable Names

In C, a name given to a variable must satisfy the following rules.

 The name can contain letters, digits and the underscore character.

The first character of the name must be an alphabet or an underscore. However the use of
an underscore is not recommended.

 C is case sensitive. So C treats X and x as two different variables.

Keywords cannot be used as variable names

C compilers allow long variable names. However most of the C compilers recognize the first 32 characters.
In C / C++ it is necessary to declare variables before they are used in a program. When a variable is
declared it is designated as belonging to one of the data types used in C. The compiler allocates memory
for the variable according to its data type.

                     Declaration                              Memory Allocation in Bytes
Eg:                     int a;                                                            2
                          char ch;                                                       1
                         float salary;                                                   4

Sunday, April 1, 2012

Symbolic Constants


Symbolic Constants


A symbolic constant is a constant that is represented by a symbol (name) in a program. A non numeric constant may consist of letters, digits, and other characters.

The literals enclosed in single quotes are referred to as character values. Others those enclosed in double quotes are called character strings. In C you can use a name to represent a constant. The value associated with a constant cannot be changed or reassigned.


‘a’, ‘b’, ‘,’, ‘;’ - character constants.
“Hello”, “Information”, “31/12/1999” - string constants.

Numeric constants in C are made up of digits and can include decimal points and contain letters and do not
have single or double quotes.

Constants can be defined by using by using the # define construct.


 # define a 10
# define ch ‘a’
# define msg “End of Program”