M
mitchellpal
guys.... help me out here... my code is running halfway... how do i
complete the other right half....... pp.. the user should input an odd
number btw 0 and 20 then the program displays th shape as shown....i.e
two half diamonds...e.g if no. is 3 output;
* *
* * *
#include <stdio.h>
void star(int num);
void space(int num);
main()
{
int num;
do
{
printf("Please enter an odd number : ");
scanf("%d",&num);
}while(num % 2 ==0);
star(num);
}
void star(int num)
{
int count_stars=0;
int num_stars= 1;
int count_spaces= 1;
// loop for the upper part of the left diamond
while (num_stars <= num)
{
count_spaces =(num-num_stars)/2;
// loop for printing spaces input value
while (count_spaces > 0)
{
printf(" ");
count_spaces = count_spaces - 1;
}
//initialising number of stars
count_stars = num_stars;
//this is for printing stars
while (count_stars > 0)
{
printf("*");
//loop for printing spaces inside value which is 2 less the input
number
while (count_stars > 2)
{
printf(" ");
count_stars = count_stars -1;
}
count_stars = count_stars -1;
}
//void star (int num);
num_stars=num_stars +2;
printf("\n");
}
}
and you say c ain't challenging! my email address is real.
complete the other right half....... pp.. the user should input an odd
number btw 0 and 20 then the program displays th shape as shown....i.e
two half diamonds...e.g if no. is 3 output;
* *
* * *
#include <stdio.h>
void star(int num);
void space(int num);
main()
{
int num;
do
{
printf("Please enter an odd number : ");
scanf("%d",&num);
}while(num % 2 ==0);
star(num);
}
void star(int num)
{
int count_stars=0;
int num_stars= 1;
int count_spaces= 1;
// loop for the upper part of the left diamond
while (num_stars <= num)
{
count_spaces =(num-num_stars)/2;
// loop for printing spaces input value
while (count_spaces > 0)
{
printf(" ");
count_spaces = count_spaces - 1;
}
//initialising number of stars
count_stars = num_stars;
//this is for printing stars
while (count_stars > 0)
{
printf("*");
//loop for printing spaces inside value which is 2 less the input
number
while (count_stars > 2)
{
printf(" ");
count_stars = count_stars -1;
}
count_stars = count_stars -1;
}
//void star (int num);
num_stars=num_stars +2;
printf("\n");
}
}
and you say c ain't challenging! my email address is real.