@rApToR:
Mate, it is not quite a smart idea to "outsource" an entire program for others to do. It is advisable that you also post the effort and in what lines you are thinking. After all it is YOU who has to learn and not us.
Anyway you would be already thinking, I would not help you but I will but only one of the problem i.e. the star one.
Now to get the ouput, first of all you want this, right?
Code:
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
Cool. Now you have to think how to achive the pattern. Now you already realise you need a loop(of course we can printf these [
] but that would not be the point).
Now decide the position of which the loop should move.
So Draw it again and mark positions where the asterisks have to be printed.
Code:
* 4
* * 3,5
* * * 2,4,6
* * * * 1,3,5,7
* * * * * 0,2,4,6,8
* * * * 1,3,5,7
* * * 2,4,6
* * 3,5
* 4
012345678
See, now you need loops which go from 4 to 0 and 0 to 4. So the output loop would go like that. I ran the output loop from 4 to -4 and set the negative numbers as positive ones by my abs() function.
Inside it the outer loop run first an inner loop which will print the blank spaces as well as run another parallel inner loop which will print the alternate spaces and asterisks.
Now here in my code. I have compiled it in gcc -pedantic -ansi, so I think it should work in any C compiler.
Read the code carefully. It will work pattern of any size. For getting the pattern you want as exact enter 3 as input.
Code:
#include<stdio.h>
int abs(int n)
{
if(n>=0)
return n;
else
return -n;
}
int main()
{
int n;
int i,j,k;
printf("Enter a number: ");
scanf("%d", &n);
for(i=n; i>=-n; i--)
{
for(j=0; j<abs(i); j++)
printf(" ");
for(k=0; k<2*(n-abs(i))+1; k++)
{
if(k%2==0)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
Now I hope you understand the code.
Regarding the second problem, I WONT solve it for you. Try to attempt it first and if you can't then post again.