0% found this document useful (0 votes)
12 views4 pages

Chapter 10 Errors and Outputs

The document contains a series of code segments that demonstrate various printf statements and their expected outputs in C programming. It also includes sections where errors in code are identified, highlighting common mistakes in syntax and function usage. Overall, the document serves as a guide for understanding output formatting and error identification in C code.

Uploaded by

vibefuse0967
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Chapter 10 Errors and Outputs

The document contains a series of code segments that demonstrate various printf statements and their expected outputs in C programming. It also includes sections where errors in code are identified, highlighting common mistakes in syntax and function usage. Overall, the document serves as a guide for understanding output formatting and error identification in C code.

Uploaded by

vibefuse0967
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Chapter 10 Errors and outputs Tracing

Determine the output of the following code segments


1. printf(“Pakistan \t is \t great”); 2. printf (“Pakistan \nis \ngreat”);

3. printf(“Pakistan\nZinda\tbad”); 4. printf(“*\n**\n***\n”);

5. printf(“123\t”); 6. char ch1=’A’, ch2=’B’, ch3=’C’;


printf(“456”); printf(“%c\n%c\n%c”,ch1, ch2, ch3);
printf(“\n 789”);

7. printf(“\”Pakistan Zindabad \””); 8. char ch1=’A’ , ch2=’B’, ch3=’C’;


printf(“%c\t%c\t%c”, ch1, ch2, ch3);

9. int x=10; 10. int m=5,n=6;


printf(“Given = %d \n Mod=%d”, x, x%2) printf(“%d %d %d” ,m, n, m*n);

11. printf(“Islamabad\r Lahore”); 12. printf(“*\n**\n***\n****\n*****”);

13. char ch1=’A’ , ch2=’B’, ch3=’C’; 14. float i=2.099;


printf(“Character \t %c \t %c”, ch2, ch3); printf(“%5.1f”, i);

15. float a=14.199; 16. float a=14.199;


printf(“%5.0f”, a); printf(“%0.0f”, a);

17. float a=1.1; 18. float x=12.11111;


printf(“%7.4f”, a); printf(“%2.4f”, a);

19. float f=6.1455; 20. char ch1=’A’, ch2=’+’, ch3=’B’;


printf(“%6.2f”, f); printf(“%c %c %c”, ch1, ch2, ch3);

21. hfloat f = 5.6789; 22. int i=20;


printf(“f=%3.3f”, f); printf(“%3d”, i);

23. float f = 5.14159; 24. float f=6.1415;


printf(“f=%0.0f”, f); printf(“%6.2f”, f);

25. float f = 3.6780; 26. int i=10;


printf(“value is %f”, f); printf(“%6d”, i);

27. printf(“%0.3f”, 2.3); 28. printf(“%.3f”,7.2349);

29. int a, b, c; 30. int x, a, b, n;


a=5; x=500;
b=a; a=x%100;
c=b; b= x/10;
printf(“%d %d %d”, a, b, c); n= x% 10;
printf(“%d %d”, b, a);
31. int a=5; 32. int a =20;
a*=4; printf(“%d”, a%10);
printf(“Result is %d”, a);

33. int x =5; 34. int x=10, y=20, z;


int y=-x; z=x;
printf(“%d %d”, x, y); x=y;
y=z;
printf(“%d %d”, x, y);

35. int a, b, c; 36. int x=65;


a=5; printf(“%d %d %d”,x+y, y-x, z-x);
b=8;
c=a*b;
printf(“Product = %d ”, n*2);
Find Errors in the following code segments:
1. 2. void Main ()
Printf(“Enter Value”); {
scanf(“%f”, r); printf(“Pakistan”)
}
void main()
Clrscr(); prnitf(“Program”);
{ getch[];
printf(“ “Lahore” ”);
}
3. #includes<stdio.h> 4. #include<stdio.h>
void main() void main ()
{ printf(“%d Karachi”);
print(“C-Language”); }
}
5. 6. {
{ int c = 9;
Float x = 22.55; printf(“%d” c)
printf(“%F”, x); }
}
7. 8.
{ {
Int x=5 int a;
Printf(“%d”,x; printf(Enter value);
} scanf(“%f”, &a);

9. 10.
void main () void main<>
{ char ch;
flaot x=1.5 printf(“Enter character”);
printf(“%n”, x); scanf((“%c”,ch);
}
11. 12. void main ()
float area, rad = 3.3; [
area = 3.14 x rad * rad; x =2;
printf(“Area = %f”, Area); y= 8;
x+y = z;
printf(“%d”,z);
]

13. Char ch 14.


print(“enter character”); {
ch = getch(); printf(“Enter number = ”)
printf(“\n”, Ch); scanf(“%d”,&n));
}
15. 16.
Void main() void main()
{ {
int a=20; int a = 20;
print(“%f”, a) print f(“%d”, a);
getch; getch(6);
} }

17. voidmain() 18. Float f;


{ printf(“Enter a number);
char c1, c2; scanf(“\f”, &f);
c1 = X; printf(“Number = ”, n);
c2 = Y;
}
19. void main() 20. void main()
{ {
scanf(“%d %c %d”, a ,c ,b); Float f=43.09;
scanf(“%5..6f”, f);
}
}
21. void main() 22. void main()
{ {
int a, b, c; int a, b, c;
Crlscr(); crlsrc();
scanf(“Enter Values”, &a ,&c ,&b); printf(“%a %a %a”, &a ,&c ,&b);
getch(3);
} }
23. void main() 24. void main()
{ {
int a; int m, n;
crlscr[]; crlscr(3);
printf[“Values”, a]; printf(“%d %d”, &m &n);
getch()
} }

You might also like