C语言简单循环示例

# include <stdio.h>

int main(void)
{
	int i;
	int count = 0;
	int sum = 0;
	float avg;
	
	for (i=1; i<=100; i++)
	{
		if (i%2==0) 
		{
			count++;
			sum += i;
		}
	}

	avg = 1.0*sum / count;	// 1.0 默认为double类型
	
	printf("%d\n", count);
	printf("%d\n", sum);
	printf("%f\n", avg);
	
	return 0;
}

 

九九乘法表

# include <stdio.h>

int main(void)
{
	int i;
	int j;

	for (i=1; i<10; i++)
	{
		for (j=1; j<=i; j++)
		{
			printf("%d x %d = %d  ", i, j, i*j);	
		}
		printf("\n");

	}

	return 0;
}

 

你可能感兴趣的:(c)