Important C Program For Practical
Important C Program For Practical
h>
void main ()
int x, Yi
float a, b;
printf ("Enter two integers: "):
scanf ("d d", áx, 6y) ;
printf ("\nEnter two float: "):
scanf ("f f", Ea, cb) ;
:
Print£ ("Integer: \nSum: d\nProduct: dl",
x + Y, x * y);
printf("Float:\nSum: £\nProduct f\n", a
+ b, a * b) ;:
Integer:
Sum:5
Product: 6
Float:
Sum: 6.0000000
Product: 8.750000
#include<stdio.h>
void main ()
float a, b;
printf("\nEnter two float: "):
scan£ ("f f", Ga, cb) ;
printf ("Float:\nDifference: %f\nDivision :
£\n", a-b, a ;
/b)
Difference: 0.000000
Division: 1.000000
#include<stdio. h>
void main ()
Sum: 7.500000
Avg: 2.500000
#include<stdio .h>
void mainn()
float x;
printf ("Enter a number: "):
scanf ("d", sx) ;
printf("\nCube: %d", x * x * x) ;
Enter a number: 2
Cube: 8
#include<s tdio .h>
void main ()
loat a, b, ci
float s, ans 0;=
print£ ("Enter three sides of the
triangle\n");
scanf (" f 8f", Ea,
s = (a + b + c) / 2;
sb, &c) ;
ans = sqrt(s * (s-a) * (s-b) * (s-c));
printf("Area of triangle is:$f", ans) :
L
Enter three sides of the triangle
2
m3
4
Area of triangle is: 2.904737
#include<stdio. h>
void main ()
int length;
print£ ("Enter length\n");
scanf ("d", 6length) ;
print£ ("Area: td\nPerimeter: td\n", length
* length, 4 * length) ;
Enter length
3
Area: 9
Perimeter: 12
#include<stdio.h>
void main ()
float side;
printf("Enter side\n") :
scanf ("f", Sside) ;
print£ ("\nSuraface Area of cube =$£\nVolume of
)
cube =
,
£\n", side * side side * side * side) ,
Enter side
2
Surface Area of cube = 4.000000
Volume of cube =8.000000
#include<stdio. h>
void main ()
float F;://fahrenheit
float C;l/celcius
printf ("Enter Temperature in Celcius\n" ):
scanf ("f", EC) ;
F = (C * 9 / 5) 32;+
printf ("Temperature in Fahrenheit £", F) ;
float F://fahrenheit
float C;//celcius
printf ("Enter Temperature in Fahrenheit\n" ):
scanf ("f", 6F) ;
C = (F -
32) * 5 / 9;
printf ("Temperature in Centigrade =
f", C);
int n;
printf("Please Enter a number: "):
scanf ("d", Sn ) ;
i£(n 20)
printf ("Even.") :
else
printf ("odd..") :
#include<stdio.h>
void main ()
int x, Y, z;
print£ ("Enter three numbers\n") :
scanf ("d d d", Ex, 6y, z);
if (x>y)
if (x > z)
else
printf ("d is greatest\n", x) ;
Printf("d is greatest\n", z) ;
else
{
if (y > z)
printf ("%d is greatest\n", y):
else
Printf("d is greatest\n", z) ;
int x;
printf ("Enter a number\n") ;
scanf ("d" ,Ex):
if (x!=1 &6 x!=2)
:
printf ("Error")
Enter a number
3
Error
#include<stdio .h>
void main ()
float percentage:
printf ("Enter percentage\n") ;
if (percentage =
scanf ("f" ,spercentage)
printf ("A+").
80)
:
Enter percentage
67
B
#include<s tdio .h>
void main ()
int i = 1;
while (i <= 10)
int i = 1;
while (i <- 10)
i£ (i 20)
Printf ("d ", i) ;
it+;
#include<stdio .h>
void main ()
int i = 1;
while (i <= 10)
if(i 2 != 0)
printf ("%d ", i) :
i++;
#include<stdio. h>
void main ()
int i = 10;
while (i >= 1)
Enter num
7
11235813
#include<stdio.h>
void main ()
int n, i =
1, j =1;
printf("Enter the number of rows\n"):
scanf ("d", &n) ;
while (i <= n)
{
j= 1;
while (j i)<
printf ("*"):
)
printf ("\n") ;
it+;
#include<stdio.h>
void main ()
i=0;
while (i<10)
if (a[i]%2!=0)
i++;
printf ("%d ",a [i]) ;
Enter number 1 =2
Enter number 2 =3
Enter number 3 =6
Enter number 4 =1
Enter number 5 = 78
Enter number 6 =23
Enter number 7 =19
Enter number 8= 23
Enter number 9 =4
Enter number 10 = 6
3123 19 23
#include<stdio .h>
void main ()
int n;
printf("Enter a 5 digit num : "):
scanf ("d" ,sn) :
while (n!=0)
print£("%d",
„n810) :
n=n/10;
Practical Notebook Computer Science - 10
Constant is a quantity whose value cannot be changed; it cannot be changed like a variable. There are
numeric constants and string constants.
What is a Numeric Constant?
Numeric constant consists of integers, single-precisionor double- precisionnumbers.
What is a String Constant?
A String constant is a sequence of alphanumeric characters enclosed in double quotation marks. The
maximum length of a string constant is 255 characters.
What is a Direct Mode?
When GW-BASIC is loaded, it shows OK message, it is in Direct Mode. In this mode GW-BASIC commands
are executed as they are typed. Results are displayed immediately but the commands are lost after
execution.
What is an Indirect Mode?
The Indirect mode is used to type the programs. The program loaded in memory is executed by entering
RUN Command.
What is a Flow Chart?
Flowchart is thepictorial representationof an algorithm.We can present the flow of data in visual form with
a Flowchart.
What is an Algorithm?
An Algorithm is a step by step procedure for solving a problem e.g.. a recipe for baking a cake is an
algorithm?
What are logicalerrors?
Such errors are called logical errors that are caused in a program due to improperuse of symbolsand date
or wrong use of formula.
What areSyntax Errors?
Syntax errors occur when the program violates one or more grammatical rules of the programing
language. These errors are detected atcompile time.
What is a Loop?
Loop is a technique to execute a setof statement repeatedly.
What is an array?
Such collection of contiguous memory collections is called arraywhich can storedata of sametype.
54
Practical Notebook Computer Science -10
What is compiler?
A compiler is a software that is responsible for conversion of a computer program written in some
programming language to machine language code.
Define Integrated Development Environment (IDE)?
A software that provides a programming environment which facilitates the programmer in writing and
executing computer programs is known asan lntegrated Development Environment (1DE).
What is variable initialization?
Assigning value to a variable for the first time is called variable initialization. The variablecan be initialized
atthetime of declarationor afterdeclaration.
55