0% found this document useful (0 votes)
80 views26 pages

Important C Program For Practical

The document contains a series of C programming code snippets demonstrating various programming concepts such as input/output, arithmetic operations, control structures, and data types. It also includes a section on viva questions and answers related to programming fundamentals, including definitions of variables, constants, algorithms, and error types. Overall, it serves as a practical notebook for Computer Science students, particularly those in class 10.

Uploaded by

whitestone201052
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)
80 views26 pages

Important C Program For Practical

The document contains a series of C programming code snippets demonstrating various programming concepts such as input/output, arithmetic operations, control structures, and data types. It also includes a section on viva questions and answers related to programming fundamentals, including definitions of variables, constants, algorithms, and error types. Overall, it serves as a practical notebook for Computer Science students, particularly those in class 10.

Uploaded by

whitestone201052
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/ 26

#include<stdio .

h>
void main ()

printf ("My Name is:


\tMuhammad\n_\bHassan\a \nI study in class
10th\t bye \n") :
1/single line comment
/*
multi
line
comment
*/

My Name is: Muhammad


Hassan
Istudy in class 10th bye
#include<stdio .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) ;:

Enter two integers: 2


3

Enter two float: 2.5


3.5

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)

Enter two float: 2.5


2.5
Float:

Difference: 0.000000
Division: 1.000000
#include<stdio. h>
void main ()

x = 1.5, y= 2.5, z = 3.5;


float
Printf ("Sum: 8f\nAvg: f\n", x + y+ z, (x
+ y+ z) / 3);

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

int length, width;


printf ("Enter length and width\n"):
scanf ("d d", 6length, Swidth );
printf ("Area: td", length * width) ;
Enter length and width
2
4
Area: 8
#include<stdio .h>
#include<math. 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 radius, height; of Cylinder


printf ("Enter Radius and Heightof Cylinder\n") ;
scanf("f 8f", sradius sheight);
printf ("\nVolume of Cylinder
, =
$£", (22 *
radius * radius * height / 7)):
)

Enter Radius and Height of Cylinder


3
4

Volume of Cylinder = 113.142857


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

Enter Temperature in Celcius


36.8
Temperature in Fahrenheit =98.239998
#include<stdio.h>
void main ()

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

Enter Temperature in Fahrenheit


98.6

Temperature in Centigrade =37.000000


#include<stdio .h>
void main ()

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

Enter three numbers


2
5
3
5 is greatest
#include<stdio.h>
void main ()

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)
:

else if(percentage >= 70)


printf ("A"):
else if(percentage >= 60)
printf ("B") :
else if(percentage >= 50)
printf ("C") :
else if(percentage >= 35)
printf ("D"):
else
printf ("F") ;

Enter percentage
67
B
#include<s tdio .h>
void main ()

int i = 1;
while (i <= 10)

printf ("d ", i) ;


it+;
#include<s tdio.h>
void main ()

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)

printf ("%d ", i):


i--;
#include<stdio .h>
void main ()

int il = 1, i2 =1, i3 = 010110, i=1, num;


:
printf ("Enter num\n")
scan£ ("d", snum) :
while (i <= num)

Printf ("d ", i1)


i3 i2;
;
i2 += il;
il = i3;
it+;

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

int a[10] ,i=0


while (i<10)
;
printf ("Enter number d ",i+1):
scan£ ("d", &a[i]) ;
i++;

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

VIVA QUESTIONS AND ANSWERS


What arenumeric Variables?
Numeric variables arethosevariables that can storenumeric values.
What are stringvariables?
Stringvariables are thosevariables that can store sequence of characters.
What is constant?

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

VIVA QUESTIONS AND ANSWERS

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.

What arecomment statements and why do weaddcomments?


Comments are the statements that are ignored by the compiler and do not get executed. To include
additionalinformation about theprogram,comments can be used.

55

You might also like