Here is the code to do it:
#include<stdio.h> main() { int n, c, k, space = 1; //Here we ask for the number of rows would be : printf("Enter number of rows\n"); scanf("%d",&n); space = n - 1; //This is the first half of the diamond for ( k = 1 ; k <= n ; k++ ) { for ( c = 1 ; c <= space ; c++ ) printf(" "); space--; for ( c = 1 ; c <= 2*k-1 ; c++) printf("*"); printf("\n"); } space = 1; //Here is the second half of the diamond for ( k = 1 ; k <= n - 1 ; k++ ) { for ( c = 1 ; c <= space; c++) printf(" "); space++; for ( c = 1 ; c <= 2*(n-k)-1 ; c++ ) printf("*"); printf("\n"); } return 0; }
Hope that helped :)
Input a variable.
It is unnecessary to use a for loop to convert meters to centimeters. Just multiply by 0.01.
printf ("x")
An infinite loop is one sequence of commands that just repeats over and over again forever. When it comes to creating an infinite loop you can use the: for do while and do statements. using the keywords 'true'
void line(int length) { for(int i=0; i<length; ++i) std::cout<<'_'; std::cout<<std::endl; }
It depends on what program you design really
There are three ways out of a loop.1. Satisfy the loop ending condition2. Execute a break statement3. Terminate the programPerhaps you are not changing the value of the variable that is used in the loop ending condition. Perhaps you are using a variable, such as an unsigned int, decrementing it, and expecting it to go negative. Suggest you run the program in a debuger and step through the loop.
Place the digits in an array (or vector) and use the loop to sum each digit to a running total initialised to zero. The following function demonstrates the loop: int sum_vector(std::vector<int>& v) { int total=0; int i=0; while( i<v.size() ) total+=v[i]; return total; }
No, why did you think so?
Example: int main (void) { LOOP: goto LOOP; }
* ** *** **** simply use dis... { int x,y; for(x=1;x<=4;x++) { for(y=1;y<=x;y++) printf("*"); printf("\n"); } }
In C++, a for loop is structured as follows: for( int index = 0; index < 10; ++i ) { //do something }