Pps Practical File
Pps Practical File
Practical File
On
Programming in C Lab
(ESC-CSE103G)
Submitted
For
Bachelor of Technology
In
Computer Science & Engineering
At
10
Program-1
Write a Program to calculate and display the volume of a Cuboid
having its height(h=10cm),width (w=12cm) and depth (8cm).
Solution:
#include<stdio.h>
int main(){
int height=10,width=12,depth=8;
int volume;
volume=height*width*depth;
printf("The volume of cuboid is %d\n", volume);
return 0;
}
Output:
The volume of Cuboid is 960 cmᶟ
Program-2
Write a program to calculate
(a)Simple interest
(b)Compound interest.
Solution:
(a)
#include<stdio.h>
int main(){
float principle,rate,time,SI;
printf("Enter principle:\n");
scanf("%f",&principle);
printf("Enter rate:\n");
scanf("%f",&rate);
printf("Enter time:\n");
scanf("%f",&time);
SI=(principle*rate*time)/100;
printf("Simple interest = %f", SI);
return 0;
}
Output:
Enter principle:
100000
Enter rate:
4
Enter time:
5
Simple interest = 20000.000000
(b)
#include<stdio.h>
#include<math.h>
int main(){
float principle,rate,time,compound_interest;
printf("Enter the principle:");
scanf("%f", &principle);
printf("Enter the rate:");
scanf("%f", &rate);
printf("Enter the time:");
scanf("%f", &time);
compound_interest = principle * pow((1 + rate/100), time);
printf("The compound interest is %f", compound_interest);
return 0;
}
Output:
Enter the principle:5000
int a;
printf("Enter a number:");
scanf("%d", &a);
if(a%2==0){
printf("%d is even\n", a);
}
else{
printf("%d is odd\n", a);
}
return 0;
}
Output:
(a)
Enter a number:52
52 is even
(b)
Enter a number:17
17 is odd
Program-4
Write a program to find whether a character is consonant or vowel
using switch statement.
Solution:
#include<stdio.h>
int main(){
char alphabet;
printf("Enter an alphabet:");
scanf("%c",&alphabet);
switch(alphabet)
{
case 'a':
printf("This is a vowel");
break;
case 'e':
printf("This is a vowel");
break;
case 'i':
printf("This is a vowel");
break;
case 'o':
printf("This is a vowel");
break;
case 'u':
printf("This is a vowel");
break;
default:
printf("This is a consonant");
}
return 0;
}
Output:
(a) Enter an
alphabet:y This is a
consonant
(b) Enter an alphabet:a
This is a vowel
Program-5
Write a program to compute grade of students using if else adder.
Solution:
#include<stdio.h>
int main(){
int marks;
printf("enter your marks:");
scanf("%d", &marks);
your grade is A+
your grade is A
(c) enter your marks:74
your grade is B+
your grade is B
your grade is C
your grade is F
Program-6
Write a program to generate Fibonacci series.
Solution:
#include<stdio.h>
int main(){
int ele1 = 0, ele2 = 1, nextTerm, no_of_terms;
scanf("%d", &no_of_terms);
for (int i=0;i<no_of_terms;i++)
{
printf("%d", ele1);
nextTerm=ele1+ele2;
ele2=ele1;
ele1=nextTerm;
}
return 0;
}
Output:
(a)3
011
(b)5
01123
Program-7
Write a program to find the factorial of a number using recursion.
Solution:
#include <stdio.h>
int factorial(int x);
int main()
{
int a;
printf("Enter the value of a\n");
scanf("%d", &a);
printf("The value of factorial %d is %d", a, factorial(a));
return 0;
}
int factorial(int x){
int f;
if (x == 0 || x == 1)
return 1;
else
f = x* factorial(x-1);
return f;
}
Output:
Solution:
#include<stdio.h>
int main(){
int n, reversedN=0, remainder, originalN;
printf("Enter an integer:");
scanf("%d", &n);
originalN=n;
while(n!=0){
remainder = n % 10;
reversedN = reversedN*10+remainder;
n/=10;
}
if(originalN == reversedN)
printf("%d is palindrome.", originalN);
else
printf("%d is not a palindrome.", originalN);
return 0;
}
Output:
(a)Enter an integer:878
878 is palindrome.
569 is not a
palindrome.
Program-9
Write a program to swap value of two variables using pointer.
Solution:
#include<stdio.h>
void swap(int *a, int *b);
int main(){
int x = 8, y = 13;
printf("The value of x and y before swap is %d and %d\n", x , y);
swap(&x, &y);
printf("The value of x and y after swap is %d and %d\n", x , y);
return 0;
}
Enter marks: 96
Enter marks: 94
Enter marks: 90
Enter marks: 99
Enter marks: 98
Displaying Information:
Roll number: 1
Marks: 96
Roll number: 2
Marks: 94
Roll number: 3
Marks: 90.0
Roll number: 4
Marks: 99.0
Roll number: 5
Marks: 98.0