Maharaja Surajmal Institute
Department of Computer Applications
BCA-171
Practical I - C Programming Lab
Submitted by:
Name of Student: _Ishant Kochar__
Enrolment Number:_________
Course: BCA I Semester Section A (I Shift)
Submitted to:
Name of Faculty: Dr. Neetu Narwal
Associate Professor, BCA
Index
Program Program Date of
No execution
Topic Covered: Variable declaration, expression evaluation, operators
1 WAP to calculate the real root of the equation ax2+bx+c=0
using the quadratic formula
2 WAP to calculate Compound interest
3 WAP to calculate degrees Celsius given temperature in degrees
Fahrenheit using the formula
4 WAP to Calculate the volume and area of a sphere using the
formulas accept radius from user.
5 WAP to accept a character from user and check whether an
alphabet is vowel or consonant using conditional operator.
6 Write a Program to calculate diameter, circumference and area
of circle accept radius from user.
7 WAP to accept number from user and display whether it is even
or odd.
Topic Covered: If–else control statement and loop
8 WAP to accept a character and display whether it is Capital
Letter, Small Letter or Integer value.
9 Write a Program to count number of digits in any number.
10 Write a Program to find first and last digit of any number
display them. Then swap the digits and create a new number
and display it.
11 Write a Program to enter any number and print all factors of the
number.
12 Write a Program to enter any number and calculate its factorial.
13 Write a Program to find HCF (GCD) of two numbers.
14 Write a Program to find LCM of two numbers.
15 Write a Program to check whether a number is Prime number
or not.
16 Write a Program to find sum of all prime numbers between 1 to
n.
Topic covered: Functions
17 Write a function Power (a,b), to calculate the value of a raised
to the power of b.
18 Write a function Primefactor(a) , to calculate the prime factors
of a number and display the result in the function.
19 Write a function CompoundInterest(P,r,t) it receives 3
arguments principal, rate, time and displays the sum, average
and the standard deviation of these numbers.
20 Write a function Palindrome(a), that accepts an integer and
return 1 if the number is a palindrome number and return 0 if it
is not.
Topic covered: Recursive Functions
21 Write a recursive function GCDRec(a,b), that accepts two
integer values and returns the GCD of two numbers.
Program Program Date of
No execution
22 Write a recursive function FiboRec(a), that accepts number of
terms to be displayed in fibonacci series starting with 1 ,1 .
23 Write a recursive fuction SumTermRec(a), that accepts an
integer value and return the sum of all the digits.
24 Write a recursive function DectoBinaryRec(a), that accepts an
integer and return Binary equivalent of the decimal number.
Topic covered: Array
25 Write a Program to count frequency of each element in an
array.
26 Write a Program to print all unique elements in the array.
27 Write a Program to find reverse of an array.
28 Write a Program to merge two arrays to third array.
29 Write a function to accept 5 elements, performs sorting
operation: SelectionSortAsc(), SelectionSortDesc()
30 Write a function to delete a specific element specified by the
user and then shift all the elements towards left and last element
will become zero.
31 Create a header file xstring.h and include string
manipulation/handling functions, show its use
1) xstrlen(s1)
2) xstrcpy(s1,s2),
3) xstrcmp(s1,s2)
4) xtoupper(s1),
5) xtolower(s1),
6) xstrcat(s1, s2)
7) xstrncat(s1, s2, n)
8) xstrrev(s1),
9) xstrchr(s1,c1),
10) xstrstr(s1,s2),
Topic covered: Structure and Union
32 Write program to create a structure Accounts with members
char accname[20], int acctno,char acctype[10], float balance,
struct date openingbalance.
Structure date with members int day,month, year.
Create Structure Array of 10 elements. Write function to display
details of all the data, display details of specific account holder.
33 Write a program to create a union Color with members int
colorcode, char hexa[10]. Create structure Garments with
members int garmentid, char garmentname[20], float cost, union
color Clothcolor.
Create structure member and display the details.
Topic covered: File Handling
34 Write a program to copy a content of one file into another using
stream oriented file function.
Program 1: Write a program to calculate the real root of the equation ax2+bx+c=0
using the quadratic formula.
Source code:
#include <stdio.h>
#include <math.h>
Int main(){
Double a , b , c , realPart, imaginaryPart, discriminant , root1 , root2;
Printf(“Enter coefficients a,b,c of the quadratic equation respecitively:\n”);
Scanf(“%lf %lf %lf” , &a, &b, &c);
Discriminant = (b*b) – 4*a*c;
Printf(“discriminant is: %2lf\n”,discriminant);
If ( discriminant > 0 ) {
Printf(“the roots are real and distinct\n”);
root1 = (-b + sqrt(discriminant)) / ( 2 * a);
root2 = (-b – sqrt(discriminant)) / ( 2 * a);
printf(“Roots are: %.2lf and %.2lf\n”,root1,root2);
}
Else if ( discriminant == 0 ){
Printf(“the equation has two equal real roots.\n”);
root1 = -b / ( 2 * a );
printf(“Root is: %.2lf\n”, root1);
}
Else{
Printf(“The equation has complex roots.\n”);
realPart = -b / (2*a);
imaginaryPart = sqrt(-discriminant) / (2*a);
printf(“roots are: %.2lf + %.2lfi and %.2lf - %2lfi\n”,
realPart, imaginaryPart, realPart, imaginaryPart);
}
Return 0;
}
Output:
Program 2: Write a Program to calculate Compound Interest using formula
Source Code:
#include <stdio.h>
#include <math.h>
int main() {
double Amt, Principal, Rate, Time, CI;
int n;
printf (“Enter principal , \nInterest rate, \nNumber of time interest is applied
per year, \nTime in years\n”);
scanf(“%lf %lf %d %lf”, &Principal, &Rate,&n,&Time);
Rate=Rate/100;
Amt=Principal*(pow(1+Rate/n),n*Time);
Printf(“Amount is: %.2lf\n”,Amt);
CI= Amt – Principal;
Printf(“Compound Interest is: @.2lf,CI);
Return 0;
}
Output:
Program 3: Write a program to calculate degrees Celsius given temperature in
degrees Fahrenheit using the formula:-
C = (5/9) * (F-32)
Source Code:-
#include <stdio.h>
int main() {
float Cel, Fahr;
printf(“Enter temperature in Celsius: “);
scanf(“%f”, &Cel);
Fahr = (Cel * 9) / 5 + 32;
Printf(“Temperature in Fahrenheit is: %.2f\n”, Fahr);
Return 0;
}
Output:
Program 4: Write a Program to calculate the volume and area of a sphere using the
formulas accept radius from user.
Source Code:-
#include <stdio.h>
int main() {
double pi = 3.14;
double radius, volume, area;
printf(“Enter Radius: “);
Scanf(“%lf”, &Radius);
volume = (4.0 / 3) * pi * (radius * radius * radius );
area = 4 * pi * radius *radius;
printf(“\nVolume: %.2lf cm^3”, volume);
printf(“\nArea: %.2lf cm^3”, area);
return 0;
}
Output:-
Program 5: Write a program to accept a character from user and check whether an
alphabet is vowel or consonant using conditional operator.
Source Code:-
#include <stdio.h>
int main() {
char c;
printf(“Enter an alphabetical character: “);
scanf(‘%c”,&c);
if(c==’a’||c==’e’||c==’i’||c==’o’||c==’u’||
c==’A’||c==’E’||c==’I’||c==’O”||c==’U’){
printf(“%c is a vowel”, c);
Else{
Printf(“%c is a consonant”, c);
}
return 0;
Output:-
Program 6: Write a program to calculate diameter, circumference and area of circle
accept radius from user.
Source Code:
#include <stdio.h>
#define PI 3.14
int main() {
float r, dia, circ, area;
printf(“Please input the circle’s radius: “);
scanf(“%f”, &r);
dia = r * 2;
circ = PI * 2 * r;
area = PI * r * r;
printf(“circle’s diameter: %.2f units\n”, dia);
printf(“circle’s circumference: %.2f units\n”, circ);
printf(“circle’s area; %.2f square units\n”, area);
return 0;
}
Output:
Program 7: Write a program to accept number from user and display whether it is
even or odd.
Source Code:-
#include <stdio.h>
int main(){
int num;
printf(“enter a number: “);
scanf(“%d”, &num);
if ( num%2 == 0) {
printf(“%d is Even\n”, num);
}
else{
printf(“%d is Odd\n”, num);
return 0;
}
Output:
Program 8: Write a program to accept a character and display whether it is Capital
letter, Small Lettter or Integer Value.
Source Code:-
#include <stdio.h>
int main(){
char ch;
printf(“Enter a character: “);
scanf(“%c”, &ch);
if ( ch >= ‘A’ && ch<= ‘Z’){
printf(“%c is a Capital letter\n”, ch);
}
else if ( ch >= ‘a’ && ch <= ‘z’){
printf(“%c is a Small Letter\n”, ch);
}
else if ( ch>= ‘0’ && ch <= ‘9’) {
printf(“%c is an Integer value\n”, ch);
}
else {
printf(“%c is a Special Character\n”, ch);
}
return 0;
}
Output:-
Program 9: Write a program to count number of digits in any number.
Source Code:-
#include <stdio.h>
int main() {
int num, count=0;
printf(“Enter a number: “);
scanf(“%d”, &num);
if ( num == 0){
count = 1;;
}
else {
if (num < 0) {
num = -num;
}
while (num > 0) {
num = num / 10;
count++;
}
}
printf(“Number of digits = %d\n”, count);
return 0;
}
Output: