0% found this document useful (0 votes)
5 views17 pages

pst

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)
5 views17 pages

pst

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/ 17

i++) num/2; <= i 2; =(i for

&num)
scanf("%d",
;
:"); number printf("\n
Enter
a
; =flag i, num, int
main() void
<stdio.h> #include
not. prime
or number
is whether
the check Program
to Program
3:
num3);number.", largest the isprintf(
"%d
else
num2);number.", largest thprintf("%d
e is
num3) >=
num2 ( if else
number.",num1); largest tprintf("%d
he is
num3) >=num1 &&
num2 >=
(num1 if
&num3); &num2, &num1, %d", scanf("%d
%d
");numbers: threeprintf("Enter
any
number. largest the is 56 num3; num2, num1, int
56 numbers:
4 12 three any Enter
main() void
Output:
<stdio.h> #include
three. biggest
of the find numbers
and three read Program
to Program
2:
}
",circum); %f :Circle
is Circumference
aof printf("\n
",area); %f
Circle
: aprintf("\n
ofArea
radius; *PI *circum
2=
radius; radius* *PI area
=
scanf("%d",&radius);
");Circle: Radius
of the Enter printf("
circum; area,
PI=3.14, float
radius; int
6.280000 :Circle
is Circumference
a of
3.140000 Circle: a of
Area
main() void
Circle:
1 Radius
of the Enter
Output:
#include<stdio.h>
circumference. and area find toand circle radius
aof read Program
to Program
1:
Techniques Solving Problem A.2
while(1)
\n") end the Printf("Enter
pri
at 999 ("Enter
ntf
as
aswell positive both numbers the
\n");negative
sum=0; x,int
include<stdio.h> main() void
numbers positive only of
sum the find to Program
5:
and presses
999 the till
user continuously keyboard fromnumbers to
read Program
palindrome"); anot number
is printf("\n
The
else
palindrome"; ) anumber
is printf("\n
The
rev) = (x if
%d",rev) ; number
= the Reverse
of printf("\n
sum); %d", digits= printf("\n
ofSum
rev=rev*10+d;
palindrome anot number
is The
sum=sum+d;
num=num/10;
4321 number the Reverse
of
d=num%10;
10digits ofSum
1234number: the Enter while(num)
2:Run
X=numj
palindrome "%d",&num) ; scanf(
number
a1s The ");number: printf("Enter
the
252 number the Reverse
of
digits
9 ofSum rev=0,d,x; sum=0, num, int
252number: the Enter
1:Run
Output: main() Void
#include<stdio.
h>
check andnumber reverse
the digits, palindrome. for it
the sum
of number,
the find reada Program Program
4:
to
number Prime a1s 13 number",n):
:13 number Enter
a Prime printf("%d
ais
Run2: number",n): else
Prime anotorintf("%d
is
number Prime 1) (lag if
anot is 4
number
4: Entera
}
1:Run break; 1; flag
Output:
0) n%1 (num if
A,3
Programs Lab
improve
... to need Youfailed, Sorry,
student:
32 percentage
the of the Enter
3:Run
Class second Scored
student:
59 thpercentage
e of the Enter
2:Run
distinction with Class First Congratulations
Scored !
student:
88 e of
thpercentage the Enter
1:Run
Output:
}
improve..."); toneed You failed,
printf("Sorry,
else
"); Classprintf("Scored
Third
(percent>=35) if
else
"); Class printf("Scored
second
(percent>=50) ifelse
Class First Scored
"); printf("Congratulations!
(percent>=60) ifelse
distinction"); printf("Congratulations!
with Class First Scored
(percent>=75) if
&percent); scanf("%F",
student:
"); percentage
the of printf("Enter
the
percent; float
{
main() void
#include<stdio.h>
else-if of
ladder) (Demonstration Program
6:
to and marks percentage
of to
read Program
essageappropriate display
}
Positive the printf("\n
ofSum
sum); %d", Entered
is: Numbers
Entered Numbers Positive the ofSum
210 is: Sum=sum+x;
(x>0) if
-5 50 30 -20 -10 20 10 break;
999 100
end the at999 Enter (x==999) if
posltive both numbers the Enter scanf("%d",
&x);
egatiue aswell as
Output:
Techniques Solving Problem A.4
<stdio.h>
#include If If If
main()
void the Progrann 7:
the the

discriminant discriminant discriminant


else //
printf("Enterdouble
discriminant
if
// Scanf("%1f
condition (discriminantcondition
if a, Program
rintf("Roots root1
f("root1 printf("root1
printf("Roots root2 root1 b,
(discriminant %1f = >
for = c, <
= for = = coefficients O 0 e
(-b (-b b*
%1f",
root2 discriminant, to
real > real find
- + 0) b
= = are - &a,
= are
== and sqrt
sqrt(discriminant)) and
4 the
root2 -b %.21f
0) real * &b, a,
real / equal (discriminant)) different a roots
(2 *&c); b
= and and
c; androot1,
and * of
%.21lf;", roots root2
a); c: root2 = =
root1quadratic
equal: different:"); roots root2 = rootl=root1=root2 =
= ");root2,
root %. /
"); / (2 2a 2a -b
21f", (2 realPart, iy-(B'
-4ac)
-b +
-b-(b'-4ac)
-b+(b'-4ac)equation
1
); * * 2a 2a
root1, a); a); -(b°-4ac) 2a -b
2a 2a
imagPart;
root
2)
;
} main()
#include<stdio.h>
{void Roots Enter Roots Enter Run2: Roots Enter Runli
Run 3: } A.6
Program 8:
Output:
n, are
coefficients are
coefficients are
coefficients else 1|
avg=sum/n;
rintf("Average (i=0;i<n;i++)
for printf(
scanf("%d",
&n); float int i; Techniques
Problem
Solving
1f
printf("\n real not real
sum=sum+marks
[i];
scanf("%F", marks roots
"Enter real: printf("Roots
printf("' realPart
root1 imagPart
and and
[30],
Program
(Demonstration
a, a, a, are
equal: root1 different:
&marks
[i]) Enter
; the b b b
= = not
of sum=, and and and
Total =
sqrt(-discriminant) -b/
the to root1 = real
Student c: c: c: %.21f+%.21f are
avg; read -1.00+1,41i (2
entered Number 1 1 root1 1 not
of 2 -3 *
singlemarks = 2 a);
root2 1 3
%d = 2 real:
of 2.00
and
marks: marks:
dimensionalscored = and
Students: root2 ");
-1.00; and
root2 /
%.2f", ", =%.2f-%.2f", (2
i+1): root2
by *
=
avg): "): array). n a);
-1.00-1.41i =
students 1.00
realPart,

and
imagPart,
find

the
realPart,
average

inagPart):
of
marks
#include<stdio.h>
main()
void Average Enter Enter Enter Enter Enter Enter
} { Program 9:
Output:
Student
Student Student
Student Student the
for(i=0;
printf("\nArray i<number;
for(i=0;
for(i=0;printf("Entered i++) printf("Enter
printf(&number); int
for(i=0;i<number; it+)Scanf("%d", of
printf("%d
",a[i]); for(3 ",a[i]); Total
printf("%d scanf("%d",
&a[i]); a[50],i,j, the
if(a[i]
a[j])
{ = "Enter 5 4 3 2
1
i number--; j--; for(k=j; = i Program enteredmarks:marks:marks:marks:marks:Number
< i+1; <
number; a[k+1];
a[k] = number; elements size k,
after j elements number; 450 498 590 525 550 of
k < tomarks:
of Students:
i++) < number; it+) remove
deleting number; the
of 522.60
are:\n the array
j++) Duplicate 5
the k++) array
"); :
");
duplicate :\n
Element
");

elements in
a
Single
is:");
Dimensional

Array.
ProgramsLab

A.7
#include<stdio.h>
main()
void 30
Array elements
Entered
30are: 30
Enter Enter
Program 10
: A.8
20 20 20 Output:
10
after 20 elements
20 size
for(c
{
printf("\nThe for(c
printf("\nThe for(c
printf("\nEnter printf("\nEnter
printf("\nEnter
for(c
scanf("%d%d", &n);&m, int
40 10 10 Techniques
Problem
Solving
printf("\n"); for(d printf("\n"); for(d for(d for(d of
n, 50
deleting 40 40
second[c][d]);
printf("%d\t", = =
scanf("%d",
printf("%d\t", &second[c][d]); = = the
0; 0; Scanf("%d",
&irst[c]
0; 0; m, 30 30 of
= = = = Program
0; C 0; C 0; C C, 50 50 the array
0; C
< < < < d, 40 40
d Second
m; d First
m; d m; d m; the array
< < < the the rows first :
n; c++) n; C++) njc++) n;c++) toduplicate 8
Matrix %d %d [10] perform
d++) Matrix d++) d++) and :
first d++) elements elements
columns [10],
[c] is: [d]);
is: [d]); addition elements
\n"); second
\n"): of of of
the the the [10] and is:
Second First
matrix:"); [1], subtraction
Matrix
Matrix sum[10][10],

: of
:
", Matrices.
m*n); m*n);
diff[10]

[10];
The The The The EnterEnter Enter
-8 10 10 10 3 6 9 897 4 1
4 -2
Subtraction Addition 12 Second
5 8 5First
2
Output:
-6 10 1 10
6 the the rows printf("\nThe for(c
printf("\nThe
7 6 3 for(c for(c for(c
-4 10 10 10
2 Matrix Matrix 9 9 and printf("\n"); for(d for(d for(d for(d
elements
elements printf("\n") ;
of printf("%d\t", = printf("%d\t",
=um[c][d]); s = =
columns diff[c]
0; 0; sum[c][d]
0; 0;
of the = = = =
is:
is: c C
the 0; 0; C 0; 0; C
Two < < <
of of Subtraction
d
< [d]
d m; d Addition
m; d m;
Two of < m; < <
Matrices the the = <
n; c++) = n;c++) n; c++)
the first[c][d] n;c++)
Matrices first[c]
SecondFirst diff[<] d++) d++) d++) d++)
matrix: of
is: the
Matrix:
of[d]
is: Matrix [d] the Two +
3 ); second[c][d];
Two second[c][a];
3 Matrices
: 1
9 2 Matrices
87 3
45
6 is:
5 6
4 7 is:
\n");
3 8
2 9 \n");
1

ProgramsLab
#include
main()int<stdio.h> }
} Program main(
void#include
)<stdio. h> A.10
Program
printf("Enter
for 1/ Scanf("%d",
printf("Fibonacci 1/&n); a int printf("\n } for int
//get scanfprintf
(
C print print = /
initialize 12: Techniques
Problem
Solving
C
=b b;a= (i a=0, fact*i;
fact = 11
printf(",%d = , (i num,
= b= :
a Write =&num);
"%d", ("\n
+ 3; 3rd the no. b=1, fact Program
1;
b; i to 1; Factorial
first i<=num; Enter
<= the of first C, a =
nth terms program
nj two n, 1, to
Series: number and a
t+i) terms i; find
i=3; of it+) number
terms from second
of to %d Factorial
%d, generate
a terms: user is :");
%d", and terms %d",
b of
a, "); FibonacciEnter fibonacci num, a
b);
Output: Number.
fact);
the
series
number
Series:

FactorialEnter
of Output:
0,
terms:
1, a
number
1, of
2, 10 5
3, is :
5
5, 120
8,
13,
21,
34
main()
void
|#include<stdio.h>
*include<string.h> maiwid n ()
<stdio.hy
luidenc
Program Program 13:
else
(value--0)
value=strcmp(cpy, if
cmp)printf(\n gets(cat);
printf("\n
printf("\n
printf("\n gets(s) ;
printf("\n value;int char printf("\nThe lien=0;nt char
: str[100];
; (cmp
gets); printf("\n while(str[len]
!='gets(str)
len++;
\8') printf
printf("\n
strcmp()
Usingprintf("\n 14:Program
s[29], ("Enter
Program
Using Enter
Enter Using Enter Using cpy[20],
Using Length the
strpy()
the strcat the strlen() a to to
String cmp String find
strcmp() String String demonstrate of
[20], the the
() Oriiginal -
- : :
to
Concatenation to Length "); cat String "); length
- [20];
be be
Strings Strings
Same");are String string
Compared Concatenated is: of
of a
is the functions. %d",len); string
are
of :
given
with %s
not Two without
and
with The Enter
Output:
Same"); %s:", Strings Copiedstring
%s Length using
the
:"String is
cpy);
is String built
S);
: of
: is%d",
%s", the
: in
strlen
%s String : function.
strcat",S,strcpy(cpy, Programming
(s)); ProgramsLab

(s, is:
cat)); 16 in
s) C
); A.11
void #include<stdio.
void /* h> UsingEnter Using Using Enter A.12
/* UsingEnter
This This
Programstrcmp()
Output:
displayMatrices(int
;i<m;i++)
tf("\nstored
are:\n");
matrices i,j;int for(i=0;i<m;i++)for(i=0;i<m;i++) addMatrices(int
printf("\nSum int e
thstrcat() he strlen()
tstrcpy() a
function function String Techniques
Problem
Solving
for(j=0;j<n;j++) for(j=0;j<n;j++)
printf("\n"); 15: String String
i,
printf("%d " sum[i][j]=a[i]
[i]+b[i]
[j]; j, - - - :
sum[m][n]; Program
is is Concatenation to
Original Length Skyward
Strings
Sameare to
used of used be be
m, Concatenated
Compared
the int to to of
m, to sum[i][il); , String
int given n, add read, the
display
n, int of given
the display with
matrices:\n"); Two is
int a[m]
the two with :string
SkywardStrings Skyward
a[m] [n],int and
matrices matrices
Skyward
[n],int
add is
b[m][n]) : is and
two Skyward :
b[m][n]) */ */ :
: Copied 7
mSkywardBooksBooks
×
n
matrices String

is
using
:
Skyward
functions.
main()
void }
void /*
This
readElements
addMatrices
displayMatrices scanf("%d
int
printf("Enter m,n,i,intj; for(i=0;i<m;i++)
printf("Enter printf("Enter
for(i=0;i<m;
i++) readElements
i,j;int
function for(1=0;i<m;i++)
printf("\n"); }
a[m] for(j=0;j<n;j++) for(j=0;j<n;j++)
printf("\n");
for(j=0;j<n;j++) printf("\n");
[n], scanf("%d",
&b[ij[3]) ; scanf("%d",
&a[i][3]); (j=0;1j<n;j++)for
%d",
",b[i][j]);
printf("%d printf("%d
(m, is
n,
(m, b[m] (int
n, &m, the %d to
a,b) (m, a, %d
n, [n]; order elements m,
read
elements
; a, b); &n); int
b); (31);
a[i] ",
n, the
of
the of of int
elements
the the a[m]
matrices
second first [n),int
of
matrix the
: matrix
"); b[m][n])
matrices
rOw-wise:
row-wise:
*/

\n",m*n);
\n",m*n);

ProgramsLab

A.13
main()
void
#include<stdio
.h> 10 10 10Sum 132 654 897 7 matrices
456Stored
123are: 1 Enter
987 Enter Enter
Program16: A.14
89 23 Output:
of
(i=0;ch[i]!='\0';i++)
for splchar_count=0;intch[100];
printf("Enter int char 65 4569 9the
(ch);
gets the
else
} if elementselements Techniques
Problem
Solving
i,alpha_count=0, given 4 order
_count++; else
alpha_count++;
if 3 789
if (ch[i] ( 2
Consonant_count++;
vowel_count++;(ch[i] spaces
Programto
string
reada 1 of of
(ch[i] matrices: of

a the the the


= >= String: and
= 'a' a' matrices:3
second first
digit_count=0, special
'0' ||
&&ch[i] matrix
&&ch[i] ch[i] "); matrix
characters.
== row-wise: 3
<= and
<= 'e' row-wise:
'z') vowel_count=0,
'9') || to
ch[i] find
||
(ch[i] the
==
number
'i'
>= consonant_count
||
ch[i] 'A' ofalphabets,
digits,
&&ch[i]
=
'o'
<= -0,
||
c] space_count=0;
Z)
vowels,consonants,
)
main()
void <stdio.h>
void #include
Program17: Consonants
Spaces
No of of
No
NoVowels of
Alphabets
Digits
No of No Enter
No of
Scanf("%d",
&number1) swapNumbers(int of Output:
Scanf("%d",
SwapNumbers&number2)
printf("Before
ntf("After printf("Enter number2;
number1,
; int
; printf( temp; *b=*b; *a= temp;
temp =int
Special a
String printf("\n
printf("\n
printf("\n
printf("\n
printf("\n
printf("\n
"Enter *aj
else
if(ch[i]
else
='
Characters
Program splchar_count++;
space_count++;
(&number1, :
#157
SwappingSwapping the the No No No No No No
*a, of of of of of of
value value 7th
int to Special
Consonants\t\t
Vowels\t\t\t
Spaces\t\t\t Alphabets\t\t
Digits\t\t\t:
the
&number2) the Swap Cross
of of *b) :2 :3 : :5 : :
11 10 16
Two
\nnumber1:numbers..number2: number1:
Bangalore-560018 Characters\t
; Numbers : :
%d",
%d",vowel_count);
: %d", :
\nnumber1: "); "); %d",
%d",consonant_count)
;
space__count)digit_count)
using : alpha_count);
%d",
%d\tnumber2:
%d\tnumber2: 20
number1:
number1:After 10 Enter Enter
Before Pointers.
Output: splchar_count);
;
Swapping Swapping the the

%d\n", %d\n", value value ;

number2:10 the
number2: 20 the of of
number1, number1,
number1:
number2:
numbers..numbers..

number2)number2); ProgramsLab
20 10

A.15
Saatvik
Smayan
Snigdha Name Students
Details: main()
void student
#include<stdio.h> A.16
Enter Enter Enter Enter struct Program18:
Output:
name, name, name, noprintf("\nstudents
Details printf("Enter i,n;
student
struct
ints[20]; percentage;
float roll;int (30];
charname
****************\n"):
printf("****
"Name\t\tRoll\t\tPercentage\n"); printf(
(i=0;i<n;i++)for :\n\n",n); scanf("%d",
for &n); Techniques
Problem
Solving
of
"%s\t\t%d\t\t%2.2f\n",
printf( printf("Enter
(i=0;i<n;i++)
scanf(
roll roll roll
students
1003 1002 1001 Roll

and and and "%s%d%f", Program


percentage
percentage
percentage no
:
3 of to
name,
99.0087.00 97.00
percentage s[i].name, students: demonstrate
of of of roll
student student
student
&s[i].roll, and
");
s[i].percentage);
s[i].roll,
s[i].name, percentage student
3: 2: 1:
Saatvik Snigdha
Smayan

&s[i].percentage); structure
of
1003 1002 1001
student
99 87 97 to
read
%d:",i+1);
records
display &

students. ofn
main()
void union_example
union
declaring
{union || struct_example
struct <stdio.h>
#include
<string.h>
#include
structure
declaring I/ Program
19:

u.decimal
.name,u.integer
nion");
"new 90; 183;
strcpy(s.name,
Structure"); S.integer
=S.decimal
"new 90; 183;
= printf("\n\nAccessing printf("Union
printf("-----Demonstration
printf("Structure
=printf("\nsizeof
= printf("
printf("\nsizeof integer;
decimal;
[20];
name
char float int decimal;
[20];
name
char
printf("***** * union 1/struct 1/ integer;
float int
creating creating
union_example
struct
Program
Data\t: variable variable
Data\t: _example
union\t
structureinteger to
integer u={18,38, for demonstrate
all for
s={18,38,
=
structure = %d = union structure
%d" = of
\t %d
%d", difference "union"};
,decimal \t and
"structure"};
sizeof deciral the
sizeof initializing and
and = difference
(u)); %.2f = initializing
union (s) %.2f
between
); \t \t
name name
members between
=STRUCTURE values
%s %s =
values
\n",u.
\n",s.iteger,
at structure
a integer,
time: &
*********\n");
UNION----\n");
--\n"); u.deciral, &
\n"); S.decimal,
union.
ProgramsLab
u.name);s.nae)

;
A.17
A.l8
Problem Solving Techniques

printf("Structure Data\t: integer = %d\t decimall = %.2f \t name =


printf("Uhion Data\t: integer = %d \t decimal = %.2f \t name = %s\n",s.iteger, s.decimal, s.narel.
%s\n",u. integer, u.decimal, u.name):
printf("\nACCessing
printf(
each member of a structure and union at a time :\n"):

printf("Structure Data\t: "); -- \n")


s.integer 240;
printf("integer = %d \t ",
s.integer);
S.decimal = 120;
printf(" decimal = %.2f \t " ) S.decimal) :

strcpy (S.name, "C


printf("name = programming);
%s\n", s.name);
printf("Union Data\t: ");
u.integer = 240;
printf("integer = %d \t ",
u.integer);
u.decimal = 120;
printf("decimal = %. 2f \t
u.decimal);
strcpy(u.name, "C programming");
printf("name = %s", u.name);
}

Output:
-Demonstration of difference between STRUCTURE & UNION---
kok ** ****
Structure Data : integer = 18
Union Data decimal = 38.00 name = structure
integer = 18 decimal = 0. 00 name = t

sizeof structure 28
sizeof union = 20

Accessing all structure and union members at a time:


Structure Data : integer = 183
Union Data :
decimal = 90.00 name = new Structure
integer = 544695662
decimal = 0.00 name = new Union
Accessing each member of a
structure and union at a time :

Structure Data : integer = 240 decimal = 120,00


Union Data : integer = 240 name = C prOgramming
decimal = 120.00 name = Cprogramming

You might also like