Q:

C program to print square and cube of all numbers from 1 to N using goto statement

0

C program to print square and cube of all numbers from 1 to N using goto statement

Given the value of N and we have to print square and cube of all numbers between 1 to N using C language goto statement.

goto is a jumping statement, which transfers the program’s control to specified label, in this program, we are going to read the value of N and printing the square, cube of all numbers between 1 to N.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to print Square and Cube of all numbers from 1 to N using goto in C

#include<stdio.h>

int main()
{
	int count,n;

	printf("Enter the value of N: ");
	scanf("%d",&n);
	
	count=1;
	
	start:
	printf("num: %4d, Square: %4d, Cube: %4d\n",count,(count*count),(count*count*count));
	count++;

	if(count<=n)
		goto start;

	return 0;
}

Output

Enter the value of N: 10
num:    1, Square:    1, Cube:    1
num:    2, Square:    4, Cube:    8
num:    3, Square:    9, Cube:   27
num:    4, Square:   16, Cube:   64
num:    5, Square:   25, Cube:  125
num:    6, Square:   36, Cube:  216
num:    7, Square:   49, Cube:  343
num:    8, Square:   64, Cube:  512
num:    9, Square:   81, Cube:  729
num:   10, Square:  100, Cube: 1000

This is how we can find the square and sum from 1 to N, using goto statement? If you liked or have any issue with the program, please share your comment.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C program to print 1, 11, 31, 61, ... 10 times usi... >>
<< C program to read a name and print its 10 times us...