在C語言中不使用迴圈、遞迴和宏定義來列印一個數字100次
在本節中,我們將演示如何在C語言中列印一個數字100次。這裡有一些限制。我們不能使用迴圈、遞迴或宏定義。
為了解決這個問題,我們將使用C語言中的setjump和longjump。setjump()和longjump()位於setjmp.h庫中。這兩個函式的語法如下。
示例
#include <stdio.h>
#include <setjmp.h>
jmp_buf buf;
main() {
int x = 1;
setjmp(buf); //set the jump position using buf
printf("5"); // Prints a number
x++;
if (x <= 100)
longjmp(buf, 1); // Jump to the point located by setjmp
}輸出
5555555555555555555555555555555555555555555555555555555555555555555555555555 555555555555555555555555
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP