0% found this document useful (0 votes)
31 views7 pages

Bbca Caiii C Practicla

The document contains 5 C program examples: 1) Find largest of 3 numbers using ternary operator, 2) Check if a number is a palindrome, 3) Print prime numbers within a range, 4) Menu driven application for basic math operations, 5) Sort array elements using bubble sort algorithm.

Uploaded by

Sadhi Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views7 pages

Bbca Caiii C Practicla

The document contains 5 C program examples: 1) Find largest of 3 numbers using ternary operator, 2) Check if a number is a palindrome, 3) Print prime numbers within a range, 4) Menu driven application for basic math operations, 5) Sort array elements using bubble sort algorithm.

Uploaded by

Sadhi Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

* C program to find largest among

Three numbers using ternary operator

*/

#include<stdio.h>

#include<conio.h>

void main()

int a,b,c,larg; // Variable declaration

printf("Enter three number\n");

scanf("%d %d %d",&a,&b,&c);

larg = a>b?a>c?a:c:b>c?b:c; // Largest among a, b and c

printf("largest number is : %d",larg); // Print the largest number

getch();

2.POLNDROM OR NOT

#include <stdio.h>

int main() {

int n, reversed = 0, remainder, original;

printf("Enter an integer: ");

scanf("%d", &n);

original = n;

// reversed integer is stored in reversed variable

while (n != 0) {

remainder = n % 10;
reversed = reversed * 10 + remainder;

n /= 10;

// palindrome if orignal and reversed are equal

if (original == reversed)

printf("%d is a palindrome.", original);

else

printf("%d is not a palindrome.", original);

return 0;

Output

Enter an integer: 1001

1001 is a palindrome.

3.Write a Program to print the prime numbers in given range.(minimum and maximum values should be
accepted from the user)

#include <stdio.h>

int main()

int num1, num2, flag_var, i, j;

/* Ask user to input the from/to range

* like 1 to 100, 10 to 1000 etc.

*/
printf("Enter two range(input integer numbers only):");

//Store the range in variables using scanf

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

//Display prime numbers for input range

printf("Prime numbers from %d and %d are:\n", num1, num2);

for(i=num1+1; i<num2; ++i)

flag_var=0;

for(j=2; j<=i/2; ++j)

if(i%j==0)

flag_var=1;

break;

if(flag_var==0)

printf("%d\n",i);

return 0;

Output:

Enter two range(input integer numbers only):Prime numbers from 1 and 50 are: 1 50
2

11

13

17

19

23

29

31

37

41

43

47

4. Create a menu driven application using switch to find addition, subtraction, multiplication and division
of two numbers.

#include<stdio.h>

int main()

int n,m,t;

char c;

printf("Enter two numbers and operator :\n");

scanf("%d %d %c", &n, &m, &c);

switch(c)
{

case '+' : printf("Addition is : %d", n+m);

break;

case '-' : printf("Substraction is %d", n-m);

break;

case '*' : printf("Multiplication is %d", n*m);

break;

case '/' : printf("Division is %f", (float)n/m);

break;

default : printf("Not valid");

getch();

return 0;

Output

Enter two numbers and operator :

28/

Division is 0.250000

Enter two numbers and operator :

28/
Division is 0.250000

5. Write a Program to sort the elements of an array using bubble sort technique

#include<stdio.h>

int main(){

int count, temp, i, j, number[30];

printf("How many numbers are u going to enter?: ");

scanf("%d",&count);

printf("Enter %d numbers: ",count);

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

scanf("%d",&number[i]);

/* This is the main logic of bubble sort algorithm

*/

for(i=count-2;i>=0;i--){

for(j=0;j<=i;j++){

if(number[j]>number[j+1]){

temp=number[j];

number[j]=number[j+1];

number[j+1]=temp;

}
}

printf("Sorted elements: ");

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

printf(" %d",number[i]);

return 0;

Output:

You might also like