Jumping statements (Programs)

 Program with Goto statements to print (6 no.s)

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

void main()
{
    int c=1;
    start:
    if (c<7)
    {
        c=c+1;
    printf("\n c= %d",c);
    goto start;
    }
}

Output:
















Program with continue statement to skip 5 from output of 1-10

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

void main()
{
    int c=0;
    for( int i=1;i<=10;i++)
    {
        c++;
        if(i==5)
        {
            continue;
        }
        printf("\nc=%d",c);
    }
}

Output:













Program with break statement (it will break to the parent condition)

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

void main()
{
    int c=0;
    for( int i=1;i<=10;i++)
    {
        c++;
        if(i==5)
        {
            break;
        }
        printf("\nc=%d",c);
    }
}

Output:











Program with return statement:

#include<stdio.h>
int add(int c,int b)
{
    return c+b;
}
void main()
{
    int a,b,c;
    a=10;
    b=30;
    c=add(a,b);
    printf("addition = %d",c);
}

Output:








No comments:

Post a Comment