info@thistimebd.com

Tuesday 3rd of December 11:59:06pm

6.16 Describe the output that will be generated by each of the following c program.(Note the similartion in the programs that are shown from each other)

6.16 Describe the output that will be generated by each of the following c program.(Note the similartion in the programs that are shown from each other)


Solution:

a)

#include<stdio.h>

int main()

{

int i=0,x=0;

while(i<20)

{

if(i%5==0)

{

x+=i;


printf("%d",x);

}

i++;

}

printf(" x=%d",x);

}

ans: Output: 0 5 15 30

x=30


b)

#include<stdio.h>

int main()

{

int i=0,x=0;

do

{

if(i%5==0)

{

x++;

printf("%d",x);

}


++i;

}

while(i<20);


printf(" x=%d",x);

}

ans: Output: 1 2 3 4

x=4


c)

#include<stdio.h>

int main()

{

int i=0,x=0;

for(i=1;i<10; i*=2)

{

x++;

printf("%d",x);

}


printf(" x=%d",x);

}

ans: Output: 1 2 3 4

x=4


d)

#include<stdio.h>

int main()

{

int i=0,x=0;

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

{

if(i%2==1)

x+=1;

else

x--;

printf("%d ",x);

}


printf(" x=%d",x);


}

ans: Output: 1 0 1 0 1 0 1 0 1

x=1