Get Email Subscription

Enter your email address:

Delivered by FeedBurner

Thursday, December 31, 2009

Write a program in 'C' to enter sales man name and sales. Find and print commission where comm = 4% on sales



#include<stdio.h>
main()
{
char name [25];
float comm, sales;
printf("Enter name of sales man and sales\n");
scanf("%s %f", name, &sales);
comm = sales*4/100;
printf("The commission is %f", comm);
return(0);
}

For eg :-

Output :-
Enter name of sales man and sales
Fransis 10000
The commission is 400.000000
read more "Write a program in 'C' to enter sales man name and sales. Find and print commission where comm = 4% on sales"

Write a program in 'C' to enter the base (b) and height (h) of a traingle and to calculate and print the area (a) where area = 1/2*base*height



#include<stdio.h>
main()
{
float b, h, a;
printf("Enter the value for base and height\n");
scanf("%f %f", &b, &h);
a = 0.5* b*h;
printf("The area is = %f\n", area);
return(0);
}

For eg :-

Output :-
Enter the value for base and height
5 8
The area is = 20.000000
read more "Write a program in 'C' to enter the base (b) and height (h) of a traingle and to calculate and print the area (a) where area = 1/2*base*height"

Write a program in 'C' to enter the radius and calculate and print the area of Circle using the formula area = TT * (radius)2, where TT = 3.14



#include<stdio.h>
main()
{
float r, a;
printf("Enter the value of radius\n");
scanf("%f", &r);
a = 3.14*r*r;
printf("The area is %f\n", a);
return(0);
}

For eg :-

Output :-
Enter the value of radius
5
The area is 78.50000
read more "Write a program in 'C' to enter the radius and calculate and print the area of Circle using the formula area = TT * (radius)2, where TT = 3.14"

Wednesday, December 30, 2009

write a program in 'C' to enter three integers and print the maximum integer?



#include<stdio.h>
main()
{
int a, b, c, max;
printf("Enter three integers\n");
scanf("%d %d %d", &a, &b, &c);
max = (a>b)?a:b;
max = (max>c)?max:c;
printf("The maximum integer is = %d\n", max);
return(0);
}

For eg :-

Output :-

Enter three integers
12 20 50
The maximum integer is = 50
read more "write a program in 'C' to enter three integers and print the maximum integer?"

write a program in 'C' to enter three integers and print the minimum integer?



#include<stdio.h>
main()
{
int a, b, c, min;
printf("Enter three integers\n");
scanf("%d %d %d", &a, &b, &c);
min = (a<
b)?a:b;
min = (min<
c)?min:c;
printf("The minimum integer is = %d\n", min);
return(0);
}

For eg :-

Output :-

Enter three integers
12 20 50
The minimum integer is = 12
read more "write a program in 'C' to enter three integers and print the minimum integer?"

Write a progam in 'C' to enter two integers and to print the minimum integers?

#include<stdio.h>
main()
{
int x, y, min;
printf("Enter two unequal integers\n");
scanf("%d %d", &x, &y);
min = (x>y)?y:x;
printf("The minimum integer = %d\n", min);
return(0);
}

For eg :-

Output :-

Enter two unequal integers
25 35
The minimum integer = 25
read more "Write a progam in 'C' to enter two integers and to print the minimum integers?"

Write a progam in 'C' to enter two integers and to print the maximum integers?

#include<stdio.h>
main()
{
int x, y, max;
printf("Enter two unequal integers\n");
scanf("%d %d", &x, &y);
max = (x>y)?x:y;
printf("The maximum integer = %d\n", max);
return(0);
}

For eg :-

Output :-

Enter two unequal integers
25 35
The maximum integer = 35
read more "Write a progam in 'C' to enter two integers and to print the maximum integers?"

Write a 'C' program to enter two integers and to print thier sum?



#include<stdio.h>
main()
{
int a, b, s;
prinft("Enter two integers\n");
scanf("%d %d", &a, &b);
s = a + b;
printf("The Sum is %d\n", s);
return(0);
}

For eg :-

Output :-

Enter two integers
25 10
The Sum is 35
read more "Write a 'C' program to enter two integers and to print thier sum?"

How to type simple program in 'C'

Q.1) Write the output for the following in 'C' program

a) Happy New Year

Ans :-


#include<stdio.h>
mani()
{
printf(" Happy New Year");
return(0);
}

OutPut :-

Happy New Year
read more "How to type simple program in 'C'"

Tuesday, December 29, 2009

Rules Regarding 'C' Programm

1) At the beginning of the program we should include some header file with the help of #include statement.
For eg :-
#include<stdio.h>
#include<conio.h>
#include<math.h>

2) The first function is main( ) or void main( ).
If a program begins with main( ) then it should end with return(0);
If a program begins with void main( ) then return(0); is not necessary.

3) All the statement should be enclosed in a pair of braces as { and }

4) All the statement in 'C' should be written in lower case alphabets

5) The statement #include, #define, main( ) and void main( ) should not end with semi colon but all other statement must end with a semi colon.

6) The comment / remarks regarding a program should be enclosed with in /* */ marks. These comment can appear any where in the programm.
Note that :- A comment is a non-executable or non-programmable statement
For eg :- /* Calculation of Simple interest */

7) Blank spaces can be introduced between two words to improve the readability of the programm

8) After typing the entire programm to compile it press Alt + F9
To run the programm press ctrl + F9
To view the output press Alt + F5
read more "Rules Regarding 'C' Programm"

printf( ) function in 'C'

printf( ) :- This function is use to receive the output in the formatted manner. Format should be specified by the user. It is called as formatted output function. Having the following syntax :-

Syntax:-

printf("control string", arg1, arg2, arg3, ..........................................., argn);

The meaning of control string is same as scanf( ) but the argument in the above function should not begin with & (ampersand) symbol and the arguments are optional in the function.
read more "printf( ) function in 'C'"

scanf( ) function in 'C'

A) Formatted Input and Output ( )


1) scanf( ):- This is used in ‘C’ programming to supply the data in a fixed formatted. Hence it is the formatted input function in ‘C’. The format should be specified by the user.


The Syntax is:-


scanf(“control string”, arg1, arg2, arg3, …………., argn);



The control string gives the required formatting information. It must begin with the symbol % followed by a conversion character and a number specifying the width these number is optional.

Conversion Character
Meaning


d
the data item an integer value


f
the data item is a floating value


c
the data item is a Single Character


s
the data item is a string



The argument represent individual data item. If the argument contains variables name having integer or float value or a single character constant then such argument must begin with symbol & (ampersand).

If the argument contains a string constant then & (ampersand) is not required.
read more "scanf( ) function in 'C'"

Monday, December 28, 2009

Input and Output (I/O) Function in ‘C’

Input and Output (I/O) Function in ‘C’


To perform the task of supplying the data to a programme we use input function and to receive the result from the computer we used output function.These Input and Output function allowed transfer the data between the CPU and the standard Input and Output devices.The standard Input device is Keyboard.The standard Output device is Monitor or Screen.The Input and Output function are also called as library Function of ‘C’


The Input and Output function are of two types



A) Formatted Input and Output( )


B) Unformatted Input and Output( )



There are two types of Formatted Input and Output function


1) scanf( )


2) print( )



There are nine types of Unformatted Input and Output function



1) getch( )


2) getche( )


3) getchar( )


4) gets( )


5) putch( )


6) putchar( )


7) puts( )


8) sqrt( )


9) pow( )

read more "Input and Output (I/O) Function in ‘C’"

Header files in ‘C’

Header files in ‘C’:-

Most versions of ‘C’ include a collection of header files.
In which the necessary information is store to support the library function.
These files are include in the programme by using the #include statement at the beginning of the programme
For eg:-
#include<stdio.h>
#include<conio.h>
#include<math.h>

Meaning:-
1) <stdio.h> means the Standard input output header file.
2) <conio.h> means the Console input output header file.
3) <math.h> means the Mathematics header file.





read more "Header files in ‘C’"

Symbolic Constants in 'C'

Symbolic Constants in C

In ‘C’ programming there are some constant which are important in the programme. These constant can be made more clear by given them some proper name such constant are called as symbolic constant and they appear in #define statements.

#define is called a preprocessor directive in ‘C’

For eg:-


#define RADIUS 10


#define MARKS 100


#define TOTAL 500


#define COLLEGE Google School


#define HEIGHT 3.7


Rules to define symbolic Constants:-

  1. The preprocessor directive #define must appear before the symbolic constants.
  2. No space is allowed between # and define
  3. After the word #define a gap is necessary before the symbolic constant.
  4. After writing the constant a gap is necessary before the assigned value.
  5. These constants are written in upper case form.
  6. #define statement should not end with a semicolon.
read more "Symbolic Constants in 'C'"

Sunday, December 27, 2009

Operators in 'C'

Operators in ‘C’

These are the special symbol in ‘C’ which is used to do specific process. There are six types of operator in ‘C’ as follows:-

1. Arithmetic Operator
2. Relational Operator
3. Logical Operator
4. Conditional Operator
5. Unary Operator
6. Assignment Operator

1) Arithmetic Operator:-
They are used to do different arithmetic process as follows:-

Operators Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% modulo division
(Gives Remainder after division)

There are three types of Arithmetic operator namely
i. Integer Arithmetic
ii. Real Arithmetic
iii. Mixed mode Arithmetic

i. Integer Arithmetic:-
It involves only the integer values / operands and gives the result only in the integer form.
For eg: - a = 15, b = 4
Then a + b = 15 + 4 = 19
a – b = 15 – 4 = 11
a * b = 15 * 4 = 60
a / b = 15 / 4 = 3
a % b = 15 % 4 = 3

ii. Real Arithmetic:-
It involves all the real value (floating points) and gives the result only in the real form
For eg:- a = 3.2, b = 0.3, c = -0.1
Then a + b = 3.2 + 0.3 = 3.5
a – b = 3.2 – 0.3 = 2.9
a * c = 3.2 * -0.1 = 0.32
a / b = 0.3 / 3.2 = 0.093
a % b = This has no values (Invalid)
Note that modulo division % is not done on real operands

iii. Mixed Mode Arithmetic:-
It involves some integer values and some real value but the result is always in the real format
For eg: - 2.5 + 3 = 5.5
3.271 – 2 = 1.271
2 – 3.271 = -1.271
4.1 * 8 = 32.8
25 / 10.0 = 2.5
25.0 / 10 = 2.5
3.3 % 2 = This has no values (Invalid)

Note that modulo division % is not done on real as well as mixed mode operands


2) Relational Operator:- These are the symbol which are used to show various relation. They are as follows:-

Operators Meaning
= = Equal to
! = Not equal to
<> Greater than
> = Greater than or equal to

In ‘C’ when the relation is false the value is 0 (zero) and whenever the relation is true the value is 1 (one)

For eg:-
Let a = 20, b = 10, c = 5.
Then,

Expression Interpretation Value
a > c True 1
a + b < a =" =" c =" =" a =" 10," b =" 20," c =" 4"> c && b True 1
b / c = = c | | a False 0
a – b > -15 && -20 True 1
a < c =" (a"> b) ? 10 : 20
Means if a > b is true then c = 10
if a> b is false then c = 20


5) Assignment operators:-
These are used to assign different value to the variables.
Expression:-

=, + =, - =, * =, / =, % =

Expression Meaning
a = 10 Assign value 10 to variable a
b = 3.9 Assign value 3.9 to variable b
a + = b a = a + b
a - = b a = a – b
a * = b a = a * b
a / = b a = a / b
a % = b a = a % b

Assignment operators is also called as shorthand operators


6) Unary Operators:-
These operators are used on a single variable operand to produce the result.
There are two types of unary operators namely Increment or Decrement operator

+ + is called an increment operator which means increase the value by 1
- - is called decrement operator which means decrease the value by 1

There are post increment / decrement and pre increment / decrement.

For eg:-
Let b = 10
Find a and b each of the following case


1) a = b + +
+ + appears after the variable b .; it is the post increment operator.
. ; value of b is assigned to a first
. ; a = 10
And then value of b is increased by 1
. ; b = 11


2) a = + + b
+ + appears before the variable b .; it is the pre increment operator.
In this case value of b increased by 1 firstly and then this value is assigned to a
. ; b = 11 and a = 11



3) a = b - -
- - appears after the variable b . ; it is the post decrement operator
. ; value of b is assigned to a first
. ; a = 10
And the value of b is decreased by 1
. ; b = 9


4) a = - - b
- - appears before the variable b .; it is the pre decrement operator.
In this case value of b decreased by 1 firstly and then this value is assigned to a
. ; b = 9 and a = 9
read more "Operators in 'C'"

Constants in ‘C’


A) Numeric Constant


1) Integer Constant:-


They are whole number without any fractional part. They are represented by keyword (int). The default sign is (+)ve positive. But integer can be positive or negative. The range of integer constant depends upon the machine there are two type of integer constant, namely signed and unsigned.

The signed integer can be positive or negative but the unsigned integers are always considered as positive.

In order to provide some control over the range of integer and the available storage space. There are 3 classes of integers in ‘C’

i) Short int

ii) Int

iii) Long int (both signed & unsigned)


2) Real Constant:-


These are the constants which can have a decimal notation. The default signed is positive but number can be negative. They are represented by keyword (float). Hence they are also called as floating point or floating numbers. These numbers can also be represented in the exponential or scientific format as follows


mantissa e exponent


OR


mantissa E exponent


B) Numeric Constant:


1) Character constant:-


It is any single character enclosed in a pair of single quotes For eg:- ‘A’ ‘+’ ‘w’ ‘0’ etc.


Each character constant has a fixed integer value in ‘C’. These values are the ASCII values as the character constant have values it is possible to do Arithmetic operation on them.


2) String Constant:-


It is any sequence of character in ‘C’ enclosed in a pair of double quotes. It can be of any length. These constant are mainly use in programs. A compailer automatically places a null character \o at the end of every string constant.


Note that this null character cannot be seend on the monitor when the string in display on it.

read more "Constants in ‘C’"

Monday, December 21, 2009

Backslash Character Constants | Escape Sequence in ‘C’

These are the special character constant which are mainly used in the output function during ‘C’ programming. There are also called as Escape sequences some of them are as follows.

Escape sequences Meaning

1) \a audible alert

It alerts the user by sounding a bell through the speaker

2) \b back space

It moves the cursor to the left by one position

3) \n new line

It takes the cursor to the beginning of the new line or next line

4) \t tab

It moves the cursor to the next tab stop

5) \o null character

It gets attached at the end of every string constant.
read more "Backslash Character Constants | Escape Sequence in ‘C’"

Sunday, December 20, 2009

Variables in ‘C’ and Identifiers in ‘C’

Variables names are used to store a data value. A variable may take different value during program execution. A variable is defined by the user for eg: - marks, total, average, etc.

Rules to construct a variable
Every variable must begin with an alphabet
It may consist of alphabets or digits or the special symbols underscore _ but no other special symbol is allowed in it.
A variable can be maximum 31 character long but many computers recognize only first 8 characters and ignore the remaining characters
Variable can be written in upper case as well as lower case but note that they are not interchangeable. Hence ‘C’ is called as CASE SENSITIVE LANGUAGE for eg: - TOTAL, total, toTal, Total are taken as 4 different variables.
A Variable should not be a keyword.

Note that variables are also called as identifiers



Valid VariableInvalid VariableReasons
name "name" quotation marks not allowed
marks200 marks 200 space is not allowed
total_50total-50'
Single quotation marks not allowed
STUDENTS10 10STUDENTS It can not start with a digit




read more "Variables in ‘C’ and Identifiers in ‘C’"

Saturday, December 19, 2009

Keyword in ‘C’ / Storage Classes in ‘C’ / Basic data type in ‘C’

A keyword is that word in ‘C’ which has a fixed predefined meaning. Its meaning cannot be changed. Note that all keywords must be written in lowercase only. There are 32 standard keywords in ‘C’


autodoubleint switch
breakelselong struct
caseexternregistertypedef
constenumshort union
charforsigned unsigned
continuefloat staticvoid
dogotosizeof volatile
defaultwhileifreturn


read more "Keyword in ‘C’ / Storage Classes in ‘C’ / Basic data type in ‘C’"

Friday, December 18, 2009

Steps in learning 'C'

Introduction

C is a general-purpose computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system.

Although C was designed for implementing system software, it is also widely used for developing portable application software.

C is one of the most popular programming languages. It is widely used on many different software platforms, and there are few computer architectures for which a C compiler does not exist. C has greatly influenced many other popular programming languages, most notably C++, which originally began as an extension to C.

Steps in learning 'C'

Alphabets --> Words --> Sentence --> Paragraph


Characters --> keywords / Variable / Constant --> Statements --> Programme

Characters in 'C'

1) Alphabets :--> A, B, C . . . . . . . . Z (26)
a, b, c . . . . . . . . . z (26)

2) Digits :--> 0, 1, 2, 3 . . . . . . . . . . 9 (10)

3) Special Symbols :-->

There are 31 Charcters as follows :-->
+ \ : (
- # ; )
/ < " {
* > ' }
% ^ , [
= _ . ]

This is 'C' has in all 93 Character

read more "Steps in learning 'C'"

About This Blog

Lorem Ipsum

  © Blogger templates Newspaper III by Ourblogtemplates.com 2008

Back to TOP