Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Enter a number: 7
- 7 14 21 28 35 42 49 56 63 70
- 77 84 91 98 105 112 119 126 133 140
- 147 154 161 168 175 182 189 196 203 210
- #include<iostream>
- #include<iomanip> // For setw()
- #include<conio.h> // For getch()
- using namespace std;
- int main()
- {
- int number;
- cout << "Enter the number whose table you want: ";
- cin >> number;
- int maxrows; int maxcols;
- cout << "nEnter the number of rows you want: "; cin >> maxrows;
- cout << "nEnter the number of columns : ";
- cin >> maxcols;
- int pos=1; //starting position
- while( pos<=maxrows*maxcols )
- {
- for(int col=1; col<=maxcols; col++, pos++)
- {
- cout<< setw(6) << pos*number << " ";
- }
- cout<<"n";
- }
- getch();
- }
- #include<iostream>
- #include<iomanip>
- #include<conio.h>
- using namespace std;
- int main()
- {
- int number;
- cout << "Enter the number whose table you want: ";
- cin >> number;
- int maxrows; int maxcols;
- cout << "nEnter the number of rows you want: "; cin >> maxrows;
- cout << "nEnter the number of columns : "; cin >> maxcols;
- int row; int col; //Current row and current col
- for(int pos=1; pos<=(maxrows*maxcols); pos++)
- {
- cout << setw(6) <<number*pos << " ";
- if((pos%maxcols)==0)
- {
- cout << "n";
- }
- }
- getch();
- }
- #include<iostream>
- #include<iomanip>
- #include<conio.h>
- using namespace std;
- int main()
- {
- int number;
- cout << "Enter the number whose table you want: ";
- cin >> number;
- int maxrows; int maxcols;
- cout << "nEnter the number of rows you want: "; cin >> maxrows;
- cout << "n Enter the number of columns : "; cin >> maxcols;
- for(int row=0; row<=(maxrows-1); row++)
- {
- for(int col=1; col<=maxcols; col++)
- {
- cout << setw(6) << number*(col + row*maxcols); // (col + row*maxcols) represent the current position
- }
- cout << "n";
- }
- getch();
- }
- #include<iostream>
- #include<iomanip> // For setw()
- #include<conio.h> // For getch()
- using namespace std;
- int main()
- {
- int number;
- cout << "Enter the number whose table you want: ";
- cin >> number;
- int maxrows; int maxcols;
- cout << "nEnter the number of rows you want: "; cin >> maxrows;
- cout << "n Enter the number of columns : ";
- cin >> maxcols;
- for(int row=1; row<=maxrows; row++ )
- {
- cout << "n";
- for(int col=0; col<maxcols; col++)
- {
- cout << setw(6)<< number*(row + maxrows*col) << " ";
- }
- }
- getch();
- }
- for(int row=0; row<=(maxrows-1); row++)
- for(int row = 0; row <= maxrows - 1; row++)
- for(int i=0; i < N; ++i) { /* do something */ }
- for(int row=0; row<=(maxrows-1); row++) {
- for(int col=1; col<=maxcols; col++) {
- // do stuff
- }
- }
- int accum = number;
- for(unsigned row = 0; row < maxrows; ++row) {
- for(unsigned col = 0; col < maxcols; ++col) {
- std::cout << std::setw(6) << accum;
- accum += number;
- }
- std::cout << "n";
- }
- #include <iostream>
- #include <iomanip>
- int main()
- {
- int number;
- std::cout << "Enter the number whose table you want: ";
- std::cin >> number;
- unsigned maxrows;
- unsigned maxcols;
- std::cout << "nEnter the number of rows you want: ";
- std::cin >> maxrows;
- std::cout << "nEnter the number of columns : ";
- std::cin >> maxcols;
- const int colincr = number * maxrows;
- const int rowdecr = number * (maxrows * maxcols - 1);
- int accum = number;
- for(unsigned row = 0; row < maxrows; ++row) {
- for(unsigned col = 0; col < maxcols; ++col) {
- std::cout << std::setw(6) << accum;
- accum += colincr;
- }
- accum -= rowdecr;
- std::cout << 'n';
- }
- }
- Enter the number whose table you want: 7
- Enter the number of rows you want: 5
- Enter the number of columns : 8
- 7 42 77 112 147 182 217 252
- 14 49 84 119 154 189 224 259
- 21 56 91 126 161 196 231 266
- 28 63 98 133 168 203 238 273
- 35 70 105 140 175 210 245 280
- #include <iostream>
- #include <iomanip>
- int main() {
- int num;
- std::cout << "Enter no: ";
- std::cin >> num;
- unsigned int row = 20, col = 10;
- int sum = 0;
- num < 0
- for( unsigned int i = 0; i < row; ++i) {
- for( unsigned int j = 0; j < col; ++j) {
- sum += num;
- std::cout << std::setw(6) << sum;
- }
- std::cout << 'n';
- }
- return 0;
- }
- for (int i = 0; i < n; i++) {
- …
- }
- for(int row=0; row<=(maxrows-1); row++)
- int n = 0;
- for (int row = 0; row < maxrows; row++) {
- for (int col = 0; col < maxcols; col++) {
- std::cout << std::setw(7) << (n += multiple);
- }
- std::cout << "n";
- }
- int stride = maxrows * multiple;
- for (int row = 1; row <= maxrows; row++) {
- for (int col = 1, n = row * multiple; col <= maxcols; col++, n += stride) {
- std::cout << std::setw(7) << n;
- }
- std::cout << "n";
- }
- #include<iostream>
- #include<iomanip>
- using namespace std;
- int main()
- {
- int number=0,i,rows,col;
- cout << "Enter the number,rows and columns: ";
- cin >> number>>rows>>col;
- for(i=1;i<=col*rows;i++)
- {
- if(i%rows==0){
- cout<<setw(5)<<number*i<<"n";
- }
- else{
- cout<<setw(5)<<number*i;
- }
- }
- }
- I find this code easy to understand as first year student!!
- date=1 ; while(date <= monthLength)
- printf("%2d%c",date++,(date-offset) % 7 ? ' ' : 'n');
Add Comment
Please, Sign In to add comment