Vous êtes sur la page 1sur 7

ASSIGNMEN T ON CAP-502

SUBMITTED TO:SUBMITTED BY:MISS.KIRAN SHARMA ROLL NO:1207B43 SECTION:1207 REG.NO.11209941

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.

Scanf() function: this function allowes us to input data in a fixed


format .Its syntax is: Scanf(format string,list of address of variables); Printf() function: The printf() function allows to output the data in a fix format .its general form looks like: Printf(format string,list of variables);

Unformatted functions: In the unformatted I/O category ,we


have function for performing input/output of one character at a time,known as character I/O function and function that perform input/output of one string at a time, known as string I/O functions .these are described in the next section. Getchar() function :this function returns a character that has been recently typed,the typed Character is echoed to the computer screen.after typing the appropriate character,the user is required to press enter key. Getche() function : like getch() function ,this function also return character that hs been recently typed.the typed character is also echoed to the computer screen.but the user is not required to press enter key after typing character. Getch() function :This function too return a character that has been recently typed.But neither the user is required to press enter key after entering the character nor the typed character is echoed to the computer screen.this function has advantage over the other function in the application where the user wants to hide the input. Putchar() function: this function output a character constant or a character variable to the standard output device.

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;

EOF: In computing, end of file is a condition in a computer operating


system where no more data can be read from a data source. The data source is usually called a file or stream.In the C Standard Library, the character reading functions such as getchar return a value equal to the symbolic value (macro) EOF to indicate that an end-of-file condition has occurred. The actual value of EOF is system-dependent (but is commonly -1, such as in glibc[1]) and is unequal to any valid character code. Block-reading functions return the number of bytes read, and if this is fewer than asked for, then the end of file was reached Depending on the operating system, this character will only work if it's the first character on a line, i.e. the first character after an Enter. Since console input is often line-oriented, the system may also not recognize the EOF character until after you've followed it up with an Enter.And yes, if that character is recognized as an EOF, then your program will never see the actual character. Instead, a C program will get a -1 from getchar(). Example of EOF:#include<stdio.h> Main() { Long nc; nc=0; while(getch()!=eof) ++nc; Pintf(%d\n,nc); }

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(); }

Vous aimerez peut-être aussi