473,320 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Nested Loops

Hi friends, newbie here, appreciate your help to convert this program into C languages. I'm really-really beginner into C world

Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2.  
  3. #define MAX 10
  4.  
  5.  
  6. int main()
  7. {
  8.     int number, line, column;
  9.  
  10.     for( line = 1; line <= MAX; line++ )
  11.     {
  12.         for( column = MAX; column >= line; column-- )
  13.             cout << ' ';
  14.  
  15.         for( column = line; column < 2*line; column++ )
  16.         {
  17.             number = column % 10;
  18.             cout << number;
  19.         }
  20.  
  21.         for( column = 2*(line-1); column >= line; column-- )
  22.         {
  23.             number = column % 10;
  24.             cout << number;
  25.         }
  26.         cout << endl;
  27.     }
  28. }
it's a nested loops that can generate a pyramids of no 1-10
so..i just need your help to convert it into C language

TQ in advanced
Sep 30 '07 #1
3 1305
Savage
1,764 Expert 1GB
Hi friends, newbie here, appreciate your help to convert this program into C languages. I'm really-really beginner into C world

#include <iostream.h>

#define MAX 10


int main()
{
int number, line, column;

for( line = 1; line <= MAX; line++ )
{
for( column = MAX; column >= line; column-- )
cout << ' ';

for( column = line; column < 2*line; column++ )
{
number = column % 10;
cout << number;
}

for( column = 2*(line-1); column >= line; column-- )
{
number = column % 10;
cout << number;
}
cout << endl;
}
}

it's a nested loops that can generate a pyramids of no 1-10
so..i just need your help to convert it into C language

TQ in advanced
All,you need to do is to use printf instead of cout and instead of endl manipulator you use "\n"

Savage
Sep 30 '07 #2
All,you need to do is to use printf instead of cout and instead of endl manipulator you use "\n"

Savage
hi savage, thanks for the reply.

Ok, for now if i use printf, what i need to put in the printf command?? is that number, line or column?
Oct 1 '07 #3
Ganon11
3,652 Expert 2GB
In order to convert the statement:

Expand|Select|Wrap|Line Numbers
  1. cout << "The value of myIntVar is " << myIntVar << endl;
you would use this statement:

Expand|Select|Wrap|Line Numbers
  1. printf("The value of myIntVar is %d \n", myIntVar);
Any string you output is just copied into the first argument. If you need to output a variable, you use one of the format specifiers (I don't know the whole list, but I know the specifier for ints is %d) in the place in the string where you'd like it to be displayed. Every time you add a specifier, you need to add the variable you wish to display as an argument after the string. In order to print endl, you add '\n' to the appropriate place in the string.
Oct 1 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: chad | last post by:
I am writing a program to do some reliability calculations that require several nested for-loops. However, I believe that as the models become more complex, the number of required for-loops will...
0
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # David Eppstein of the Geometry Junkyard fame gave this elegant # version for returing all possible pairs from a range of n numbers. def combo2(n): return...
4
by: dw | last post by:
Hello all. We're doing a site with teams and their members. We've got a page where we need to display people according to who belongs to a which team. I've heard that nested loops are bad, but...
46
by: Neptune | last post by:
Hello. I am working my way through Zhang's "Teach yourself C in 24 hrs (2e)" (Sam's series), and for nested loops, he writes (p116) "It's often necessary to create a loop even when you are...
77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
9
by: Gregory Petrosyan | last post by:
I often make helper functions nested, like this: def f(): def helper(): ... ... is it a good practice or not? What about performance of such constructs?
5
by: =?Utf-8?B?QUEyZTcyRQ==?= | last post by:
Could someone give me a simple example of nested scope in C#, please? I've searched Google for this but have not come up with anything that makes it clear. I am looking at the ECMA guide and...
4
by: toddlahman | last post by:
I am using two while loops that are nested. The first loop (post name) returns the full column of results, but the second (post modified) only returns the first row of the column. Is there another...
13
by: Fredrik Lundh | last post by:
Patrol Sun wrote: so why exactly are you trying to nest 20 or 100 for-in loops? </F>
8
by: Nathan Sokalski | last post by:
I have several nested For loops, as follows: For a As Integer = 0 To 255 For b As Integer = 0 To 255 For c As Integer = 0 To 255 If <Boolean ExpressionThen <My CodeElse Exit For Next If Not...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.