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

In this C program, we are going to learn how to find and print the square, cube of all numbers from 1 to N using goto statement in C language?
Submitted by Manju Tomar, on November 09, 2017

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.

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.

C Goto Programs »


Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.