You are on page 1of 33

PARMINDER K, 813/22, BTPS102-18

PROGRAM: 1
AIM: - Write a C Program to Print a String.

SOFTWARE USED: - Turbo C (Version 3.0)

FLOWCHART: -

STAR
T

Print=”HELL
O WORLD”

STOP

PROGRAM: -
#include<stdio.h>
#include<conio.h>
void main()
{
printf("Hello world");
getch();
}

OUTPUT: -

stop
PARMINDER K, 813/22, BTPS102-18

PROGRAM: 2
AIM: - To Observe Difference Between /n and \n.

SOFTWARE USED: - Turbo C (Version 3.0)

FLOWCHART: -
STAR
T

Print=”nn\n\
nn”
Print=”nn/
n/nn”

PROGRAM: - STOP
#include<stdio.h>
#include<conio.h>
void main()
{
printf("nn\n\nn\n");
printf("nn/n/nnn/n");
getch();
}

OUTPUT: -

stop
PARMINDER K, 813/22, BTPS102-18

PROGRAM: 3
AIM: - To Print Sum of Two Numbers.

SOFTWARE USED: - Turbo C (Version 3.0)

FLOWCHART: -

START

Declare a, b,
sum

Read
numbers

Sum=a + b

Print
sum

END
PROGRAM: -
#include<stdio.h>
#include<conio.h>
void main(){
int a, b,sum;
clrscr();
a=5, b=8
sum=a+b;
printf("%d",sum);
getch();

OUTPUT: -

stop
PARMINDER K, 813/22, BTPS102-18

PROGRAM: 4

AIM: - To get two values from user and add the numbers.

SOFTWARE USED: - Turbo C (Version 3.0)

FLOWCHART: -

STAR
T

Input
a,b

sum=a+b

Print sum

End

PROGRAM:-

#include<stdio.h>

#include<conio.h>

void main()

int a,b,sum;

clrscr();

printf("enter a number, a=");

scanf("%d", &a);

printf("enter a number, b=");

stop
PARMINDER K, 813/22, BTPS102-18

scanf("%d", &b);

sum=a+b;

printf("sum of two numbers is = %d",sum);

getch();

OUTPUT: -

PROGRAM: 5
AIM: - To Calculate Simple Interest.

stop
PARMINDER K, 813/22, BTPS102-18

SOFTWARE USED: - Turbo C (Version 3.0)

FLOWCHART: -

START

Input: P,
R. T

Calculate:-
SI=(P*R*T)/
100

Print=Si
PROGRAM: - mple
Interest
#include<stdio.h>

#include<conio.h>

void main() END

float p,r,t,interest;

clrscr();

printf("enter principal amount, p=");

scanf("%f", &p);

printf("enter rate of interest, r=");

scanf("%f", &r);

printf("enter time period, t=");

scanf("%f", &t);

stop
PARMINDER K, 813/22, BTPS102-18

interest=(p*r*t)/100;

printf("%f is the simple interest",interest);

getch();

OUTPUT: -

PROGRAM: 6
AIM: - To Implement Math Functions.

SOFTWARE USED: - Turbo C (Version 3.0)

FLOWCHART: - START

stop
Input a
PARMINDER K, 813/22, BTPS102-18

PROGRAM: -

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

float a,b,c;

clrscr();

printf("enter a number, a=");

scanf("%f",&a);

b=sqrt(a);

c=pow(a,3);

printf("%f is the square root \n",b);

printf("%f is the power",c);

getch();

stop
PARMINDER K, 813/22, BTPS102-18

OUTPUT: -

PROGRAM: 7
AIM: - To find largest of two no. using IF-ELSE condition.

SOFTWARE USED: - Turbo C (Version 3.0)

FLOWCHART: -

start

stop
PARMINDER K, 813/22, BTPS102-18

input a,b

is

No a>b Yes

print “b” is greater print “a” is greater

stop

PROGRAM: -

#include<stdio.h>

#include<conio.h>

void main()

float a,b;

clrscr();

printf("enter a number, a=");

scanf("%f",&a);

printf("enter a number, b=");

scanf("%f",&b);

if (a>b)

printf("%f is greater",a);

else

10

stop
PARMINDER K, 813/22, BTPS102-18

printf("%f is greater",b);

getch();

OUTPUT: -

PROGRAM: 8
AIM: - To find largest of three no. using IF-ELSE condition.

SOFTWARE USED: - Turbo C (Version 3.0)

FLOWCHART: -

Start

11

stop
PARMINDER K, 813/22, BTPS102-18

PROGRAM: -

#include<stdio.h> Input nos.


a, b, c
#include<conio.h>

void main(){
If a>b
float a,b,c;

printf("enter a number, a=");


If If a>c
b>c
scanf("%f",&a);

printf("enter a number, b=");


Print=B Print=C Print=A is
scanf("%f",&b);
is is largest largest
largest
printf("enter a number, c=");

scanf("%f", &c);

if(a>b && a>c)

printf("%f is the greatest", a);

else if (b>c)
End
printf("%f is the greatest", b);

else

printf("%f is the greatest", c);

getch();

OUTPUT: -

12

stop
PARMINDER K, 813/22, BTPS102-18

PROGRAM: 9
AIM: - To Print First 10 Natural Numbers using a loop.

SOFTWARE USED: - Turbo C (Version 3.0)

FLOWCHART: -

Star
t

Input n

I=1

i>
n

Print i

i=i+1

End

13

stop
PARMINDER K, 813/22, BTPS102-18

PROGRAM: -

#include<stdio.h>

#include<conio.h>

void main()

int i;

clrscr();

for(i=1; i<=10; i=i+1)

printf("%d",i);

getch();

OUTPUT: -

14

stop
PARMINDER K, 813/22, BTPS102-18

PROGRAM: 10
AIM: - To Print Even Numbers Till 10 using a loop.

SOFTWARE USED: - Turbo C (Version 3.0)

FLOWCHART: -

Start

Count=2

Count=co
unt+2

Is
count<=
10

END

PROGRAM: -

15

stop
PARMINDER K, 813/22, BTPS102-18

#include<stdio.h>

#include<conio.h>

void main()

int i;

clrscr();

for(i=0; i<=10; i=i+2)

printf("%d",i);

getch();

OUTPUT:-

PROGRAM: 11

AIM: - Multiplication table of the number to print entered.

16

stop
PARMINDER K, 813/22, BTPS102-18

SOFTWARE USED: - Turbo C (Version 3.0)

FLOWCHART: -

Start

Input i

J=1

Is Outp J=j+1
j<=10 ut=i*j

End

PROGRAM:-

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
clrscr();
printf("table of n=");
scanf("%d",&n);
for(i=0 ; i<=10 ; i++)
printf("%d * %d - %d\n",n,i,n*i);
getch();
}

17

stop
PARMINDER K, 813/22, BTPS102-18

OUTPUT:-

PROGRAM: 12
AIM: - To Check Whether A Number Is Prime or Not.

SOFTWARE USED: - Turbo C (Version 3.0)

FLOWCHART: -
18

stop
PARMINDER K, 813/22, BTPS102-18

Start

Read
n

I=2

I<n

N
%i==

I=i+1
I==
n

Print Print=
=no.is no. is
prime not
prime

End

PROGRAM:-

#include<stdio.h>
#include<conio.h>
void main(){
clrscr();
int a,b=0,c,d;
printf("enter any number=");
scanf("%d",&a);

19

stop
PARMINDER K, 813/22, BTPS102-18

for(c=2;c<a;c++)
{
d=a%c;
if(d==0)
{
b=1;
}
}
if(b==0)
{
printf("the number entered is prime number");
}
else
{
printf("the number entered is not prime number");
}

getch();
}

OUTPUT:-

PROGRAM: 13
AIM: - To Print Fibonacci Series.

SOFTWARE USED: - Turbo C (Version 3.0)

FLOWCHART:-

20

stop
PARMINDER K, 813/22, BTPS102-18

start

declare variable I,n,a,b,show

initialize ,a=0 ,b=1 and show =0

input the number of term to be printed.

The fabonacci series is a b ; \n\n\n

i=2

NO i<= n YES

Show =a + b

a=b

b =show , ++ i

pri
PROGRAM:-

#include<stdio.h>

#include<conio.h>

void main()

int i,n;

21

stop
PARMINDER K, 813/22, BTPS102-18

int t1=0, t2=1, next_t;

clrscr();

printf("enter no. of terms:");

scanf("%d",&n);

for(i=1; i<=n; i++)

printf("%d ",t1);

next_t=t1+t2;

t1=t2;

t2=next_t;

getch();

OUTPUT:-

PROGRAM: 14
AIM: - To Check Whether A Number Is Palindrome or Not.

SOFTWARE USED: - Turbo C (Version 3.0)

FLOWCHART:-
start

22

stop
PARMINDER K, 813/22, BTPS102-18

Read num

Reverse =0

Tempnum = num

Num i =0 No

Yes

Rem = num %10

Reverse* = 10 + rem

Num = num /10

Reverse = Tempnum

Yes No

Palindrome Not palindrome

Stop

PROGRAM:-
#include<stdio.h>

#include<conio.h>

void main(){

int n, rev=0, rem, orig;

printf("enter an integer, n=");

scanf("%d",&n);

23

stop
PARMINDER K, 813/22, BTPS102-18

orig=n;

while(n!=0)

rem=n%10;

rev=rev*10 + rem;

n=n/10;

if(orig == rev)

printf("%d is a palindrome no",orig);

else

printf("%d is not a palindrome no.",orig);

getch();

OUTPUT:-

PROGRAM: 15
AIM: - Calculate Operation using switch statement

SOFTWARE USED: - Turbo C (VERSION3.0)

FLOWCHART:-

24

stop
PARMINDER K, 813/22, BTPS102-18

PROGRAM:
#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

float s,a,b,sub,m,d,sq;

int ch,v=1;

clrscr();

while(v==1)

printf(" enter two integers ");

scanf("%f%f",&a,&b);

printf("enter \n 1 for addition \n 2 for substraction \n 3 for multiplication \n 4 for division \n 5 for
square root value \n 6 for exit \n ");

scanf("%d",& ch);

switch(ch)

case 1:

s=a+b;

25

stop
PARMINDER K, 813/22, BTPS102-18

printf(" %f",s);

break;

case 2:

sub=a-b;

printf("%f",sub);

break;

case 3:

m= a*b;

printf("%f",m);

break;

case 4:

d=a/b;

printf("%f",d);

break;

case 5:

sq=sqrt(a);

printf("%f",sq);

break;

default:

printf("invalid choice");

break;

printf("do you want to continue? \n enter 1 for yes \n 0 for no");

scanf("%d",&v);

getch();

26

stop
PARMINDER K, 813/22, BTPS102-18

OUTPUT: -

27

stop
PARMINDER K, 813/22, BTPS102-18

PROGRAM: 16
AIM: - Right triangle star pattern in C
SOFTWARE USED: - Turbo C (Version 3.0)
FLOWCHART:-

PROGRAM: -
#include <stdio.h>
int main()
{
int n;
printf("Enter the number of rows");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
printf("* ");
}
printf("\n");
}
return 0;

28

stop
PARMINDER K, 813/22, BTPS102-18

OUTPUT:-

PROGRAM: 17
AIM: -To print a given number pattern.
SOFTWARE USED:-Turbo C (Version 3.0)
FLOWCHART:-

PROGRAM:-
#include <stdio.h>

int main()
{
int i, j,,N;
printf(“enter N :”);

29

stop
PARMINDER K, 813/22, BTPS102-18

scanf(“%d”,&N);

for(i=1;i<=N;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}

Output :-

PROGRAM: 18
AIM: - Program to print pyramid.

SOFTWARE USED: - Turbo c (Version 3.0).


FLOWCHART:-

30

stop
PARMINDER K, 813/22, BTPS102-18

31

stop
PARMINDER K, 813/22, BTPS102-18

PROGRAM:-
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, rows, k = 0;
printf (" Enter a number to define the rows: \n");
scanf ("%d", &rows);
for ( i =1; i <= rows; i++)
{
for ( j = 1; j <= rows - i; j++)
{
printf (" ");
}
// use for loop where k is less than equal to (2 * i -1)
for ( k = 1; k <= ( 2 * i - 1); k++)
{
printf ("* "); // print the Star
}
printf ("\n");
}
getch();
}

OUTPUT:-

PROGRAM: 19
AIM:-Factorial program using a loop.

SOFTWARE USED:- Turbo C (Version 3.0).

FLOWCHART:-

32

stop
PARMINDER K, 813/22, BTPS102-18

PROGRAM:-

#include<stdio.h>
int main()
{
int i,fact=1,number;
printf("Enter a number: ");
scanf("%d",&number);
for(i=1;i<=number;i++){
fact=fact*i;
}
printf("Factorial of %d is: %d",number,fact);
return 0;
}

OUTPUT :-

33

stop

You might also like