Anda di halaman 1dari 30

# EXP_NO.:4.

Date: 2017/10/03

## (a) Purchase above Rs.500 : Discount is 5%

(b) Purchase above Rs.1000 : Discount is 10%
(c) Purchase above rs.5000 : Discount is 20%
(d) Purchase above rs.20000 : Discount is 25%
(e) Purchase above rs.50000 : Discount is 30%

## Use if else if ladder for this program.

Algorithm:
Step 1: start the program

## Step 2: Read the sales

Step 3: if (sales>=50000)

discount=30

discount=25

discount=20

discount=10

discount=5;

## Step 8: printDISCOUNT given = discount

Step 9: amount=sales-(sales*discount)/100

## Step 11: Stop the program.

PROGRAM :

#include<stdio.h>

main()

int p,d,net;

scanf("%d",&p);

d=0.05*p;

net=(p-d);

d=0.10*p;

net=(p-d);

## printf("Net Amount is : %d\n",net);

}
else if(p>=5000 && p<20000)

d=0.20*p;

net=(p-d);

d=0.25*p;

net=(p-d);

## printf("Net Amount is : %d\n",net);

else if(p>=50000)

d=0.30*p;

net=(p-d);

## printf("Net Amount is : %d\n",net);

return 0;

}
OUTPUT:

Result: Hence money to be paid by the customer after the discount given has been calculated from
above program.
EXP_NO.:4.2

Date: 2017/10/03

## (f) Purchase above Rs.500 : Discount is 5%

(g) Purchase above Rs.1000 : Discount is 10%
(h) Purchase above rs.5000 : Discount is 20%
(i) Purchase above rs.20000 : Discount is 25%
(j) Purchase above rs.50000 : Discount is 30%

## Use switch for this program.

Algorithm:
Step 1: start the program.

Step 5: case 1:

## i. if(p>=500 && p<1000)

ii. d=0.05*p
iii. net=(p-d)
iv. print "The Discount is 5%"
v. print "Discount Amount is : d
vi. print "Net Amount is : net
vii. break.
Step 6: case 2:
i. if(p>=1000 && p<5000)
ii. d=0.10*p
iii. net=(p-d)
iv. print "The Discount is 10%"
v. print "Discount Amount is : d
vi. print "Net Amount is : net
vii. break.
Step 7: case 3:
i. if(p>=5000 && p<20000)
ii. d=0.20*p
iii. net=(p-d)
iv. print "The Discount is 20%"
v. print "Discount Amount is : d
vi. print "Net Amount is : net
vii. break.
Step 8: case 4:
i. if(p>=20000 && p<50000)
ii. d=0.25*p
iii. net=(p-d)
iv. print "The Discount is 25%"
v. print "Discount Amount is : d
vi. print "Net Amount is : net
vii. break.
Step 9: case 5:
i. if(p>=50000)
ii. d=0.30*p
iii. net=(p-d)
iv. print "The Discount is 30%"
v. print "Discount Amount is : d
vi. print "Net Amount is : net
vii. break.
Step 10: Stop the program.

Program:

#include<stdio.h>

main()

int d,net,p;

char ch;

printf("\t\t\t\t\t\tDussera Offers\n\n\n");

## printf("5-Purchase above Rs. 50000 : Discount is 30 %%\n");

scanf("\n%d",&ch);

## printf("\nEnter the amount of purchase:\n");

scanf("\n%d",&p);

switch(ch)

case 1:

d=0.05*p;

net=(p-d);

break;

case 2:

d=0.10*p;

net=(p-d);

break;

case 3:

d=0.20*p;

net=(p-d);

## printf("Discount Amount is :%d\n",d);

printf("Net Amount is : %d\n",net);

break;

case 4:

d=0.25*p;

net=(p-d);

break;

case 5:

if(p>=50000)

d=0.30*p;

net=(p-d);

## printf("Net Amount is : %d\n",net);

break;

default:

printf("Invalid");

break;

return 0;

}
Output:

Result: Hence money to be paid by the customer after the discount given has been calculated from
above program.
EXP_NO.:5.1a

FACTORIAL
Date: 2017/10/03

AIM: Write a program to find the factorial of any integer using for loop.

Algorithm:

Step 1. Start
Step 2. Read the number n
Step 3. [Initialize] i=1, fact=1
Step 4. Repeat step 4 through 6 until i=n
Step 5. fact=fact*i
Step 6. i=i+1
Step 7. Print fact
Step 8. Stop

Program:

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

Result: Hence factorial of a number has been calculated from above program using for loop.
EXP_NO.:5.1b

FACTORIAL
Date: 2017/10/03

AIM: Write a program to find the factorial of any integer using while loop.

Algorithm:

## Step 3: read the value of a

Step 4: while(a<=a)

f=f*i

i++

## Step 6: Stop the program

PROGRAM
#include<stdio.h>

main()

int a,i=1,f=1;

scanf("%d",&a);

while(i<=a)

