Computer Science, asked by lr372377, 1 year ago

Write a C program to print a triangle of prime numbers upto given number of lines of the triangle.

Answers

Answered by nirajnagrale1994
4

#include <stdio.h>

 

int main()

{

 int n, i,  c, a = 1;

 

 printf("Enter the number of rows of Floyd's triangle to print\n");

 scanf("%d", &n);

 

 for (i = 1; i <= n; i++)

 {

   for (c = 1; c <= i; c++)

   {

     printf("%d ",a);

     a++;

   }

   printf("\n");

 }

 

 return 0;

}


lr372377: C progrm to print a triangle of prime numbers
Answered by phillipinestest
1

The program follows to get an output to get a triangle of prime numbers up to the provided number of lines.

class main()

{

int i,j,k, count=0;

printf("Enter the number");

scanf("%d",&k);

printf("Given prime numbers are \n");

for(1=2; i<=k; i++)

{

count =0 ;

for (j=2; j<i; j++)

{

if( i%j == 0 ){

count=1;

break;

}

}

if(count==0)

{

print("%d", i);

}

}

getch();

}

By running this programme, it will successfully give an output of triangle of prime numbers.  

Note: as we are using real numbers (prime numbers) we must set them into integer variable.

Similar questions