Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,860 questions

51,781 answers

573 users

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

1 Answer

0 votes
#include <stdio.h>

int main()
{
    int count = 1, num = 10;

start: //label

	printf("num: %2d : Square: %3d : Cube: %4d\n", count, (count * count), (count * count * count));
	count++;

	if (count <= num)
		goto start;

	return 0;
}



/*
run:

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

*/

 



answered Dec 19, 2023 by avibootz

Related questions

1 answer 126 views
1 answer 149 views
1 answer 142 views
1 answer 167 views
1 answer 125 views
...