DO NOT MISS

Ads

Monday 1 August 2016

For Loop with C-Programs



It is the most commonly used loop statement in C language. It consisting of three expressions.
Syntax :-

for(initialize;condition;inc/dec)
{
Statements;
}


Flow Chart:-

Note:-

1. First it initialize the value of variable and then goes to condition.

2. If the condition is true it executes true statement and then goes to increment or decrements statement.
3. After increase or decrease the value and then goes to condition.
4. This process will be continued until the specified condition will be false.

Programs:-

* Write a program to print 1 to 10 no's in ascending order.


#include<stdio.h>
#include<conio.h>

void main()

     {

         int i;
         clrscr();

         
for(i=1;i<=10;i++)

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

         getch();

     }

Output:-


* Write a program to print n natural no's in ascending order.

#include<stdio.h>
#include<conio.h>

void main()

      {

           int n,i;
           clrscr();

           printf("enter n value: ");
           scanf("%d",&n);

         
 for(i=1;i<=n;i++)

           printf("%d\t",i);

           getch();

      }



Output:-



* Write a program to print n natural no's in descending order.

#include<stdio.h>
#include<conio.h>

void main()

      {

         int n,i;
         clrscr();

         printf("enter n value: ");
         scanf("%d",&n);

         
for(i=n;i>=1;i--)

         printf("%d\t",i);

         getch();

      }



Output:-




* Write a program to print Sum of 1 to 10 Numbers.

#include<stdio.h>
#include<conio.h>

void main()

      {

           int i,sum=0;
           clrscr();

         
 for(i=1;i<=10;i++)

                 {
                      sum=sum+i;
                 }

           printf(“The sum of integer from 0 to 10 is: %d”,sum);

          getch();

      }



Output:-



* Write a program to print n multiplication table.

#include<stdio.h>
#include<conio.h>

void main()

    {

          int i,n;
          clrscr();

          printf(“enter the no:”);
          scanf(“%d”,&n);

         
for(i=1;i<=10;i++)

               {
                     printf(“%d*%d=%d\n”,n,I,n*i);
               }

         getch();

    }



Output:-


______________________________________________________
______________________________________________________
_____________________________________________________
>> Back to C-Language Notes (Topic Wise)
___________________________________________________


Greataims

 
Copyright © 2016 Computersadda. Designed by @ Computersadda Team - Published By Greataims