Professional Documents
Culture Documents
Algorithm:
Step 1: start the program
Step 3: if (sales>=50000)
discount=30
discount=25
discount=20
discount=10
discount=5;
Step 9: amount=sales-(sales*discount)/100
#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);
}
else if(p>=5000 && p<20000)
d=0.20*p;
net=(p-d);
d=0.25*p;
net=(p-d);
else if(p>=50000)
d=0.30*p;
net=(p-d);
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
Algorithm:
Step 1: start the program.
Step 5: case 1:
Program:
#include<stdio.h>
main()
int d,net,p;
char ch;
printf("\t\t\t\t\t\tDussera Offers\n\n\n");
scanf("\n%d",&ch);
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);
break;
case 4:
d=0.25*p;
net=(p-d);
break;
case 5:
if(p>=50000)
d=0.30*p;
net=(p-d);
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 4: while(a<=a)
f=f*i
i++
PROGRAM
#include<stdio.h>
main()
int a,i=1,f=1;
scanf("%d",&a);
while(i<=a)
{
f=f*i;
i++;
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)
Program:
#include <stdio.h>
int main()
{
int n, i=1,f=1;
scanf("%d",&n);
do
f=f*i;
i++;
while(i<=n);
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
AIM : Write a program to find whether the entered number Is Armstrong number or not. Use do-
while() loop for your program.
Algorithm:
Step 4: do {
c=a%10
sum+=c*c*c
a=a/10
while(a!=0)
Step 5: If (sum==n)
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
Algorithm:
Step 4: do {
sum*=10;
sum+=a%10;
a/=10;
}
while(a!=0)
Step 5: If (sum==n)
PROGRAM :
#include<stdio.h>
main()
int n,sum=0,a;
{
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:
b) Again inside i
i)for j=1,j<i,j++
c)print (space)
d) print("*");
e)print("\n");
#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 2: main()
Step 4: for(i=1;i<=5;i++)
Step 5: for(j=1;j<=5;j++)
Step 7:print("\n");
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
Algorithm:
Step 2: main()
Step 4: for(i=1;i<=5;i++)
Step 5: for(j=1;j<=5;j++)
Step 7: printf("C");
else
Step 9:printf("\n");
main()
int i,j;
for(i=1;i<=5;i++)
for(j=1;j<=5;j++)
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.