Writing a C Program with answers
Writing a C Program with answers
JV
The skeletal format of a C language program consists of various elements such as
Variable declaration
___________________________, Executable
_________________________ statements and other
functions.
non executable
Program comments are _______________________________ statements that are used
Library functions
______________________________________ execute certain task within a program
such as I/O operations, display output to the monitor, manipulate string operations, perform
main()
All C programs must have a function called __________________. This special function
driver function
also called _____________________________ marks the point where C program begins
execution.
variables
It is necessary to declare the ___________________ which are used in the program. The
declaration includes the type of the variable and its name. For example, int cs_mark; is a
integer
variable of type ____________________ cs_mark
having the name ________________
_________________________
Assignment statements can be used to assign or initialise values to
the variables. It should be noted that initialising the variables with a value is not mandatory.
Page 1
Complete the Lesson Summary (Contd …) HGC
9
JV
Executable
_________________________ statements must follow the variable declarations to
.c
completed source code is saved with the _____________ extension and finally compiled to
Run → Run
run the program using _________________________
STRUCTURE OF A C PROGRAM
Teacher’s Signature:
I. Circle the word that is associated with the word in the first column HGC
9
JV
1. Function sub main( ) add
2. Assignment 10 a=10 a
W-2
3. Comment /* */ <!-- -- > “
II. Arrange the words in the box under the correct headings
1. Non-executable statements
b
a. stdio.h b. Comment line c. conio.h
2. Driver Functions
a
a. main( ) b. Main( ) c. MAIN( )
3. Output Statement
c
a. stdio.h b. string.h c. printf( )
4. Input Statement
a. printf( ) b. scanf( ) c. main( )
b
5. Collection of functions within a program
a. Library function b. Input function c. Output function
a
Page 1
IV. Mark the program units in the box provided HGC
9
JV
Comment
/* C Program to find the product of two numbers */
line Library
#include <stdio.h> function
Function Name
main( )
{ Start of W-2
function
int a = 5; Assignment
Statement
int b = 10; Variable
int prod; Declaration
prod = a * b ; Program
printf (“ The product of two numbers is: %d”,prod); statements
getch( );
End of
} function
#include<stdio.h>
main() { Enter Dividend
int dividend, divisor, quotient, remainder;
52
clrscr();
printf("Enter Dividend \n"); Enter Divisor
scanf("%d",÷nd); 5
printf("Enter Divisor \n");
Quotient=10
scanf("%d",&divisor);
quotient=dividend/divisor; Remainder = 2
remainder=dividend%divisor;
printf("Quotient=%d \n",quotient);
printf("Remainder=%d\n",remainder);
getch();
}
VI. Find the error and rewrite the code in the space provided
getch( );
} }
Teacher’s Signature:
I. Write a C program to display the following output HGC
9
JV
Assessment Report
Name : Rithul .C
Percentage in topics covered:-
C++ : 94%
#include<stdio.h> O-1
main()
clrscr();
printf("C++ \t \t : \t 94%");
getch();
II. Write a program to extract the unit’s digit of an accepted integer number
#include<stdio.h>
main() {
int digit;
clrscr();
printf("Enter a number");
scanf("%ld",&num);
digit=num%10;
JV
and seconds
#include<stdio.h>
main() {
int hour,min,sec; O-1
clrscr();
printf("Enter the no: of hours\n");
scanf("%d",&hour);
min=hour*60;
sec=hour*3600;
printf("Minutes = %d\n",min);
printf("Seconds = %d",sec);
getch();
}
IV. Write a program to accept numbers and find the sqrt and power of the numbers
#include<stdio.h>
#include<math.h>
main() {
int no,sqroot,exp,sq;
clrscr();
scanf("%d %d",&no,&exp);
sqroot=sqrt(no);
sq=pow(no,exp);
Teacher’s Signature: