You are here:

C/c programming

Advertisement


Question
Sir,how to code a c program to get following output
12345678910
123456789
12345678
1234567
123456
12345
1234
123
12
1

I can do it with many "for loops" but how to code it with 2 or three loops(it can be any loop).?I kindly request you give the LOGIC  or CODING for it?

Answer
Hi, Sathish.

Use two for loops, nested within one another.  The outer for loop will contain the number you're counting up to and will decrement every time.  The inner for loop will actually count up from 1 to the desired number and will increment every time.  Something like:

   for (int i = 10; i > 0; --i)
   {
       for (int j = 1; j < i; ++j)
       {
           // print out here
       }
   }

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Joseph Moore

Expertise

I've been programming in one form or another since my brother taught me BASIC when I was 6. I've been programing professionally since I was 20, first web development with HTML, JS, DHTML, CSS, etc., then I became a video game developer, writing code in C, C++, C#, SQL, assembly, and various scripting languages. I've even written my own scripting languages, custom designed for the games I was making. I also dabble in Java, PHP, and Perl. I've worked on pretty much every aspect of game development, including graphics, audio, gameplay, tool, UI, input, animation, and physics.

Experience

I've been writing C code for 12 years, both on my own in my spare time and professionally.

Organizations
IGDA

Education/Credentials
Bachelor of Science in Game Design and Development, Full Sail University, Winter Park, FL

Awards and Honors
Salutatorian and Advanced Achiever Awards at Full Sail; Independent Games Festival Student Showcase winner, 2004; Featured article on Gamasutra about an experimental game developed in 2004

©2012 About.com, a part of The New York Times Company. All rights reserved.