Find the output of the following c programs
1. #include<stdio.h>
int main()
{
int
i,j;
for(i=0,j=10;i<10;i++,j--);
printf("%d %d",i,j);
return
0;
}
2. #include<stdio.h>
int main()
{
int
i=0,j;
if(i
&& (j=2))
printf("%d
%d",i,j);
return
0;
}
3. #include <stdio.h>
int main()
{
int a=9;
if(a=5)
printf ("It
is important to practice c");
else
printf ("ss
coading may help you");
return 0;
}
4. #include <stdio.h>
int main()
{
int
a=5, b=3;
if(a<5)
a=a-3;
b=b+3;
printf("a=%d
b=%d\n",a,b);
return
0;
}
5. #include <stdio.h>
int main()
{
int
a=9,b=0,c=0;
if
(!a<1 && !b||c)
printf
("practice makes perfect\n");
else
printf
("practice makes us better\n");
return
0;
}
6. #include <stdio.h>
int main()
{
int
i=1, j=9;
if(i>=5&&j<5);
i=j+2;
printf("%d\n",i);
return
0;
}
7. #include <stdio.h>
int main()
{
int
a=0,b=0;
if
(!a)
{
b=!a;
if (b)
a=!b;
}
printf("%d,
%d",a,b);
return
0;
}
8. #include<stdio.h>
int main()
{
int a=5;
begin:
if(a)
{
printf ("%d
",a);
a--;
goto begin;
}
return 0;
}
9. #include<stdio.h>
int main()
{
int
a=2,b=5;
if(a==2)
if(b==3)
printf("a
is equal to 2 and b is equal to 5");
else
printf("a
equals to 2");
return
0;
}
10. #include <stdio.h>
int main()
{
int k=1,n;
do
{
printf ("%d
",k) ;
n=n+k++;
}
while(k<5) ;
return 0;
}
11. #include<stdio.h>
int main()
{
int
a=6,b=4;
while(a+b)
{
printf("a=%d,
b=%d\n",a,b);
a=a/2;
b%=3;
}
return
0;
}
12. #include<stdio.h>
int main()
{
int
i=1,j;
if(i
|| (j=2))
printf("i=%d,
j=%d",i,j);
return
0;
}
13. #include<stdio.h>
int main()
{
char a;
if('a')
printf("%c",a);
return 0;
}
14. #include<stdio.h>
int main()
{
int
i=10;
do
{
printf("i=%d\n",i);
i=i-3;
}
while(i)
;
return
0;
}
15. #include<stdio.h>
int i;
int main()
{
do
printf("%d",i);
while(!i);
return 0;
}
16. #include<stdio.h>
int main()
{
int
i,j=10;
for(;i=j;j-=2)
printf("%d
",j);
return
0;
}
17. #include<stdio.h>
int main()
{
int
i,j,a=0;
for(i=0;i<5;i++)
for(j=i;j>0;j--)
a=i+j+1;
printf("%d\n",a);
return
0;
}
18. #include<stdio.h>
int main()
{
int
i,index=0;
for(i=0;i<10;i++)
;
{
int i=0;
while(i++<5)
index++;
}
printf
("index = %d\n", index);
return
0;
}
19. #include<stdio.h>
int main()
{
int
i;
for(i=1;i<10;i++)
{
if(i==3)
continue;
printf("%d
",i);
}
return
0;
}
20. #include<stdio.h>
int main()
{
int
i=1;
while(i<10)
{
if(i==3)
continue;
printf("%d
",i);
i++;
}
return
0;
}
21. #include<stdio.h>
int main()
{
int i,sum;
for(i=0;i<10;i+=3)
sum +=i*i;
printf("%d",sum);
return 0;
}
22. #include<stdio.h>
int main()
{
do
{
int i=1;
printf("%d",i);
}
while(!i);
return 0;
}
23. #include<stdio.h>
int main()
{
int
c=50;
for(;c;)
c--;
printf
("c=%d",c);
return
0;
}
24. #include<stdio.h>
int main()
{
int
i;
for(i=0;i<10;i++);
printf("%d
\n",i);
return
0;
}
25. #include<stdio.h>
int main()
{
char
ch= 'A' ;
switch(ch)
{
case
'A': ch++;
continue;
case
'B':ch;
}
return
0;
}
26. #include<stdio.h>
int main()
{
char
ch= 'A' ;
switch(ch)
{
case
'A': ch++;
break;
case
'B':ch;
}
print("%c",ch);
print("%c",ch);
return
0;
}
27. #include<stdio.h>
int main()
{
char ch='A';
while(ch<='D')
{
switch(ch)
{
case 'A':
case'B': ch++;
continue;
case 'C':
case 'D': ch++;
}
printf("%c
",ch) ;
}
return 0;
}
28. #include<stdio.h>
int main()
{
int n,sum=0;
for( ; ; )
{
scanf("%d",
&n);
sum+=n;
if(sum>100)
break;
}
return 0;
}
29. #include<stdio.h>
int main()
{
int i ,sum1=0,
sum2=0;
for(i=1;i<5;i++)
sum1+=i;
while(i<=5)
{
i++;
sum2+=i;
}
printf ("%d
%d\n",i,sum1,sum2) ;
return 0;
}
30. #include<stdio.h>
int main()
{
int i=-1;
if(i)
printf("true\n");
else
printf("false\n");
return 0;
}
31. #include<stdio.h>
int main()
{
if(printf("This
is"))
printf("
true\n");
else
printf("false\n");
return 0;
}
32. #include<stdio.h>
int main()
{
int
i=1;
for(i;i;i)
printf("%d",i);
return
0;
}
33. #include <stdio.h>
int main()
{
int
a=3;
switch(--a)
{
case 1:printf("one ");
case 2:printf("two ");
case 3:printf("three ");
default:printf("none ");
}
return
0;
}
34. #include <stdio.h>
int main()
{
int
a=1,b=2,c=3;
switch(a||b||c)
{
case a:printf("one ");
case b:printf("two ");
case c:printf("three ");
default:printf("none ");
}
return
0;
}
35. #include <stdio.h>
int main()
{
int
a=3,b=2,c=1;
switch(a||b||c)
{
case 1+2:printf("three ");
case 1+1:printf("two ");
case 1:printf("one ");
break;
default:printf("none ");
}
return
0;
}
36. #include <stdio.h>
#define aa 2
int main()
{
int
a=4;
switch(a)
{
case 1: printf("three ");
default: printf("none ");
case aa: printf("two");
case 3: printf("three ");
break;
}
return
0;
}
37. #include <stdio.h>
int main()
{
int
a='a',A='A',n;
n=a||A;
while(n)
printf
("%d ",a-A) ;
return
0;
}
38. #include <stdio.h>
int main()
{
int i;
for(i=1;i<=3;i++);
printf("i=%d",i++);
return 0;
}
39. #include <stdio.h>
int main()
{
int i,j;
for(i=1;i<=2;i++)
for(j=1;j<=5;++j)
printf
("i=%d, j=%d\n",i++,++j);
return 0;
}
40. #include <stdio.h>
int main()
{
int k=1;
do
{
printf
("%d ",k) ;
k+=k;
}
while(k<5) ;
return 0;
}
41. #include <stdio.h>
int main()
{
int
a=1;
while(a=5)
printf
("%d ",a++) ;
return
0;
}
ANSWER
- 10 0
- No output
- It is important to practice c
- a=5 b=6
- practice makes perfect
- 11
- 0, 1
- 5 4 3 2 1
- a equals to 2
- 1 2 3 4
- a=0, b=1a=0, b=1------- infinity loop
- i=1, j= Garbage value
- Garbage value (null character also may)
- 1074…….. infinite loop
- infinite loop
- 10 8 6 4 2
- 6
- index = 5
- 1 2 4 5 6 7 8 9
- infinite loop
- 126
- compilation error
- c=0
- 10
- compilation error
- B
- D E
- It will take the entered value until the sum total is 100.
- 6 10
- true
- This is true
- infinite loop
- two three none
- compilation error
- one
- none two three
- 32 32 32…. Infinite loop
- i=4
- i=1, j=2i=2, j=4i=3, j=6
- 1 2 4
- 5 5 5… infinite loop
No comments:
Post a Comment
For any doubt or suggestion you can write here