You are on page 1of 30

EXP_NO.:4.

CRITERIA FOR DISCOUNT(Using else-if Ladder)


Date: 2017/10/03

AIM: Write a program to define criteria for discount in a shop as follows:

(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

Step 4: else if(sales>=20000)

discount=25

Step 5: else if(sales>=5000)

discount=20

Step 6: else if(sales>=1000)

discount=10

Step 7: else if(sales>=500)

discount=5;

Step 8: printDISCOUNT given = discount

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

Step 10: printnow you had to pay = amount

Step 11: Stop the program.


PROGRAM :

#include<stdio.h>

main()

int p,d,net;

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

scanf("%d",&p);

if(p>=500 && p<1000)

d=0.05*p;

net=(p-d);

printf("The Discount is 5-Percent\n");

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

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

else if(p>=1000 && p<5000)

d=0.10*p;

net=(p-d);

printf("The Discount is 10-Percent\n");

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

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

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

d=0.20*p;

net=(p-d);

printf("The Discount is 20-Percent\n");

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

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

else if(p>=20000 && p<50000)

d=0.25*p;

net=(p-d);

printf("The Discount is 25-Percent\n");

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

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

else if(p>=50000)

d=0.30*p;

net=(p-d);

printf("The Discount is 30-Percent\n");

printf("Discount Amount is : %d\n",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

CRITERIA FOR DISCOUNT USING SWITCH CASE


Date: 2017/10/03

AIM: Write a program to define criteria for discount in a shop as follows:

(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 2: give the criteria for discount.

Step 3: Read the value of p and ch

Step 4: pass ch in switch

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("1-Purchase above Rs. 500 : Discount is 5 %%\n");

printf("2-Purchase above Rs. 1000 : Discount is 10 %%\n");

printf("3-Purchase above Rs. 5000 : Discount is 20 %%\n");

printf("4-Purchase above Rs. 20000 : Discount is 25 %%\n");

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


printf("\n\nChoose Your Offer\n");

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

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

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

switch(ch)

case 1:

if(p>=500 && p<1000)

d=0.05*p;

net=(p-d);

printf("The Discount is 5%%\n");

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

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

break;

case 2:

if(p>=1000 && p<5000)

d=0.10*p;

net=(p-d);

printf("The Discount is 10%%\n");

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

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

break;

case 3:

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

d=0.20*p;

net=(p-d);

printf("The Discount is 20%%\n");

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


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

break;

case 4:

if(p>=20000 && p<50000)

d=0.25*p;

net=(p-d);

printf("The Discount is 25%%\n");

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

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

break;

case 5:

if(p>=50000)

d=0.30*p;

net=(p-d);

printf("The Discount is 30%%\n");

printf("Discount Amount is :%d\n",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 1: Start the program

Step 2: initialize i=1 and f=1

Step 3: read the value of a

Step 4: while(a<=a)

f=f*i

i++

Step 5: printthe factorial is = f

Step 6: Stop the program

PROGRAM
#include<stdio.h>

main()

int a,i=1,f=1;

printf("\n enter value for which you want to find fectorial");

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 1: Start the program

Step 2: initialize i=1 and f=1

Step 3: read the value of a

Step 4: Do

f=f*i

i++

while(a<=a)

Step 5: printthe factorial is = f

Step 6: Stop the program .

Program:

#include <stdio.h>

int main()
{

int n, i=1,f=1;

printf("Enter an integer: ");

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:

Result: Hence the program is successfully executed and output is verified.

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-
while() loop for your program.

Algorithm:

Step 1: Start the program

Step 2: Read the number n to check

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)

Then print the number is an armstrong

Step 6: Else Print the number is not an armstrong

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 1: Start the program

Step 2: Read the number n to check

Step 3: Initialize a=n

Step 4: do {

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

while(a!=0)

Step 5: If (sum==n)

Then print the number is an Palindrome

Step 6: Else Print the number is not an Palindrome

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

AIM : Write a program to print the following triangle.

*****

****

***

**

Algorithm:

Step 1: Start the program

Step 2: Read the number i , j ,k

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

b) Again inside i

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

c)print (space)

i)for k=6-I, k>=1, k--

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.

TO PRINT FULL SQUARE (5x5) FILLED WITH A CHARACTER C

Date: 2017/10/03

AIM : FULL SQUARE (5x5) FILLED WITH CHARCTER C.

Algorithm:

Step 1: Step the program.

Step 2: main()

Step 3: Assign int i,j;

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

TO PRINT WITH ONLY BORDER OF QUESTION 7.2.A


Date: 2017/10/03

AIM : To print with only border of the same shape as of 7.2.a

Algorithm:

Step 1: Start the program.

Step 2: main()

Step 3: Assign int i,j;

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.

You might also like