0% found this document useful (0 votes)
6 views

Writing a C Program with answers

Uploaded by

shreeprakash1620
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Writing a C Program with answers

Uploaded by

shreeprakash1620
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Complete the Lesson Summary  HGC

JV
The skeletal format of a C language program consists of various elements such as

Program comments, ____________________________,


Library function ___________________________,
Function main() LS-2

Variable declaration
___________________________, Executable
_________________________ statements and other

functions.

non executable
Program comments are _______________________________ statements that are used

by the author to add description wherever required in the program.

Library functions
______________________________________ execute certain task within a program

such as I/O operations, display output to the monitor, manipulate string operations, perform

math functions etc.

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

complete the program.


LS-2

The C program source code is written using a ___________________


Turbo C editor. The

.c
completed source code is saved with the _____________ extension and finally compiled to

Run → Run
run the program using _________________________

STRUCTURE OF A C PROGRAM

/* Skeletal format of C */ - Program comments


#include<stdio.h> - Library Function
main( ) - Driver Function
{ - Start of driver function
int i; - Variable declaration
i = 5; - Assignment statement
::::::::::::::::: - Program statements
:::::::::::::::::
getch( ); - Function name
} - End of driver function
add( )
…………..
……………
sub( ) - Other functions
…………..
……………



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 /* */ <!-- -- > “

4. Library function scanf( ) printf( ) <string.h>

5. Compile & Run Windows→Close File→Quit Run→Run

6. Save as .C .C++ .Cpp

7. Editor Dennis Ritchie Turbo C C

II. Arrange the words in the box under the correct headings

main( ) int sal=2000 int age clrscr( ) getch( )


float avg=90.5 char grade=’A’ char grade float mark

Variable declaration Functions Assignment statements


statements

int age main() int sal=2000

char grade clrscr() float avg=90.5

float mark getch() char grade= ‘A’

III. Fill in the box with the correct option

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

V. Complete the output for the following program

#include<stdio.h>
main() { Enter Dividend
int dividend, divisor, quotient, remainder;
52
clrscr();
printf("Enter Dividend \n"); Enter Divisor
scanf("%d",&dividend); 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

#include <Stdio.h> #include <stdio.h>


main( ) main( )
{ {
int price=100, quantity=10; int price=100, quantity=10;
int amt, discont; int amount, discount;
amount=price*quantity; amount=price*quantity;
discount=amount/10;
printf(“Discount:\n”,discount)
discount=amount/10;
printf(“Discount:\%dn”,discount);

printf(“Amount after discount %d\n”,(amount-discount),“Rs”);
getch( );
printf(“Amount after discount %d\n”,(amount-discount),“Rs”);

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("\t \t Assessment Report \n");

printf("Name \t \t : \t Rithul.c \n");

printf("Percentage in topics covered:-\n");

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() {

long int num;

int digit;

clrscr();

printf("Enter a number");

scanf("%ld",&num);

digit=num%10;

printf("Units position of the number = %d\n",digit); 


getch();

}
Page 1

III. Accept the hours from the user and display the output converting it into minutes HGC
9

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

printf("Enter no’s – sqroot, exp\n");

scanf("%d %d",&no,&exp);

sqroot=sqrt(no);

printf("Square root of %d is %d \n",no,sqroot");

sq=pow(no,exp);

printf("%d to the power of %d is %d",no,exp,sq);




getch();

Teacher’s Signature:

You might also like