Lab 2
Lab 2
Lab 2
a Login to default directory and see if the directory LAB2 exists. [Hint. ls]
b If the directory LAB2 exists, then remove it. [Hint. To remove the directory LAB2,
the following steps are needed (i) Go to that directory (cd LAB2); (ii) Remove its
content (rm -i *); (iii) Go back to the previous directory (cd ..); (iv) Remove the
directory (rmdir LAB2).]
c Create the directory LAB2 (mkdir LAB2) and go to the directory (cd LAB2).
#include<stdio.h>
int main(void)
{ int a=123,b=-123,c=12345;
printf("%2d\n",c);
printf("%10.2d\n",c);
printf("%-10.2d\n",c);
printf("%-7d\n",a);
printf("%07.2d\n",a);
printf("%07d\n",a);
printf("%+0-9.4d\n",a);
printf("%+09.4d\n",a);
printf("%+07d\n",a);
printf("%+07.4d\n",a);
printf("%+-07.4d\n",a);
printf("%-08d\n",b);
printf("%-08.2d\n",b);
printf("%-8.4d\n",b);
return 0;
}
#include <stdio.h>
int main(void)
{ double a=12345.6789;
printf("\nFormatting with %%e or %%E\n");
printf("%e\n",a);
printf("%5e\n",a);
printf("%5.2E\n",a);
printf("%5.0E\n",a);
printf("%#5.0E\n",a);
printf("%05e\n",a);
printf("%010.2e\n",a);
printf("%+010.1e\n",a);
printf("\nFormatting with %%lf\n");
printf("%lf\n",a);
printf("%5lf\n",a);
printf("%4.2lf\n",a);
printf("%10.2lf\n",a);
printf("%-10.2lf\n",a);
printf("%10.0lf\n",a);
printf("%#10.0lf\n",a);
printf("%+010.2lf\n",-a);
printf("\nFormatting with %%g \n");
printf("%g\n",a);
printf("%9g\n",a);
printf("%4.3g\n",a);
printf("%4.5g\n",a);
printf("%#4.5g\n",a);
printf("%#9.5g\n",a);
printf("%5.4g\n",a);
return(0);
}
3. Find the errors (if any) in the following program: (You may type the program in a file
fun.c and identify the erros during compilation)
/* Is it a C program?*/
#include <stdio.h>
int
main(
)
{
int a,b
,c;
a=
2.45;
b
=a+2;
printf(
"Enter an integer:");
scanf(
"%d",
&c);
printf(
"%d %d %d\n",a,
b,c);
return
0;
}
4. Find the errors (if any) in the following program assuming that the #define statements
are correct. (You may type the program in a file err.c and identify the erros during
compilation). Modify the code so that it becomes error free.