BCA-110 Practical Software Lab
BCA-110 Practical Software Lab
#include<stdio.h>
int factorialItrative(int n)
{
int val=1;
for (int i=n; i>1; i--)
{
val *= i;
}
return val;
}
int main()
{
int n;
printf("enter the number for factorial cal
culation\n");
scanf("%d", &n);
int factorial=factorialItrative(n);
printf("the value of factorial %d\n",factorial);
return 0;
}
Output :-
W.A.P to find number is greater than 8 or
not using if else:
#include <stdio.h>
int main()
{
int num1,num=8;
Output :-
W.A.P to find character is vowel or not
using else if ladder:
int main()
{
char Character;
printf("Enter a character: ");
scanf("%c", &Character);
if (Character == 'a')
{
printf("It's a vowel\n");
}
else if (Character == 'e')
{
printf("It's a vowel\n");
}
else if (Character == 'i')
{
printf("It's a vowel\n");
}
else if (Character == 'o')
{
printf("It's a vowel\n");
}
else if (Character == 'u')
{
printf("It's a vowel\n");
}
else
{
printf("It is not a vowel\n");
}
return 0;
}
Output :-
W.A.P to find greater between 3 no.using
nested if:
#include<stdio.h>
int main()
{
int A,B,C;
printf("Enter the value of A , B & C: \n");
scanf("%d %d %d",&A,&B,&C);
if (A >= B && A >= C)
printf("%d is the largest number", A);
if (B >= A && B >= C)
printf("%d is the largest number.", B);
if (C >= B && C >= A)
printf("%d is the largest number.", C);
return 0;
}
Output :-
W.A.P using while loop to display even no.
B/W 1to 50:
#include<stdio.h>
int main()
{
int n,number=1;
printf("Enter the value of N: ");
scanf("%d",&n);
printf("Even numbers from 1
to %d:\n",n);
while (number <= n)
{
if (number % 2 == 0)
{
printf("%d\n", number);
}
number ++;
}
return 0;
}
Output :-
W.A.P using do while loop display
Counting 1 to 50:
#include<stdio.h>
int main()
{
int numb=1;
printf("counting form 1to50\n");
do{
printf("%d\n",numb);
numb++;
}
while(numb <= 50);
return 0;
}
Output :-
W.A.P using for loop to display table of any
number:
#include<stdio.h>
int main()
{
int number, i, a;
printf("Enter number: ");
scanf("%d", &number);
for(i = 1; i <= 10; i++)
{
a = number * i;
printf("%d x %d = %d\n", number, i, a);
}
return 0;
}
Output :-
W.A.P using switch to display days of week:
#include<stdio.h>
int main()
{
int ch;
printf("Enter user choice :");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("monday");
break;
case 2: printf("tuesday");
break;
case 3: printf("wednesday");
break;
case 4: printf("thursday");
break;
case 5: printf("friday");
break;
case 6: printf("saturday");
break;
case 0: printf("sunday");
break;
default : printf("Invalid User Chice");
}
return 0;
Output :-
W.A.P to check number is positive or
negative:
#include<stdio.h>
int main()
{
int a;
printf("Enter the value of a");
scanf("%d",&a);
if(a>0)
{
printf("number is positive");
}
else{
printf("number is negative");
}
return 0;
}
Output :-
W.A.P of Fibonacci series:
#include<stdio.h>
int main()
{
int n, first = 0, second = 1, next, i;
return 0;
}
Output :-
W.A.P to display star pattern:
#include<stdio.h>
int main()
{
int rows,i,j;
printf("Number of rows:");
scanf("%d",&rows);
for(i=1;i<=rows;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
Output :-
W.A.P to find location of an element In an
array:
#include<stdio.h>
int main()
{
int a[5] = {10, 20, 30, 40, 50};
int element, i;
return 0;
}
Output :-
W.A.P of call by value:
#include <stdio.h>
void swap(int *a, int *b);
int main()
{
int x = 10, y = 20;
return 0;
}
// Function definition
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
Output :-
W.A.P of call by reference:
#include <stdio.h>
int main()
{
int x = 10, y = 20;
return 0;
}
Output :-
W.A.P of sum using pointer:
#include <stdio.h>
#include<conio.h>
int main()
{
int num1, num2, sum;
int *ptr1, *ptr2;
ptr1 = &num1;
ptr2 = &num2;