Bharati Vidyapeeth Deemed University
Institute of Management,
Kolhapur
JOURNAL
IT Lab- I ( C, Word, Excel )
Submitted by: - Mr./MS._______________________
BCA-I (Semester I)
Bharati Vidyapeeth Deemed University
Institute of Management,
Kolhapur
Certificate
Exam Seat No ___________
This is to certify that Mr./Ms._________________________ of
BCA–I has satisfactorily completed the Practical Assignments
on “IT Lab- I ( C, Word, Excel)” for the academic year 2010-
2011.
Place: - Kolhapur.
Date:-
Prof. P. G. Tandale Prof. A. T. Gaikwad
H.O.D
CONTENT
Sr. Page
Program Title Sign
No No
1 First C Program- “Hello World”
2 Addition of Two Numbers
3 Simple Interest Calculation
4 Temperature Conversion
5 Printing the pattern of asterisks(*)
6 Finding reverse of a number
7 Finding sum of 3-digit number
8 Fibonacci Series
9 Roots of Quadratic Equation
10 Finding sum of first n terms of series
1+3+5+…………+n terms
11 Greatest among three numbers using if……else
12 Finding average of N numbers
(use #define & while loop)
13 Printing even numbers from 1 to 100
(use for loop)
14 Salesman’s salary (use symbolic constants)
15 Swapping of three numbers
16 Grading of a student using switch …. case
Sr. Page
Program Title Sign
No No
17 Number Triangle using for loop
18 Factorial of a number using recursive function
19 Swapping of two variable using call by
reference
20 Sum of squares of 1st 10 natural numbers
using array
21 Different operations of strings
22 Accessing a variable through its pointer
Program No. 1- Write a program to print “Hello world” on screen
#include <stdio.h>
#include<conio.h>
int main()
{
clrscr( );
printf("Hello, world\n");
getch( );
return 0;
}
Output-
Hello, world
Program No. 2- Write a program for addition of two numbers
#include <stdio.h>
#include <conio.h>
void main(void)
{
int number; //varible decleration
float amount;
clrscr();
number=100;
amount=30.75+75.35;
printf("%d\n",number); //output
printf("%5.2f",amount);
Output-
100
106.10
Program No. 3- Write a program for calculation of Simple Interest.
#include <stdio.h>
#include <conio.h>
void main(void)
{
int P,N; //varible decleration
float R,SI;
clrscr();
printf("\n Enter Principal Amount, Years & Rate of Interest\n");
scanf("%d%d%f",&P,&N,&R);
SI=(P*N*R)/100;
printf("\nSimple Interest= Rs. %.2f",SI); //output
getch();
}
Output-
Enter Principal Amount, Years & Rate of Interest
4000
5
5.5
Simple Interest= Rs. 1100.00
Program No. 4- Relation between Celsius and Fahrenheit is governed by the
formula
9C
F= + 32
5
Write a program to convert the temperature form Fahrenheit to Celsius.
#include<stdio.h>
#include<conio.h>
void main(void)
{
float cel,fah;
clrscr();
printf("\n Enter the Temperature in Fahrenheit");
scanf("%f", &fah);
cel=(fah-32)/1.8;
printf("\n\n%.2f Fahrenheit= %.2f Degree Celsius" ,fah, cel);
getch();
Output-
Enter the Temperature in Fahrenheit105
105.00 Fahrenheit= 40.56 Degree Celsius
Program No. 5- Write a program to print the pattern of asterisks ( * )
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a,b;
clrscr();
printf("\n\n");
for(a=1;a<=5;a++)
{
for(b=1;b<=a;b++)
{
printf("\t*");
}
printf("\n\n\n");
}
getch();
}
Output-
* *
* * *
* * * *
* * * * *
Program No. 6- Write a program for finding reverse of a number.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,rem,quo,sum;
rem=0;
sum=0;
clrscr();
printf("\n\n Enter a number: ");
scanf("%d",&n);
while(n>0)
{
rem=n%10;
quo=n/10;
sum=sum*10;
sum=sum+rem;
n=quo;
}
printf("\n\nReverse of no = %d",sum);
getch();
}
Output-
Enter a number: 2356
Reverse of no= 6532
Program No. 7- Write a program for finding sum of a 3-digit number.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,s,q,r;
s=0;
clrscr();
printf("\n\nEnter the number:");
scanf("%d",&n);
while(n>0)
{
r=n%10;
s=s+r;
q=n/10;
n=q;
}
printf("Sum of given number is:%d",s);
getch();
}
Output-
Enter the number:1478
Sum of given number is:20
Program No. 8- Write a program to generate Fibonacci series.
0, 1, 1, 2, 3, 5, 8, 13, 21 ………
#include<stdio.h>
#include<conio.h>
void main()
{
int n,a,b,i,c;
a=0;
b=1;
i=2;
clrscr();
printf("\n Enter Value of N ");
scanf("%d",&n);
printf("\n%d\t%d",a,b);
do
{
i=i+1;
c=a+b;
printf("\t%d",c);
a=b;
b=c;
}
while(i<n);
getch();
}
Output-
Enter Value of N 8
0 1 1 2 3 5 8 13
Program No. 9- Write a program to find roots of the Quadratic equation
ax + bx + c = 0
2
A quadratic equation has two roots which are given by the formula:
− b ± b 2 − 4ac
x=
2a
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,dis,root1,root2;
clrscr();
printf("\n\nInput value of a,b and c \n");
scanf("%f%f%f",&a,&b,&c);
dis=(b*b)-(4*a*c);
if (dis<0)
printf("\n\n root are imaginary \n");
else
{
root1=(-b + sqrt(dis)) / (2.0*a);
root2=(-b - sqrt(dis)) / (2.0*a) ;
printf("\n\n root1=%5.2f \n\n root2=%5.2f\n",root1,root2);
}
getch();
}
Output-
Input value of a,b and c
2
3
-14
root1= 2.00
root2=-3.50
Program No. 10- Write a program for finding sum of first n terns of series
1 + 3 + 5 + …….. + n terms
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,sum;
sum=0;
clrscr();
printf("\n\nEnter any numbers:\n");
scanf("%d",&b);
for(a=1; a<=b; a++)
{
if(a%2!=0)
{
printf("%d+",a);
sum=sum+a;
}
}
printf("=%d",sum);
getch();
}
Output-
Enter any numbers:
16
1+3+5+7+9+11+13+15=64
Program No. 11- Write a program to find greatest among three numbers using
if ….. else
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("\n\nEnter three numbers:\n");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
{
printf("A is maximum");
}
else
{
printf("C is maximum");
}
}
else
{
if(b>c)
{
printf("B is maximum");
}
else
{
printf("C is maximum");
}
getch();
}
Output-
Enter three numbers:
14
20
69
C is maximum
Program No. 12- Write a program for finding average of N numbers
(use #define & while loop)
#include<stdio.h>
#include<conio.h>
#define N 10
void main()
{
int count;
float sum, average, number;
sum=0;
count=0;
clrscr();
printf("\n\n\nEnter any 10 numbers\n\n");
while (count<N)
{
scanf ("%f",& number);
sum=sum+number;
count=count+1;
}
average=sum/N;
printf("N=%d,sum=%f",N,sum);
printf("Average=%f",average);
getch();
}
Output-
Enter any 10 numbers
5
10
15
20
25
30
35
40
45
50
N=10, sum=275.000000Average=27.500000
Program No. 13- Write a program to print all even numbers from 1 to 100.
(use for loop)
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
clrscr();
printf("\n Enter value of n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2==0)
{
printf("\t%d",i);
}
}
getch();
}
Output-
Enter value of n 100
2 4 6 8 10 12 14 16 18
20 22 24 26 28 30 32 34 36 38
40 42 44 46 48 50 52 54 56 58
60 62 64 66 68 70 72 74 76 78
80 82 84 86 88 90 92 94 96 98
100
Program No. 14
A computer manufacturing company has following monthly compensation policy to
their sales-persons:
Minimum basic salary : 1500.00
Bonus for every computer sold : 200.00
Commission on the total monthly sales :2%
Since the prices of computers are changing, the sales price of each computer is fixed
at the beginning of every month.
Write a program to computer sales-person’s gross salary.
#include<stdio.h>
#include<conio.h>
#define BASE_SALARY 1500.00
#define BONUS_RATE 200.00
#define COMMISSION 0.02
void main()
{
int quantity;
float gross_salary,price;
float commission,bonus;
clrscr();
printf("Input number sold and price\n");
scanf ("%d %f",&quantity,&price);
bonus=BONUS_RATE*quantity;
commission=COMMISSION*quantity*price;
gross_salary=BASE_SALARY+bonus+commission;
printf("\n Bonus= %6.2f",bonus);
printf("\n Commission= %6.2f",commission);
printf("\n Gross Salary= %6.2f",gross_salary);
getch();
}
Output-
Input number sold and price
6 14500.00
Bonus= 1200.00
Commission= 1740.00
Gross Salary= 4440.00
Program No. 15- Write a program for swapping of three numbers.
AB C
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,temp;
clrscr();
printf("\n Enter any two number:");
scanf("%d%d%d",&a,&b,&c);
temp=a;
a=b;
b=c;
c=temp;
printf("\nSwapped numbers are %d %d %d",a,b,c);
getch();
}
Output-
Enter any two number:25 36 42
Swapped numbers are 36 42 25
Program No. 16- Write a program to find grade obtained by the student in exam.
( use switch …. case)
#include<stdio.h>
#include<conio.h>
void main()
{
int marks,index;
char grade;
clrscr();
printf("\n\nEnter marks obtained: ");
scanf("%d",&marks);
index=marks/10;
switch(index)
{
case 10:
case 9:
case 8:
case 7:
grade='D';
break;
case 6:
grade='1';
break;
case 5:
grade='2';
break;
case 4:
grade='P';
break;
default:
grade='F';
break;
}
printf("\n Grade obtained is %c", grade);
getch();
}
Output-
Enter marks obtained: 67
Grade obtained is 1
Program No. 17- Write a program to generate number triangle using for loop
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a,b;
clrscr();
printf("\n\n");
for(a=1;a<=5;a++)
{
for(b=1;b<=a;b++)
{
printf("\t%d",b);
}
printf("\n\n\n");
}
getch();
}
Output-
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Program No. 18- Write a program to find factorial of a number using recursive
function.
N factorial = N! =1*2*3*4*…..*N
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int n,a,f;
clrscr();
printf("\n\nEnter the number:");
scanf("%d",&n);
a=fact(n);
printf("\n\nFactorial=%d",a);
getch();
}
int fact(int n)
{
int m;
if(n==1 || n==0)
return(1);
else
{
m=n*fact(n-1);
return(m);
}
}
Output-
Enter the number:6
Factorial=720
Program No. 19- Write a program for swapping of two variables using ‘call by
reference
#include<stdio.h>
#include<conio.h>
void exchange(int*p,int*q);
void main()
{
int x,y;
clrscr();
x=29;
y=7;
printf("\nValues before exchange x=%d,y=%d",x,y);
exchange(&x,&y);
printf("\nValues after exchange x=%d,y=%d",x,y);
getch();
}
void exchange(int*p,int*q)
{
int temp;
temp=*p;
*p=*q;
*q=temp;
Output-
Values before exchange x=29,y=7
Values after exchange x=7,y=29
Program No. 20- Write a program to find average of 10 numbers using array.
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
int x[10],value,total;
clrscr();
printf("\n\nEnter 10 numbers:\n");
for(i=0;i<10;i++)
{
scanf("%d",&value);
x[i]=value;
}
total=0;
for(i=0;i<10;i++)
{
total=total + x[i]*x[i];
}
printf("\n");
for(i=0;i<10;i++)
{
printf("x[%d]=%d\n",i+1,x[i]);
}
printf("\nTotal= %d", total);
getch();
}
Output-
Enter 10 numbers:
1 2 3 4 5 2 7 8 10 11
x[1]=1
x[2]=2
x[3]=3
x[4]=4
x[5]=5
x[6]=2
x[7]=7
x[8]=8
x[9]=10
x[10]=11
Total= 393
Program No. 21- Write a program to illustrate different operations on string.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[20],s2[20],s3[20];
int x,l1,l2,l3;
clrscr();
printf("\n\nEnter two string constants");
scanf("%s %s",s1,s2);
x=strcmp(s1,s2); //comparing
if(x!=0)
{
printf("\n Strings are not equal");
strcat(s1,s2); // joining s1 and s2
}
else
printf("\n Stings are equal");
strcpy(s3,s1); //copying s1 to s3
// finding length of string
l1=strlen(s1);
l2=strlen(s2);
l3=strlen(s3);
printf("\ns1=%s\t length = %d characters",s1,l1); //output
printf("\ns2=%s\t length = %d characters",s2,l2);
printf("\ns3=%s\t length = %d characters",s3,l3);
getch();
}
Output-
Enter two string constants
Kolhapur
Sangli
Strings are not equal
s1=KolhapurSangli length = 14 characters
s2=Sangli length = 6 characters
s3=KolhapurSangli length = 14 characters
Program No. 22- Write a program to access a variable though its pointer.
#include <stdio.h>
#include <conio.h>
void main(void)
{
int x,y;
int *ptr;
clrscr();
x=10;
ptr=&x;
y=*ptr;
printf("Value of x is %d\n\n",x);
printf("%d is stored at addr %u\n", x,&x);
printf("%d is stored at addr %u\n", *&x,&x);
printf("%d is stored at addr %u\n", *ptr,ptr);
printf("%d is stored at addr %u\n", ptr,&ptr);
printf("%d is stored at addr %u\n", y,&y);
*ptr=25;
printf("\n Now x= %d\n",x);
getch();
}
Output-
Value of x is 10
10 is stored at addr 65524
10 is stored at addr 65524
10 is stored at addr 65524
-12 is stored at addr 65520
10 is stored at addr 65522
Now x= 25