write a program to display the numbers in the following
format
4 4
3 3 3 3
2 2 2 2 2 2
1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1
2 2 2 2 2
3 3 3
4
Answers were Sorted based on User's Feedback
Answer / vidyullatha
#include<stdio.h>
main()
{
int i=0,k=0,l=0;
int cnt=1;
int space=7;
for (i=4;i>0;i--)
{
for(l=1;l<=cnt;l++)
{
printf("%d ",i);
}
for(k=0;k<space;k++)
{
printf(" ");
}
for(l=1;l<=cnt;l++)
{
printf("%d ",i);
}
cnt++;
space=space-2;
printf("\n");
}
for(i=0;i<9;i++)
{
printf("0 ");
}
printf("\n");
cnt=7;
for(i=1;i<=4;i++)
{
for(k=0;k<i;k++)
printf(" ");
for(l=1;l<=cnt;l++)
{
printf("%d ",i);
}
printf("\n");
cnt=cnt-2;
}
}
Is This Answer Correct ? | 19 Yes | 1 No |
Answer / jankipatel
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,l,p;
clrscr();
// printf("enter the value\n");
// scanf("%d",&l);
for(i=4;i>=0;i--)
{
for(j=4;j>=i;j--)
{
// textcolor(0-i);
printf("%d ",i);
}
for(k=0;k<=i-1;k++)
{
printf(" ");
}
for(k=0;k<=i-1;k++)
{
printf(" ");
}
for(j=4;j>=i;j--)
{
// textcolor(0-i);
printf(" %d",i);
}
printf("\n");
}
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
printf(" ");
}
for(k=4;k>=i;k--)
{
printf("%d ",i);
}
for(k=4;k>=i;k--)
{
printf(" %d",i);
}
printf("\n");
}
getch();
}
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / meet parikh
public class Arrow_1 {
private final int LARG = 4;
String printint,fillint;
boolean display = false;
public Arrow_1(){
fillint = " ";
for(int i = LARG; i >= 0; i--){
if(i == 0){
display = true;
fillint = 0 + "";
}
StringBuilder sb = new StringBuilder();
printint = i + "";
insertDisp(sb, i);
System.out.println(sb.toString());
}
printint = " ";
for(int i = LARG; i>0;i--){
StringBuilder sb = new StringBuilder();
fillint = LARG - (i-1) + "";
insertDisp(sb,i);
System.out.println(sb.toString());
}
}
private void insertDisp(StringBuilder sb,int number){
printDisp(sb, number);
fillempty(sb, number);
if(display){
sb.append(fillint);
} else {
sb.append(" ");
}
fillempty(sb, number);
printDisp(sb, number);
}
private void printDisp(StringBuilder sb,int number){
int itr;
if(number == 0){
itr = LARG;
} else {
itr = LARG - (number-1);
}
for(int i = 0 ; i < itr;i++){
sb.append(printint);
}
}
private void fillempty(StringBuilder sb, int number){
for(int i = 0; i < number-1 ;i++ ){
sb.append(fillint);
}
}
public static void main(String args[]){
new Arrow_1();
}
}
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / padmapriya
class Pattern{
public static void main(String[]args){
for(int i=4;i>0;i--){
for(int j=0;j<5-i;j++){
System.out.print(i);
}
for(int j=0;j<i;j++){
System.out.print(" ");
}
for(int j=0;j<i-1;j++){
System.out.print(" ");
}
for(int j=0;j<5-i;j++){
System.out.print(i);
}
System.out.println();
}
for(int i=0;i<5;i++){
for(int j=0;j<i;j++){
System.out.print(" ");
}
for(int j=0;j<9-2*i;j++){
System.out.print(i);
}
System.out.println();
}
}
}
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / mahesh
#include<stdio.h>
int main()
{
int a=2,n=4,i,j,k;
for (i=4;i>=0;i--)
{
for(j=0;j<a;j++)
{
printf("%d",n);
}
printf("
");
a=a+2;
n--;
}
n=1;
a=a-4;
for(i=0;i<=4;i++)
{
for(j=0;j<a;j++)
{
printf("%d",n);
}
printf("
");
a=a-2;
n++;
}
}
Is This Answer Correct ? | 2 Yes | 1 No |
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,l,n;
clrscr();
printf("enter the number");
scanf("%d",&n);
for(j=n,l=1;(j>0 && l<=n);j--,l++)
{
for(k=1;k<=2*l;k++)
printf("%d",j);
printf("
");
}
for(j=0,l=n;(j<=n && l>=0) ;j++,l--)
{
for(k=1;k<=2*l+1;k++)
printf("%d",j);
printf("
");
}
getch();
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / vamsi talapatra
#include<iostream>
using namespace std;
int main(){
int n = 4;
int e = 2;
while(n>0){
for(int i = 0; i< e ; i++){
cout<<n<<" ";
}
cout<<endl;
e=e+2;
n--;
}
while(n<=4){
for(int i = 1; i< e ; i++){
cout<<n<<" ";
}
cout<<endl;
e=e-2;
n++;
}
return 0;
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / venkatesh
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int i,j,k,n1,n2;
printf("
enter n1 value:");
scanf("%d",&n1);
k=4;
for(i=1;i<=n1;)
{
for(j=i;j<=2*i;j++)
{
printf("%d ",k);
}
printf("
");
i=i+2;
k=k-1;
}
k=0;
n2=n1+1;
for(i=9;i>=1;)
{
for(j=1;j<=i;j++)
{
printf("%d ",k);
}
printf("
");
k=k+1;
i=i-2;
}
return 0;
}
Is This Answer Correct ? | 0 Yes | 1 No |
Differentiate between calloc and malloc.
what are enumerations in C
In c programming language, how many parameters can be passed to a function ?
Write a simple program to find the size of different basic data types in C.
Why cann't whole array can be passed to function as value.
how to print "hai" in c?
Would you rather wait for the results of a quicksort, a linear search, or a bubble sort on a 200000 element array? 1) Quicksort 2) Linear Search 3) Bubble Sort
IS Doon college of Engn.. has good faculty
give one ip, find out which contry
Why is sizeof () an operator and not a function?
Compare and contrast compilers from interpreters.
What is derived datatype in c?