0% found this document useful (0 votes)
68 views

C Language: Paras Goyal Bca Semester-1 (2-SHIFT) Enroll. No. (02624002016)

The document contains a C language program written by Paras Goyal for BCA Semester 1. It includes 13 programs covering basics of C like input/output, arithmetic operations, conditional statements, loops, functions, pointers and recursion. The programs calculate addition, interest, even/odd numbers, area and circumference, swapping values, digit sums, percentages, loops, simple interest using loops, call by value/reference, factorials and Fibonacci series using recursion. The document provides the full source code for each program and the expected output.

Uploaded by

Paras Goyal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

C Language: Paras Goyal Bca Semester-1 (2-SHIFT) Enroll. No. (02624002016)

The document contains a C language program written by Paras Goyal for BCA Semester 1. It includes 13 programs covering basics of C like input/output, arithmetic operations, conditional statements, loops, functions, pointers and recursion. The programs calculate addition, interest, even/odd numbers, area and circumference, swapping values, digit sums, percentages, loops, simple interest using loops, call by value/reference, factorials and Fibonacci series using recursion. The document provides the full source code for each program and the expected output.

Uploaded by

Paras Goyal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

C LANGUAGE

PARAS GOYAL
BCA SEMESTER-1
(2-SHIFT)
ENROLL. NO.
(02624002016)
1
1. Write a program to perform addition, subtraction,

multiplication and division.

#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,c,add,sub,mul,div;
clrscr();
printf("\n enter the value of a=");
scanf("%f",&a);
printf("\n enter the value of b=");
scanf("%f",&b);
printf("\n enter the value of c=");
scanf("%f",&c);
add=a+b+c;
printf("\n addition of a,b and c= %f",add);
sub=a-b-c;
printf("\n substraction of a,b and c= %f",sub);
mul=a*b*c;
printf("\n multiplication of a,b and c= %f",mul);
div=a/b/c;
printf("\n division of a,b and c= %f",div);
getch();
}

2
OUTPUT

3
2. Write a program to calculate simple interest.

#include<stdio.h>

#include<conio.h>

void main()

float t,rt,p,si;

clrscr();

printf("enter years:");

scanf("%f",&t);

printf("\nenter rate:");

scanf("%f",&rt);

printf("\nenter principal:");

scanf("%f",&p);

si=(t*rt*p)/100;

printf("\nsimple interest:%f",si);

getch();

4
OUTPUT

5
3. Write a program to find whether the number entered is even

or odd.

#include<stdio.h>
int main()
{
int n;
clrscr();
printf("\n enter an integer=");
scanf("%d",&n);
if(n%2==0)
printf("\n its a even number");
else
printf("\n its a odd number");
return 0;
}

OUTPUT

6
4. Write a program to calculate Area & Circumference of circle
and Area & Perimeter of rectangle.
#include<stdio.h>
#include<conio.h>
void main()
{
int r,l,b,area1,area2,circumference,perimeter;
clrscr();
printf("\n enter the value of radius=");
scanf("%d",&r);
printf("\n enter the value of length=");
scanf("%d",&l);
printf("\n enter the value of breadth=");
scanf("%d",&b);
circumference= 2*22/7*r;
area1= 22/7*r*r;
perimeter=2*(l+b);
area2= l*b;
printf("\n circumference of circle= %d",circumference);
printf("\n area of circle= %d",area1);
printf("\n perimeter of rectangle= %d",perimeter);
printf("\n area of rectangle= %d",area2);
getch();
}

7
OUTPUT

8
5. Write a program interchange/swap values of two integers

stored at location X and Y with using a third variable and

without using a third variable.

(1) With using third variable


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf("enter value of a:");
scanf("%d",&a);
printf("\nenter value of b:");
scanf("%d",&b);
printf("\nvalues are:\na=%d",a);
printf("\nb=%d",b);
temp=a;
a=b;
b=temp;
printf("\nvalues after swaping:\na=%d",a);
printf("\nb=%d",b);
getch();
}

9
OUTPUT

(2) Without using third variable


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("enter value of a:");
scanf("%d",&a);
printf("\nenter value of b:");
scanf("%d",&b);
10
printf("\nvalues are:\na=%d",a);
printf("\nb=%d",b);
a=a+b;
b=a-b;
a=a-b;
printf("\nvalues after swaping:\na=%d",a);
printf("\nb=%d",b);
getch();
}

OUTPUT

11
6. Write a program to calculate the sum of all digits of a five

digit number and the sum of the first and last digit of the

entered number.

(1) Sum of all digits of the five digit number


#include<stdio.h>
int main()
{
int sum,rem,no;
clrscr();
printf(" enter a five digit number=");
scanf("%d",&no);
sum=0,rem=0;
if(no==0)
printf("\n%d",no);
while(no!=0)
{
rem=no%10;
sum=sum+rem;
no=no/10;
}
printf("\n sum is %d",sum);
}
OUTPUT

12
(2) sum of first and last digit of a five digit number
#include<stdio.h>
int main()
{
int no,first,last;
int sum=0;
clrscr();
printf("\n enter the number:");
scanf("%d",&no);
first=no%10;
last=no/10000;
sum=first+last;
printf("\n the sum of fist and last digit of %d is %d",no,sum);
return 0;
}

OUTPUT

13
7. Write a program to calculate aggregate percentage of a

student based on marks obtained in 5 different subjects. Using

if-else & else-if clause print division of the student.


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e;
float per,agg;
clrscr();
printf("\n enter marks");
scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
agg=(a+b+c+d+e)/500;
per=agg*100;
if(per<=100)
printf("\n first division");
else if(per<=60&&per>=40)
printf("\n second division");
else
printf("\n passed");
getch();
}

OUTPUT

14
8. Write a program to add two numbers using for loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,sum;
clrscr();
for(x=0;x<=3;x++)
{
for(y=0;y<=3;y++)
{
sum=x+y;
printf("\n addition of two number is: %d",sum);
}
}
getch();
}

OUTUPUT

15
9. Write a program to calculate simple interest for 3 instances

using while and do while loop.

(1) Using do while loop


#include<stdio.h>
#include<conio.h>
void main()
{
int p,n,count;
float r,si;
count=1;
clrscr();
do
{
printf("\n enter value of p,n,r");
scanf("%d %d %f",&p,&n,&r);
si=p*n*r/100;
printf("\n si is %f\n",si);
}
while(count<=3);
count=(count+1);
getch();
}

16
OUTPUT

(2) Using while loop


#include<stdio.h>
#include<conio.h>
void main()
{
int p,n,count;
float r,si;
count=1;
clrscr();
while(count<=3)
{
printf("\n enter value of p,n,r");
scanf("%d %d %f",&p,&n,&r);
si=p*n*r/100;
count=(count+1);
printf("\n si is %f\n",si);

17
}
getch();
}

OUTPUT

18
10. Write a program to calculate sum of two numberts using call

by value and call by reference.

(1) Using call by reference


#include<stdio.h>
#include<conio.h>
int add(int *i,int *j);
void main()
{
int i,j,sum;
clrscr();
printf(" enter the value of i and j");
scanf("%d\t%d",&i,&j);
sum=add(&i,&j);
printf("\n sum of %d and %d is: %d",i,j,sum);
getch();
}
int add(int *i,int *j)
{
return *i+*j;
}

OUTPUT

19
(2) Using call by value
#include<stdio.h>
#include<conio.h>
int add(int i,int j);
void main()
{
int i,j,sum;
clrscr();
printf(" enter the value of i and j");
scanf("%d\t%d",&i,&j);
sum=add(i,j);
printf("\n sum of %d and %d is: %d",i,j,sum);
getch();
}
int add(int i,int j)
{
return i+j;
}

OUTPUT

20
11. Write a program to calculate factorial of a number using

recursion.
#include<stdio.h>
#include<conio.h>
int factorial(int i);
void main()
{
int n,result;
clrscr();
printf("enter factorial:");
scanf("%d",&n);
result=factorial(n);
printf("\n %d",result);
getch();
}
int factorial(int i)
{
printf("%d*",i);
if(i<=1)
{
return 1;
}
else
return i*factorial(i-1);
}

OUTPUT

21
12. Write a program to print fibonnacci series using recursion.
#include<stdio.h>
int fibonnacci(int i)
{
if(i==0)
{
return 0;
}
if(i==1)
{
return 1;
}
return fibonnacci(i-1)+fibonnacci(i-2);
}
int main()
{
int i;
clrscr();
for(i=0;i<9;i++)
{
printf("\t %d",fibonnacci(i));
}

OUTPUT

22
13. For an integer i=3 having pointer int *j and int **k. Write a

program to print address of i, j and k and print value stored and

print value stored at k & j; and *j & **k.


#include<stdio.h>
#include<conio.h>
void main()
{
int i=3;
int *j;
int **k;
j=&i;
k=&j;
clrscr();
printf("\n value of i %d",i);
printf("\n value of i %u",&i);
printf("\n value of i is %d",*(&i));
printf("\n value of j is %u",j);
printf("\n value of j is %u",&j);
printf("\n value of j is %u",*(&j));
printf("\n value of j is %d",*j);
printf("\n value of k is %u",k);
printf("\n value of k is %u",&k);
printf("\n value of k is %u",*(&k));
printf("\n value of k is %u",*k);
printf("\n value of k is %d",**k);
getch();
}

23
OUTPUT

24
25
26

You might also like