Results 1 to 16 of 16

Thread: test your c skills

  1. #1
    Expert Member
    Join Date
    May 2008
    Answers
    100

    Thumbs up 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.

  2. #2
    Junior Member
    Join Date
    May 2008
    Answers
    1

    Re: test your c skills

    main()
    {
    int i, j ;

    for (i = 0; i <= 7; i++)
    for(


  3. #3
    Junior Member
    Join Date
    May 2008
    Answers
    6

    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");
    }


  4. #4

    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("&#37;c%c",&a,&b);
    printf("%c%c",a,b);
    }


  5. #5
    Junior Member
    Join Date
    Jun 2008
    Answers
    1

    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.


  6. #6
    Junior Member
    Join Date
    Apr 2008
    Answers
    8

    Wink 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 ;

    }


  7. #7

    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");

    }
    }


  8. #8
    Junior Member
    Join Date
    Apr 2008
    Answers
    8

    Smile 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 ;

    }


  9. #9
    Junior Member
    Join Date
    Apr 2008
    Answers
    5

    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("&#37;c\t", '*');
    printf("\n");
    }
    return 0;
    }


  10. #10
    Junior Member
    Join Date
    Apr 2008
    Answers
    8

    Wink 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 ]

    *
    * *
    * * *
    * * * *
    * * *
    * *
    *


  11. #11
    Junior Member
    Join Date
    Jan 2009
    Answers
    1

    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("&#37;c\t", '*');
    printf("\n");
    }
    return 0;
    }


  12. #12
    Junior Member
    Join Date
    Jan 2009
    Answers
    1

    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();
    }


  13. #13
    Junior Member
    Join Date
    Jan 2009
    Answers
    2

    Re: test your c skills

    #include<stdio.h>
    int main() {

    int a,b,n;
    printf("Enter lines of output: ");
    scanf("&#37;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.

  14. #14
    Junior Member
    Join Date
    Jul 2008
    Answers
    1

    Re: test your c skills

    what are all the sorting techniques available in data structures?


  15. #15
    Junior Member
    Join Date
    Mar 2009
    Answers
    4

    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("&#37;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();
    }



  16. #16
    Junior Member
    Join Date
    Sep 2009
    Answers
    1

    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
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact