C Program to print prime numbers in a Right angled Triangle pattern

Program

#include<stdio.h>
int prime(int num);
void main()
{
	int i, j;
	int num = 2, rows;
	printf("Enter the number of rows to print prime numbers:\t");
	scanf("%d", &rows);
	for (i = 0; i < rows; i++)
	{
		for (j = 0; j <= i; j++)
		{
			while (!prime(num))
			{
				num++;
			}
			printf("%d\t", num++);
		}
		printf("\n");
	}
}
int prime(int num)
{
	int i, flag;
	for (i = 2; i < num; i++)
	{
		if (num % i != 0)
			flag = 1;
		else
		{
			flag = 0;
			break;
		}
	}
	if (flag == 1 || num == 2)
		return 1;
	else
		return 0;
}

Output

Enter the number of rows to print prime numbers:	4
2	
3	5	
7	11	13	
17	19	23	29