You are here:

C/how to get output

Advertisement


Question
WAP tp read n nos. in an array and print as follows:if the element of array is 1 2 3 4 5,then output will be
1 0 0 0 0
1 2 0 0 0
1 2 3 0 0
1 2 3 4 0
1 2 3 4 5
i've understood the logic but can get how to print it .pls help me.

Answer
Hi Anujit,

Here is the logic i am sending you. If you want to take dynamic array you can get data from user and save it in the array.

#include <stdio.h>
#include <string.h>

main()
{
   int n=3,i,j;
   int a[3]={3,6,2};
   for(i=0;i<n;i++)
   {
       for(j=0;j<=i;j++)
       {
         printf("%d ",a[j]);
       }
       
       while(j<n)
       {
         printf("0 ");
         j++;
       }
       printf("\n");
   }
   
}

Here n is the size of an array.

Thanks & Regards,
Kedar Desai  

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Kedar Desai

Expertise

You can ask me any questions about C and c++

Experience

I don't have practical experience. But i have knowledge about C as I belong to IT field since last 5 years.

Education/Credentials
I an studying in MCA from Maharashtra (Mumbai University)

©2016 About.com. All rights reserved.