Escolar Documentos
Profissional Documentos
Cultura Documentos
Assignment no. 1
Q1.what is formatted and unformatted I/O functions ? explain. Ans. Formatted function : In formatted I/O category ,we have scanf()
function for input and printf() function for output .the working of these function is described in this section. These functions allow us to supply the input in a fixed format and let us obtain the output in the specified form. Formatted output converts the internal binary representation of the data to ASCII characters which are written to the output file. Formatted input reads characters from the input file and convert them into internal form.
Q2. What do you mean by type conversion? What is EOF? How is it entered from keyboard? Explain both with example Ans Type conversion: Type conversion" means pretty much the
same thing in any programming language, and it's difficult to explain unless you already know something about programming. Basically, a computer program can represent the number "25" (for example) in several ways. Type conversion is a way of converting between those ways. C is "strongly typed", which means the compiler will usually give you an error if you try to use a variable of one type in a way that expects a different type. Some languages (for example, Perl) are not strongly typed, and you can get away with these kinds of shenanigans, but in C you'd usually have to do "type conversion" to avoid the error. Example of type conversion:/* atoi: convert s to integer */ #include<stdio.h> int atoi(char s[]) { int i, n; n = 0; for (i = 0; s[i] >= '0' && s[i] <= '9'; ++i) n = 10 * n + (s[i] - '0'); return n;
Q3. How will you replace blank spaces with zeros using output function in case of integer data type?
Ans:#include<stdio.h> #include<conio.h> void main() { Int a[10], b,n,I; printf (enter the no:); scanf (%d,&n); for (i=0; i<n; i++) { scanf(%d,&a[i]); } printf(the no is:); for(i=0;i<n;i++)
{ If(a[i]==0) { printf(\0); } else { printf(%d,a[i]); } getch(); } Q4. What will be the output and give its descriptions:
void main(){ int a,b; int sum; printf("Enter any two integers: "); scanf("%d%d",&a,&b); sum = a - ~b -1; printf("Sum of two integers: %d",sum); } Ans.output will be:Enter any two integers:4 3 Sum=1 Firstly this program will converted into binary to decimal then calculate bs complement then subtract one from complement and the result will be subtracted from a. (b) #include<stdio.h> #define L 10 void main(){ auto money=10; switch(money,money*2){ case L: printf("Willian"); break;
case L*2:printf("Warren"); break; case L*3:printf("Carlos"); break; default: printf("Lawrence"); case L*4:printf("Inqvar"); break; } } Ans.output is:The output is warren .It give warren because the default value of L is 10 in which when it come case 2 it print it.because the value of L is defined outside the main programme.then in switch(10,10*2),then the control goes to the caseL*2 or case 20. So the output will be warren.
Q5.To show the importance of else if by making a game in which you have reach coordinates x=0 , y=0 when you are initially at x=10 , y=10.
#include<stdio.h> #include<conio.h> Void main() { Int x=10,y=10; If ((x>5)&&(y>5)) { Printf(You win this game); } Else if ((x>0)&&(y>0)) { Printf(You are vry close); } Else { Printf(losser); } getch(); }
Q6.To Convert the time in seconds to the time in hours, minutes and seconds and then display what time of the day it is?
#include<stdio.h> #include<conio.h> Void main() { Int s,m,h; Clrscr(); Printf(enter seconds); Scanf(%d,&s); h=s/3600; s=s%3600; m=s/60; s=s%60; printf(%dHours%dMinutes%dSeconds,h,m,s); getch(); }