You are on page 1of 2

DHARMSINH DESAI INSTITUTE OF TECHNOLOGY , NADIAD ( Deemed University ) Computer Programming SEM - I ( EC / IC / CH /CL ) ASSIGNMENT / TUTORIAL Chapter : 4

Q.1 Q.2 Q.3 Q.4 Why one should include <math.h> file ? "The contents of the header file become part of the source code when it is compiled" Justify. Explain the different statements by which one can read a character from the keyboard. Execute the following programs & comment on the output. Program: 1 #include<stdio.h> #include<conio.h> void main( ) { HINT char ch; clrscr( ); // give input as wwf < press enter > ch = getchar( ); // give input as < press enter > printf("\n ch = %c",ch); // give input as w < press enter > ch = getchar( ); printf("\n ch = %c",ch); } Program: 2 #include<stdio.h> #include<conio.h> void main( ) { HINT char ch; clrscr( ); // give input as wwf < press enter > ch = getchar( ); // give input as < press enter > putchar(ch); // give input as w < press enter > ch = getche( ); putchar(ch); } 1. Interchange getchar & getche in the above program & check the output. 2. Also use getch( ) in place of getche( ). Write a program in C to convert an uppercase character ( inputted through keyboard ) into a lowercase format. ( use library function(s) of <conio.h> file ) Write a program in C for checking validity of an entered character as a first character of a C variable. Display appropriate message. Write the following program on your terminal , apply the given inputs & comment on the output. #include<stdio.h> #include<conio.h> void main( ) { int a,b,c,d,e,f,g; clrscr( ); printf(" Enter an integer number .. "); scanf("%d",&a); // enter number as 11 22 33 < press enter > printf(" Entered number is accepted as %d \n",a); printf(" Now enter three integer numbers ..."); scanf("%d %d %d",&b,&c,&d); // enter number as 44 55 66 < press enter > printf(" Accepted values are b = %d \n c = %d \n d = %d \n",b,c,d); printf(" Now enter three values more ..." ); scanf("%d %d %*d",&e,&f,&g); // enter number as 77 88 99 < press enter > printf(" %d %d %d ", e,f,g); Also make use of width specifier in the above program & check the output.

Q.4 Q.5 Q.6

Q.7

Q.8

Q.9

Justify the following statements. 1. "Any unread data items will be considered as a part of the data input line to the next scanf ( ) call" . 2. "Width specifier w should be large enough to contain the input data size". 3. "Whenever data mismatch founds scanf( ) will terminate the program execution". 4. "Value returned by the scanf ( ) can be assigned to a float variable". What would be the values stored in the variables a & ch when the data 2002, DDIT is entered in as a response to the following statement(s). 1. scanf("%d %c",&a,&ch); 2. scanf("%c %d",&a,&ch); 3. scanf("%c %d",&ch &a); 4. scanf("%s %c",&a &ch); Show the exact output of the following program(s). void main( ) { int count=1234 , m ,a ,b,c; float price = - 567.89; char city[6] = "Nadiad" /* data stored in is Nadiad - an array of six characters */ m = scanf (" %d , %*d , %d " , &a , &b , &c); printf("%d\ n", m); m = scanf (" %d , %* , %d " , &a , &b , &c); printf("%d\ n", m); printf(" %d %f \n", count , price ); printf(" %2d \n %f \n ", count , price ); printf(" %d %f \n", price , count ); printf(" %10dxxxxx %5.2f \n ", count , price ); printf(" %s \n ", city ); printf(" %-10d %-15s ", count , city ); }

You might also like