Thursday, January 1, 2015

loop-Basic(3)

1:
#include <stdio.h>
///***Basic for loop:

int main()
{
int a;
for(a=1;a<=5;a++)
    printf(" %d ",a);
return 0;
}

output: 1 2 3 4 5

2:
#include <stdio.h>
///while loop:

int main()
{
int a=1;
while(a<=5){
    printf(" %d ",a);
    a++;
}
return 0;
}

output: 1 2 3 4 5 

3:
#include <stdio.h>
///loop statement:

int main()
{
int a=1;
loop:
    printf(" %d ",a);
    a++;
    if(a<=5)
        goto loop;
    return 0;
}



output: 1 2 3 4 5 

4:
#include <stdio.h>
///do loop:

int main()
{
int a=1;
do{
    printf(" %d ",a);
    a++;
}
while(a<=5);
return 0;
}

output: 1 2 3 4 5

No comments:

Post a Comment