Monday, 12 July 2010

Example program for comma operator in for loop

#include<stdio.h>
#include<conio.h>
void main()
{
 int i,j,n;
 printf("enter a number n\n");
 scanf("%d",&n);
 //illustraiton of comma operator
 for(i=0,j=n;i<=n;i++,j--)
 printf("%d+%d=%d\n",i,j,n);
 getch();
}
/*output
Enter a no: 5
0+5=5
1+4=5
2+3=5
3+2=5
4+1=5
5+0=5
*/

You may like the following posts:
Loops
Operators and Expressions

No comments:

Post a Comment