how to print number series pattern in c programming:
Answers
Answer:
kya aap mujhe brainlist ans. banaoge kyu ki mujhe jarurat he plese
Explanation:
plese
make me brainlest ans...
Answer:
C PROGRAM:
#include <stdio.h>
int main()
{
int i,j,x=0,n,k=1;
printf("Enter the no. of row: ");
scanf("%d",&n);
int m[5][5]={0};//size of matrics
for(int r=0;r<n;r++){
for (int i = x, j = n-1; i < n && j >=r; i++, j--){
m[i][j]=k++;
}
x++;
}
printf("\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(m[i][j]==0)
printf(" ");
else{
if(m[i][j]<10){
printf(" %d ",m[i][j]);
}
else{
printf("%d ",m[i][j]);}
}
}
printf("\n");
}
return 0;
}
Java program:
import java.util.*;
public class Main
{
public static void main(String[] args) {
int i,j,x=0,n,k=1;
System.out.print("Enter the no. of row: ");
Scanner sc = new Scanner(System.in);
n=sc.nextInt();
int[][] m = new int[n][n];;//size of matrics
for(int r=0;r<n;r++){
for ( i = x, j = n-1; i < n && j >=r; i++, j--){
m[i][j]=k++;
}
x++;
}
System.out.println();
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(m[i][j]==0)
System.out.print(" ");
else{
if(m[i][j]<10){
System.out.printf(" %d ",m[i][j]);
}
else{
System.out.printf("%d ",m[i][j]);}
}
}
System.out.println();
}
}
}
Explanation:
C doesn't have dynamic built-in two dimensional array so go for java for easier task.