Solve this program

0 Fayazur Rahman Summit · April 16, 2015
Write a nested loop to print:
/*In each pass you must print only one digit */


2 2 2
4 4 4 4 4
6 6 6 6 6 6 6
8 8 8 8 8 8 8 8 8
0 0 0 0 0 0 0 0 0 0 0
2 2 2 2 2 2 2 2 2 2 2 2 2

Post a Reply

Replies

Oldest  Newest  Rating
0 Dol Lod · April 16, 2015
I would use an iteration counter to print a particular number to screen and update it every time. I don't know enough about the problem for other suggestions. 
+1 Sharon Fabin · April 17, 2015
 just make the first loop as much times as you're requested to and each time it comes to the next iteration, make a variable that will store the num of digits that need to be in the next line and another that will change the digit that is going to printed.
i dont know how to write it in C but i know C++ so:

#include <iostream>

using namespace std;

int main(){
int numOfRows,numOfCols=3,digit=2;
cout << "Enter number of rows";
cin >> numOfRows;
for (int i = 0; i < numOfRows; i++){
for (int j = 0; j < numOfCols; j++){
cout << digit;
}
if (digit == 8) digit = 0;
else digit += 2;
numOfCols += 2;

cout << "\n";
}
}
0 Fayazur Rahman Summit · April 21, 2015
ohh
at last i solve this problem


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i, j;
    for(i=1; i<=6; i++){
        for(j=i; j<=3*i; j++){
            printf("%d", (i%5)*2);
        }
        printf("\n");
    }

    return 0;
}
0 Fayazur Rahman Summit · April 21, 2015

#include
#include

int main()
{
    int i, j;
    for(i=1; i
  • 1

C

107,224 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator