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

BCA-110 Practical Software Lab

BCA-106, i.e.‘C’ Programming
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views

BCA-110 Practical Software Lab

BCA-106, i.e.‘C’ Programming
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

INDEX

S TOPIC’S PAGE REMARKS


NO. NO.
1. W.A.P to find factorial of any number.
2. W.A.P to find number is greater than8 or
not using if else.
3. W.A.P to find character is vowel or not
using else if ladder.
4. W.A.P to find greater between 3no.using
nested if.
5. W.A.P using while loop to display even
no. B/W 1to 50.
6. W.A.P using do while loop display
Counting 1 to 50.
7. W.A.P using for loop to display table of
any number.
8. W.A.P using switch to display days of
week.
9. W.A.P to check number is positive or
negative.
10. W.A.P of Fibonacci series.
11. W.A.P to display star pattern.
12. W.A.P to find location of an element In
an array.
13. W.A.P of call by value.
14. W.A.P of call by reference.
15. W.A.P of sum using pointer.
W.A.P to find factorial of any number:

#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;

printf("Enter the value of num1: ");


scanf("%d", &num1);
if(num1 > num )
{
printf("%d is greater",num1);
}
else
{
printf("%d is smaller",num1);
}
return 0;
}

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;

printf("Enter the number of terms: ");


scanf("%d", &n);

printf("Fibonacci series: ");


for (i = 0; i < n; i++) {
if (i <= 1)
next = i;
else
{
next = first + second;
first = second;
second = next;
}
printf("%d ", next);
}

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;

printf("\nEnter the element to be


searched: ");
scanf("%d", &element);

for (i = 0; i < 5; i++)


{
if (element == a[i])
{
printf("Item is in list at
location %d.\n", i);
return 0;
}
}

printf("Item is not in the list.\n");

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;

printf("Before swapping, x = %d and y


= %d\n", x, y);
addresses of x and y
swap(&x, &y);

printf("After swapping, x = %d and y


= %d\n", x, y);

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>

void swap(int *a, int *b)


{
int temp = *a;
*a = *b;
*b = temp;
}

int main()
{
int x = 10, y = 20;

printf("Before swapping: x = %d, y = %d\n",


x, y);
// Passing the addresses of x and y
swap(&x, &y);

printf("After swapping: x = %d, y = %d\n",


x, y);

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;

printf("Enter two numbers: ");


scanf("%d %d", &num1, &num2);

ptr1 = &num1;
ptr2 = &num2;

sum = *ptr1 + *ptr2;


printf("Sum = %d\n", sum);
return 0;
}
Output :-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy