Can we use char/float variable for indexing of array elements? For ex,
int arr[10];
arr[ j ] =3;
whether j can be of type char or float?
Thursday, February 14, 2008
Thursday, January 31, 2008
C prog to find remainder of a number
This prog finds remainder of a number without using divisor (/), modulus (%) or multiplication (*) operator.
#include
#include
main()
{
int a,b;
printf("enter the value of Dividend=");
scanf("%d",&a);
printf("enter the value of divisor=");
scanf("%d",&b);
if(a>=b)
{
while(a-b>=b)
{
a=a-b;
}
printf("the reminder is =%d",a-b);
}
else
printf(" Dividend must be greater than divisor");
getch();
}
#include
#include
main()
{
int a,b;
printf("enter the value of Dividend=");
scanf("%d",&a);
printf("enter the value of divisor=");
scanf("%d",&b);
if(a>=b)
{
while(a-b>=b)
{
a=a-b;
}
printf("the reminder is =%d",a-b);
}
else
printf(" Dividend must be greater than divisor");
getch();
}
Tuesday, January 29, 2008
C prog to find remainder of a number
A C prog to find remainder of a number without using division (/) or modulus (%)operator.
Friday, January 25, 2008
C prog without a single Semicolon
Yes why not, we can absolutely write a C prog without using a semicolon and having at least one
executable statement.
main()
{
if(printf("hello suriya"))
{
}
}
Another way. (here notice the use of comma operator described in previous post)
main()
{
while(printf("hello suriya"),0)
{
}
}
executable statement.
main()
{
if(printf("hello suriya"))
{
}
}
Another way. (here notice the use of comma operator described in previous post)
main()
{
while(printf("hello suriya"),0)
{
}
}
Monday, January 21, 2008
C prog without semicolon??
Is it possible to write a C prog without using a single semicolon?
(prog must contain at least one executable statement, say just displaying a hello message)
(prog must contain at least one executable statement, say just displaying a hello message)
Wednesday, January 9, 2008
The Comma Operator
Can U predict output of this program:
void main()
{
int p=3,q=5,x,y;
x = p,q;
y = (p,q);
printf ("%d %d",x,y);
}
a. 3 5
b. 5 5
c. 3 3
d. 5 3
e. None (may be error)
The ans is a. 3 5
The comma separates the elements of a function argument list. The comma is also used as an operator in comma expressions. Mixing the two uses of comma is legal, but you must use parentheses to distinguish them. the left operand E1 is evaluated as a void expression, then E2 is evaluated to give the result and type of the comma expression. By recursion, the expression
E1, E2, ..., En
results in the left-to-right evaluation of each Ei, with the value and type of En giving the result of the whole expression.
void main()
{
int p=3,q=5,x,y;
x = p,q;
y = (p,q);
printf ("%d %d",x,y);
}
a. 3 5
b. 5 5
c. 3 3
d. 5 3
e. None (may be error)
The ans is a. 3 5
The comma separates the elements of a function argument list. The comma is also used as an operator in comma expressions. Mixing the two uses of comma is legal, but you must use parentheses to distinguish them. the left operand E1 is evaluated as a void expression, then E2 is evaluated to give the result and type of the comma expression. By recursion, the expression
E1, E2, ..., En
results in the left-to-right evaluation of each Ei, with the value and type of En giving the result of the whole expression.
Tuesday, January 8, 2008
Careful with arithmetic operation of dissimilar data types
Check the following prog:
main()
{
float result;
result =50/100;
printf("%f",result);
}
what is the output?
The output is not like this: 0.50000
The output is 0.000000
because
int/int = int
so change the program to
main()
{
float result;
result=50/100.0;
printf("%f",result);
}
the above programm is (int/float)
so the output is now 0.500000
conclusion:
int/int = int
int/float = float
float/int = float
float/float = float
The above table can be summarized as: integer division takes place only when both elements are integers.
Monday, January 7, 2008
Welcome
Hi
Welcome to the world of programming. "C is Sea" and it is 100% true. After teaching for almost 6 years to many students , I still feel that I am just at the surface of this sea.
In this blog, I will share my experience and will try to give some tips.
Rest on any other day
Suriya
Welcome to the world of programming. "C is Sea" and it is 100% true. After teaching for almost 6 years to many students , I still feel that I am just at the surface of this sea.
In this blog, I will share my experience and will try to give some tips.
Rest on any other day
Suriya
Subscribe to:
Posts (Atom)