Thursday, January 1, 2015

loop(5)

1:
#include <stdio.h>
///***while loop using increment operator:
int main()
{
int a,b;
    scanf("%d %d",&a,&b);
    while(a<=b){

        printf("%d ",a);
        a++;
}
return 0;
}

input:1 5
output:1 2 3 4 5

2:
#include <stdio.h>
///***loop break:
int main()
{
int i;
for(i=0;i<=5;i++){
    printf("% d ",i);
    if(i==3)
        break;
}
return 0;
}

output: 0 1 2 3

3:
#include <stdio.h>
///***loop break:
int main()
{
int i;
for(i=0;i<=5;i++){
        if(i==3)
        break;
    printf("% d ",i);
}
return 0;
}


output: 0 1 2

No comments:

Post a Comment