For Loop example


#include <stdio.h>

int main () {

    int i = 0, k = 0;
    float j = 0;
    int loop_count = 5;

    printf("Case1:\n");
    for (i=0; i < loop_count; i++) {
        printf("%d\n",i);
    }

    printf("Case2:\n");
    for (j=5.5; j > 0; j--) {
        printf("%f\n",j);
    }

    printf("Case3:\n");
    for (i=2; (i < 5 && i >=2); i++) {
        printf("%d\n",i);
    }

    printf("Case4:\n");
    for (i=0; (i != 5); i++) {
        printf("%d\n",i);
    }

    printf("Case5:\n");
    /* Blank loop  */
    for (i=0; i < loop_count; i++) ;

    printf("Case6:\n");
    for (i=0, k=0; (i < 5 && k < 3); i++, k++) {
        printf("%d\n",i);
    }

    printf("Case7:\n");
    i=5;
    for (; 0; i++) {
        printf("%d\n",i);
    }

    return 0;
}
 Case1:
0
1
2
3
4
Case2:
5.500000
4.500000
3.500000
2.500000
1.500000
0.500000
Case3:
2
3
4
Case4:
0
1
2
3
4
Case5:
Case6:
0
1
2
Case7:
 
 

3 comments:

  1. //Write a program to illustrate the use of For Loop


    #include

    int main ()

    {
    int i = 0, k = 0,loop_count = 10;
    float j = 0;


    printf("number-1:\n"); for (i=0; i < loop_count; i++)
    {
    printf("%d ",i);
    }

    printf(" \n\nnumber-2:\n"); for (j=5.9; j > 0; j--)
    {
    printf("%f ",j);
    }

    printf("\n\nnumber-3:\n"); for (i=2; (i < 12 && i >=2); i++)
    {
    printf("%d ",i);
    }

    printf("\n\nnumber-4\n"); for (i=0; (i != 11); i++)
    {
    printf("%d ",i);
    }

    printf("\n\nnumber-5:\n");/* Blank loop*/for (i=0; i < loop_count; i++) ;
    {
    printf("%d\n",i);
    }

    printf("\nnumber-6:\n"); for (i=0, k=0; (i < 10 && k <20); i++, k++)
    {
    printf("%d ",i);
    }

    printf("\nnumber-7:\n"); for (i=5; ;i++) if(i=1000) break;

    {
    printf("%d\n",i);
    }

    return 0;
    }

    ReplyDelete

  2. #include

    int main ()
    {

    int a = 0, c = 0;
    float b = 0;
    int loop_count = 5;

    printf("Case1:\n");
    for (a=0; a < loop_count; a++)
    {
    printf("%d\n",a);
    }

    printf("Case2:\n");
    for (b=5.5; b > 0; b--)
    {
    printf("%f\n",b);
    }

    printf("Case3:\n");
    for (a=2; (a < 5 && a >=2); a++)
    {
    printf("%d\n",a);
    }

    printf("Case4:\n");
    for (a=0; (a != 5); a++)
    {
    printf("%d\n",a);
    }

    printf("Case5:\n");
    /* Blank loop */
    for (a=0; a < loop_count; a++) ;

    printf("Case6:\n");
    for (a=0, c=0; (a < 5 && c < 3); a++, c++)
    {
    printf("%d\n",a);
    }

    printf("Case7:\n");
    a=5;
    for (; 0; a++)
    {
    printf("%d\n",a);
    }

    return 0;
    }

    ReplyDelete

  3. #include

    int main ()
    {

    int a = 0, c = 0;
    float b = 0;
    int loop_count = 5;

    printf("Case1:\n");
    for (a=0; a < loop_count; a++)
    {
    printf("%d\n",a);
    }

    printf("Case2:\n");
    for (b=5.5; b > 0; b--)
    {
    printf("%f\n",b);
    }

    printf("Case3:\n");
    for (a=2; (a < 5 && a >=2); a++)
    {
    printf("%d\n",a);
    }

    printf("Case4:\n");
    for (a=0; (a != 5); a++)
    {
    printf("%d\n",a);
    }

    printf("Case5:\n");
    /* Blank loop */
    for (a=0; a < loop_count; a++) ;

    printf("Case6:\n");
    for (a=0, c=0; (a < 5 && c < 3); a++, c++)
    {
    printf("%d\n",a);
    }

    printf("Case7:\n");
    a=5;
    for (; 0; a++)
    {
    printf("%d\n",a);
    }

    return 0;
    }

    ReplyDelete