-
Expert Member
test your c skills
program for output as shown below taking input from user (i.e number of lines of the output) in c language (actually the correct output is not coming on the screen correctly,but what you are seeing on right side symetrically the same on left side also)
pyramid shaped
*
* *
* * *
* * * *
* * *
* *
*
Last edited by aman15490; 05-21-2008 at 03:04 AM.
-
Junior Member
Re: test your c skills
main()
{
int i, j ;
for (i = 0; i <= 7; i++)
for(
-
Junior Member
Re: test your c skills
int n=4;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("*");
}
printf("\n");
if(n>=4)
goto n:
}
n:
for(i=4;i>n;i--)
{
for(j=0;j>n;j--)
{
printf("*");
}
printf("\n");
}
-
Junior Member
Re: test your c skills
we can't read two characters simultaniously in the following program.why?
#include<stdio.h>
int main()
{
char a,b;
scanf("%c%c",&a,&b);
printf("%c%c",a,b);
}
-
Junior Member
Re: test your c skills
hey..nice question..
1)first of all u hv written int main()..ie return type of main is int and u r not returning any thing...at last u should write return 0;
2)after taking 1st character buffer has still some space...and now when u press enter or space to take another character ...space or enter has been taken as 2nd character...so buffer get full...no chance to take 2nd character of our wish....
3)if u want to take another character first of all...u must flush the buffer by fflush(stdin);
so it will take another one...
thank you.
-
Junior Member
Re: test your c skills
#include <stdio.h>
int main() {
int i, j ; /* loop variables */
for ( i = 4 ; i > 0; i-- ) {
for ( j = 0 ; j < 4-i ; j++ ) {
printf( "%c", '*' ) ;
}
}
for ( i = 0 ; i < 4; i++ ) {
for ( j = 4-i ; j > 0 ; j-- ) {
printf( "%c", '*' ) ;
}
}
return 0 ;
}
-
Junior Member
Re: test your c skills
void main()
{
int i=0,j=0,k=7;
for(i=6;i>0;i--)
{
for(j=0;j<6-i;j++)
{
printf("*");
}
printf("\n");
}
for(i=4;i>0;i--)
{
for(j=0;j<i;j++)
{
printf("*");
}
printf("\n");
}
}
-
Junior Member
Re: test your c skills
#include <stdio.h>
int main() {
int i, j ; /* loop variables */
for ( i = 4 ; i > 0; i-- ) {
for ( j = 0 ; j < 4-i ; j++ ) {
printf( "%c", '*' ) ;
}
printf("\n") ;
}
for ( i = 0 ; i < 4; i++ ) {
for ( j = 4-i ; j > 0 ; j-- ) {
printf( "%c", '*' ) ;
}
printf("\n") ;
}
return 0 ;
}
-
Junior Member
Re: test your c skills
#include<stdio.h>
int main()
{ int comp;
int k = 2;
for(int i = 0; i<7;i++)
{
comp = i;
if(i>=4)
{
comp = i-k;
k = k+2;
}
for(int j = 0;j<=comp;j++)
printf("%c\t", '*');
printf("\n");
}
return 0;
}
-
Junior Member
Re: test your c skills
Your way is interesting and give more chance for further manipulation of the loop. Thanks!
#include<stdio.h>
int main()
{
int comp, i, j;
int k = 2;
for( i = 0; i < 7; i++)
{
comp = i;
if(i >= 4)
{
comp = i-k;
k = k+2;
}
for( j = 0; j <= comp; j++)
{
printf("%c", '*');
}
printf("\n");
}
return 0 ;
}
[ Wrote 28 lines ]
*
**
***
****
***
**
*
with the tab the out put is more interesting !
[ Wrote 28 lines ]
*
* *
* * *
* * * *
* * *
* *
*
-
Junior Member
Re: test your c skills
#include<stdio.h>
int main()
{ int comp;
int k = 2;
for(int i = 0; i<7;i++)
{
comp = i;
if(i>=4)
{
comp = i-k;
k = k+2;
}
for(int j = 0;j<=comp;j++)
printf("%c\t", '*');
printf("\n");
}
return 0;
}
-
Junior Member
Re: test your c skills
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,n;
char ch='*';
printf("Enter No of Count");
scanf("%d",n);
for(a=0;a<n;a++)
{
for(b=1;b<c;b+=2)
{
printf("%c",ch);
}
}
getch();
}
-
Junior Member
Re: test your c skills
#include<stdio.h>
int main() {
int a,b,n;
printf("Enter lines of output: ");
scanf("%d",&n);
if (n%2 == 1) {
n = n/2 + 1;
for(a = 0; a < n; a++) {
for(b = 0; b < a; b++) {
printf("*");
}
for(; b < n; b++) {
printf(" ");
}
for(b = 0; b < a; b++) {
printf("*");
}
printf("\n");
}
for(a = n; a > 0; a--) {
for(b = 0; b < a; b++) {
printf("*");
}
for(; b < n; b++) {
printf(" ");
}
for(b = 0; b < a; b++) {
printf("*");
}
printf("\n");
}
}
else {
for(a = 0; a < n/2 +1; a++) {
for(b = 0; b < a; b++) {
printf("*");
}
for(; b < n/2; b++) {
printf(" ");
}
for(b = 0; b < a; b++) {
printf("*");
}
printf("\n");
}
for(a = n/2; a > 0; a--) {
for(b = 0; b < a; b++) {
printf("*");
}
for(; b < n/2; b++) {
printf(" ");
}
for(b = 0; b < a; b++) {
printf("*");
}
printf("\n");
}
}
}
Last edited by datdo; 01-29-2009 at 05:56 PM.
-
Junior Member
Re: test your c skills
what are all the sorting techniques available in data structures?
-
Junior Member
Re: test your c skills
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,k=1,l=1;
clrscr();
printf("Enter the number of lines required:- ");
scanf("%d",&n);
for(i=n;i>0;i--)
{
for(j=1;j<i;j++)
{
printf(" ");
}
for(j=1;j<=k;j++)
{
printf("*");
printf(" ");
}
k++;
printf("\n");
}
for(i=n-1;i>0;i--)
{
for(j=0;j<l;j++)
{
printf(" ");
}
for(j=n-1;j>=l;j--)
{
printf("*");
printf(" ");
}
l++;
printf("\n");
}
getch();
}
-
Junior Member
Re: test your c skills
hi, the ans is
void main()
{
int n=4,i,j
for (i=0;i<4;i++)
{
for (j=0;j<=i;j++)
{
printf (" * ");
}
printf ("\n");
}
for (j=0;j<=i;j++)
{
printf (" * ");
}
printf ("\n");
}
for (j=0;j<=i;j++)
{
printf (" * ");
}
printf ("\n");
}
for (i=n-1;i>=1;i--)
{
for (j=i;j>=1;j--)
{
printf (" * ");
}
printf ("\n");
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules