C program to print ASCII values of all digits using goto statement

In this program, we are going to learn how to print ASCII values of all digits using goto statement?
Submitted by Manju Tomar, on November 19, 2017

Problem statement

We have to print ASCII values of all digits along with digits (in character) using C program.

Problem solution

In this program, we are using a variable named count which will be initialized by '0' and with the help of label, goto statement and condition; we are printing the ASCII values of all digits.

C program to print ASCII values of all digits

#include<stdio.h>

int main()
{
	//counter, it can also be declared as 'char'
	int count;
	//initializing counter by 'a'
	count= '0';
	//definig label
	start:
	printf("%c [%d] ",count,count);
	count++;
	//jumping back to 'stat' if condition is true
	if(count <= '9')
		goto start;
	return 0;
}

Output

0 [48] 1 [49] 2 [50] 3 [51] 4 [52] 5 [53] 6 [54] 7 [55] 8 [56] 9 [57] 

This is a way, by which we can print ASCII values of all digits, please write through comment, if you have any doubt?

C Goto Programs »

Comments and Discussions!

Load comments ↻





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