0% found this document useful (0 votes)
7 views5 pages

Break, Continue, Goto

The document contains multiple C programming exercises demonstrating the use of control statements such as break, continue, and goto. It includes programs for displaying numbers, calculating sums, filtering negative numbers, and checking if a number is even or odd. Each program is presented with its code and a brief description of its functionality.

Uploaded by

tejasbhore24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

Break, Continue, Goto

The document contains multiple C programming exercises demonstrating the use of control statements such as break, continue, and goto. It includes programs for displaying numbers, calculating sums, filtering negative numbers, and checking if a number is even or odd. Each program is presented with its code and a brief description of its functionality.

Uploaded by

tejasbhore24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Q.

1 Write a C program to display 10 numbers using break statement


#include<stdio.h>

int main ()

int i;

for(i = 0; i<=100; i++)

printf("%d ",i);

if(i == 10)

break;

printf("\nAs ordered, came outside of loop after %d", i);

return 0;

Q.2 Write a C program to calculate the sum of n numbers until user enters 0 using break
statement
#include <stdio.h>

int main()

int i, num, sum = 0;

for (i=0; i<= 100; i++)

printf("Enter a number: ");

scanf("%d", &num);

sum += num;

if (num == 0)

break;

printf("Total = %d",sum);
return 0;

Q.3 Write a C program to read 5 numbers from the user & display only -ve numbers skip the
+ve numbers using continue statement
#include <stdio.h>

int main()

int i, num[5];

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

printf("Enter number: ");

scanf("%d",&num[i]);

printf("Displaying the result: ");

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

if(num[i]<0)

printf("%d\n", num[i]);

return 0;

}
Q.4 Write a C program to display 1 to 10 numbers & skip the 5th number using continue
#include <stdio.h>

int main()

int i, num[10];

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

printf("Enter number: ");

scanf("%d",&num[i]);

printf("Displaying the result: ");

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

if(i==5)

continue;

printf("%d\n", num[i]);

return 0;

}
Q.5 Write a C program to print whether the number is even or odd using goto statement
#include <stdio.h>

int main()

int num;

printf("Enter a number\n");

scanf("%d", &num);

if (num % 2 == 0)

goto even;

else

goto odd;

even:

printf("%d is even\n", num);

exit(0);

odd:

printf("%d is odd\n", num);


return 0;

You might also like