C coding questions

(1)What will be output when you compile and execute the following code?

void main()

{

    int i,j;

    clrscr();

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

    {

       for(j=0;j<5;j++)

       {

           printf("*");

 

       }

       printf("\n");

    }

    getch();

}

For output click me

(2)What will be output when you compile and execute the following code?

 

void main()

{

    int i,j;

    clrscr();

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

    {

       for(j=0;j

       {

           printf("*");

 

       }

       printf("\n");

    }

    getch();

}

For output click me

 (3)What will be output when you compile and execute the following code?

 

void main()

{

    int i,j;

    clrscr();

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

    {

       for(j=0;j<=2*i-3;j++)

       {

           printf("*");

 

       }

       printf("\n");

    }

    getch();

}

 For output click me

(4)What will be output when you compile and execute the following code?

 

void main()

{

    int i,j;

    clrscr();

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

    {

       for(j=0;j<=2*i-2;j++)

       {

           printf("*");

 

       }

       printf("\n");

    }

    getch();

}

For output click me

 (5)What will be output when you compile and execute the following code?

 

void main()

{

    int i,j;

    clrscr();

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

    {

       for(j=0;j<3*i-2;j++)

       {

           printf("*");

 

       }

       printf("\n");

    }

    getch();

}

For output click me

(6)What will be output when you compile and execute the following code?

 

void main()

{

    int i,j;

    clrscr();

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

    {

       for(j=0;j<6-i;j++)

       {

           printf("*");

 

       }

       printf("\n");

    }

    getch();

}

For output click me

 (7)What will be output when you compile and execute the following code?

void main()

{

    int i,j;

    clrscr();

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

    {

       for(j=0;j<8-2*i;j++)

       {

           printf("*");

 

       }

       printf("\n");

    }

    getch();

}

For output click me

 (8)What will be output when you compile and execute the following code?

 

void main()

{

    int i,j;

    clrscr();

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

    {

       for(j=0;j<=8-2*i;j++)

       {

           printf("*");

 

       }

       printf("\n");

    }

    getch();

}

For output click me

(9)What will be output when you compile and execute the following code?

 

#include"math.h"

void main()

{

    int i,j;

    clrscr();

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

    {

       for(j=0;j<2*pow(2,i);j++)

       {

           printf("*");

 

       }

       printf("\n");

    }

    getch();

}

For output click me

 (10)What will be output when you compile and execute the following code?

 

#include"math.h"

void main()

{

    int i,j;

    clrscr();

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

    {

       for(j=0;j

       {

           printf("*");

 

       }

       printf("\n");

    }

    getch();

}

For output click me

 (11)What will be output when you compile and execute the following code?

 

#include"math.h"

void main()

{

    int i,j;

    clrscr();

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

    {

       for(j=0;j

       {

           printf("*");

 

       }

       printf("\n");

    }

    getch();

}

For output click me

 (12)What will be output when you compile and execute the following code?

 

#include"math.h"

void main()

{

    int i,j;

    clrscr();

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

    {

       for(j=0;j<3*pow(3,i);j++)

       {

           printf("*");

 

       }

       printf("\n");

    }

    getch();

}

For output click me

 (13)What will be output when you compile and execute the following code?

 

#include"math.h"

void main()

{

    int i,j;

    char c='*';

    clrscr();

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

    {

       for(j=0;j

       {

           printf("%*c",2,c);

 

       }

       printf("\n");

    }

    getch();

}

 For output click me

(14)What will be output when you compile and execute the following code?

 

#include"math.h"

void main()

{

    int i,j;

    char * c="*******";

    clrscr();

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

    {

       printf("%*.*s\n",i,i,c);

    }

    getch();

}

 For output click me

(15)What will be output when you compile and execute the following code?

 

#include"math.h"

void main()

{

    int i,j;

    char * c="*******";

    clrscr();

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

    {

       printf("%*.*s\n",i+6,i,c);

    }

    getch();

}

For output click me

(16)What will be output when you compile and execute the following code?

 

void main(){

    char *ptr="*******";

    int i,j;

    clrscr();

    for(i=0;i<8;i++){

       printf("%*.*s\n",8,i,ptr);

    }

    getch();

}

For output click me

 (17)What will be output when you compile and execute the following code?

 

void main(){

    char *ptr="*********";

    int i,j;

    clrscr();

    for(i=0;i<5;i++){

       printf("%*.*s\n",5+i,2*i+1,ptr);

    }

    getch();

}

For output click me

 (18)What will be output when you compile and execute the following code?

 

void main(){

    char *ptr="*********";

    int i,j;

    clrscr();

    for(i=0;i<10;i++){

       if(i<5)

       printf("%*.*s\n",5+i,2*i+1,ptr);

       else

       printf("%*.*s\n",14-i,19-2*i,ptr);

    }

 

    getch();

}

For output click me

 (19)What will be output when you compile and execute the following code?

 

void main(){

    char *ptr="*********";

    int i,j;

    clrscr();

    for(i=0;i<9;i++){

       if(i<5)

       printf("%*.*s\n",5+i,2*i+1,ptr);

       else

       printf("%*.*s\n",13-i,17-2*i,ptr);

    }

 

    getch();

}

For output click me

 (20)What will be output when you compile and execute the following code?

 

void main(){

    char *ptr="*********";

    int i,j;

    clrscr();

    for(i=0;i<5;i++){

       printf("%*.*s\n",9-i,9-2*i,ptr);

    }

 

    getch();

}

 

 For output click me

(21)What will be output when you compile and execute the following code?

 

void main(){

    char *ptr="*****";

    int i,j;

    clrscr();

    for(i=0;i<10;i++){

       if(i<6)

       printf("%*.*s\n",5,i,ptr);

       else

       printf("%*.*s\n",5,10-i,ptr);

    }

 

    getch();

}

 For output click me

(22)What will be output when you compile and execute the following code?

 

void main(){

    char *ptr="*****";

    int i,j;

    clrscr();

    for(i=1;i<10;i++){

       if(i<6)

       printf("%*.*s\n",0,i,ptr);

       else

       printf("%*.*s\n",0,10-i,ptr);

    }

 

    getch();

}

For output click me

 (23)What will be output when you compile and execute the following code?

 

void main(){

    char *ptr="*********";

    int i,j;

    clrscr();

    for(i=0;i<11;i++){

       if(i<5)

           printf("%*.*s\n",5+i,2*i+1,ptr);

       else

       {

           if(i==7)

           {

               *(ptr+3)=' ';

               *(ptr+4)=' ';

               *(ptr+5)=' ';

           }

           printf("%*.*s\n",9,9,ptr);

       }

    }

 

    getch();

}

For output click me

3 comments:

Vinoth said...

printf("%*.*s\n",5+i,2*i+1,ptr);
wat is the lodic in the printf.. kindly explain..

Priyanka kumari said...

Hi Baby
Go through the following link :
http://cquestionbank.blogspot.com/2009/01/what-is-prototype-of-printf-function.html

I think it will help you.

Unknown said...

Q.2 ) for(j=0;j

{
Condition is missing .Please fill it