{
f=f*i;

i++;

## printf("\n the factorial is =%d",f);

OUTPUT:

RESULT: Hence the program to find factorial of integer was executed successfully and output was
verified.
EXP_NO.:5.1c

FACTORIAL
Date: 2017/10/03

AIM: Write a program to find the factorial of any integer using while loop.

Algorithm:

Step 4: Do

f=f*i

i++

while(a<=a)

## Step 6: Stop the program .

Program:

#include <stdio.h>

int main()
{

int n, i=1,f=1;

scanf("%d",&n);

do

f=f*i;

i++;

while(i<=n);

## printf("Factorial of %d is : %d " ,n,f);

return 0;

}
Output:

RESULT: Hence the program to find factorial of integer was executed successfully and output was
verified.
EXP_NO.:5.2

Prime Number
Date: 2017/10/03

Aim: Take 20 numbers as input from user. Check whether it is prime or not. Count how many nos are
prime numbers from given inputs.

Algorithm:

Step 1: Start
Step 2: Declare variables n,i,flag.
Step 3: Initialize variables
flag1
i2
Step 4: Read n from user.
Step 5: Repeat the steps until i<(n/2)
5.1 If remainder of ni equals 0
flag0
Go to step 6
5.2 ii+1
Step 6: If flag=0
Display n is not prime
else
Display n is prime
Step 7: Stop

Program:

#include<stdio.h>

int main()

int numbr,k,remark,n[20],i;
printf("Enter 20 Numbers: \n");

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

scanf("%d",&n[i]);

scanf("%d",&n);

for(numbr=2;numbr<=n[i];numbr++)

remark=0;

for(k=2;k<=numbr/2;k++)

if((numbr % k) == 0)

remark++;

break;

if(remark==0)

printf("\n %d ",numbr);

return 0;

}
Output:

EXP_NO.:6.1
Date: 2017/10/03

## ARMSTRONG NUMBER USING DO WHILE LOOP

AIM : Write a program to find whether the entered number Is Armstrong number or not. Use do-

Algorithm:

## Step 3: Initialize a=n

Step 4: do {

c=a%10

sum+=c*c*c

a=a/10

while(a!=0)

Step 5: If (sum==n)

## Step 7: Stop the program.

PROGRAM:

#include<stdio.h>
main()
{

int n,a,i,sum=0;
printf("Enter the number to check:");
scanf("%d",&n);
a=n;
do

c=a%10;
sum+=c*c*c;
a/=10;
}
while(a!=0);

if(sum==n)
printf("The number is an armstrong");
else
printf("The number is not an armstrong");
}

OUTPUT:

Result: thus the program to check whether a number is Armstrong or not was
executed successfully and was verified.

EXP_NO.:6.2

## PALINDROME NUMBER USING WHILE LOOP

Date: 2017/10/03
AIM : Write a program to check whether the entered integer Is Palindrome or not. Using while loop.

Algorithm:

## Step 3: Initialize a=n

Step 4: do {

sum*=10;
sum+=a%10;
a/=10;
}

while(a!=0)

Step 5: If (sum==n)

## Step 7: Stop the program.

PROGRAM :

#include<stdio.h>

main()

int n,sum=0,a;

## printf("Enter the number to check:");

scanf("%d",&n);
a=n;
while(a!=0)

{
sum*=10;
sum+=a%10;
a/=10;
}
if(sum==n)
printf("The number is palindrome");
else
printf("The number is not palindrome");
}

OUTPUT:

Result: Thus the program to check whether the input number is palindrome or
not was executed successfully and output was verified.
EXP_NO.:7.1 PASCAL TRIANGLE

Date: 2017/10/03

*****

****

***

**

Algorithm:

## Step 3: a) for i=0,i<5,i++

b) Again inside i

i)for j=1,j<i,j++

c)print (space)

d) print("*");

e)print("\n");

## Step 4:Stop the program.

Program:

#include<stdio.h>

int main()

int i,j,k;

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

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

printf(" ");

for(k=6-i; k>=1;k--)

printf("*");

printf("\n");

return 0;

}
Output:

Result: Thus the program to print PASCAL TRIANGLE was executed successfully and output was
obtained.
EXP_NO.:7.2.

Date: 2017/10/03

Algorithm:

## Step 1: Step the program.

Step 2: main()

Step 4: for(i=1;i<=5;i++)

Step 5: for(j=1;j<=5;j++)

## Step 6: print("C ");

Step 7:print("\n");

## Step 8: End the program.

PROGRAM:

#include<stdio.h>

main()
{

int i,j;

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

for(j=1;j<=5;j++)

printf("C ");

printf("\n");

OUTPUT:

Result: Thus the program to print full square (5X5) filled with character C was executed successfully
and output was obtained.
EXP_NO.:7.2.b

Date: 2017/10/03

Algorithm:

## Step 1: Start the program.

Step 2: main()

Step 4: for(i=1;i<=5;i++)

Step 5: for(j=1;j<=5;j++)

## Step 6: if (j==1 ||j==5 ||i==1 || i==5)

Step 7: printf("C");

else

## Step 8:printf(" ");

Step 9:printf("\n");

## Step 10:End the program.

PROGRAM:
#include<stdio.h>

main()

int i,j;

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

for(j=1;j<=5;j++)

## if (j==1 ||j==5 ||i==1 || i==5)

printf("C");

else

printf(" ");

printf("\n");

OUTPUT:

Result: thus the program to print border of (5*5) square filled with character C was executed
successfully and output was verified.