c语言跳出循环goto用法

#include <stdio.h>
int main() {
	int x;
	int one, two, five;
	scanf( "%d", &x);
	for ( one = 1; one < x*10; one++ ) {
		for ( two = 1; two < x * 10 / 2; two++ ) {
			for ( five = 1; five < x * 10 / 5; five++ ) {
				if ( one + two * 2 + five * 5 == x * 10 ) {
					printf("可以用%d个1角加%d个2角加%d个5角得到%d元\n",
					       one, two, five,x);
						   goto out;  
				}
			}
		}
	}
out:
	return 0;
}
104 views
Comments
登录后评论
Sign In
·

goto是坏文明...还是不建议用的...

·