C Practice Question Example
In C practice Question has more then 100+ Question with Code .and this programs are catograize with all diffrent topic in c .i hope you will enjoy our c practice Example with coding program.
Basic Program
- Write a program in c to take your name, father name, college name, and course name as input from the user then print it.
- Write a program in c take input of five subjects from the user and find out total marks and percentage.
- Write a program in c take two numbers and input through the keyboard into two locations C and D interchange the contents of C and D.
- Write a program in c to take two numbers from the user and swap them without temp.
- Write a program in c to take length and width as input from the user to find the Area and Perimeter of a Rectangle.
- Write a program in c take the input radius from the user and find the circumference of circle and the area of a circle.
- Write a program in c that takes input as two numbers from the user finds the sum of numbers finds the sum of numbers and square of that sum result and then also calculates the cube of square result.
- Write a program in c to take input as the temperature in degrees Celsius and convert it to Fahrenheit.
- Write a program in c to take input P, T, and R from the user and find out simple interests.
- Write a program to print whether two numbers are equal or not.
- Write a c program to check whether a number is divisible by 5 or not.
- Write a c program to input week number and print week day.
- Write a c program to input any alphabet and check whether it is vowel or consonant.
- Write a program to check number is negative, positive, or zero in c.
- Write a program in c to check whether the number is odd or even.
-
• For the first 50 units Rs. 0.50/unit
• For the next 100 units Rs. 0.75/unit
• For the next 100 units Rs. 1.20/unit
-
Write a c program to check you are eligible for vote or not/drive or not.
- Write a program in c take two numbers from user and find out largest number using conditional operator.
- Write a program in c take three numbers are input from user and find the greatest number among three.
- Write a program in c to check number is prime or not.
- Write a program the number is greater or smaller in c.
-
Write a program in c to find & display sum of 6+12+18+….N term and 4+10+16+…N Term , n to be entered by the user.
-
Write a cpp program to find Fibonacci Series up to n number of terms.
The Fibonacci sequence is like this,
0, 1, 1, 2, 3, 5, 8, 13, 21.....n term.
- Write a program in c to check you are eligible for vote or not/drive or not.
- Write a program in c to check whether a number is a palindrome or not.
- Write a program in c take input salary from user theen increase 10% of salary and print total salary of employee..
- Write a program in c to check whether an alphabet is vowel or a consonant using switch case.
- Write a program in c,accept 1 to 7 number and display their respective day name using switch case.
- Write a program in c Menu driven programm for all arithmetic operation by switch case.
- Write a program in c to enter a number then print their English word.
-
Write a menu driven program which accepts a user’s choice to calculate and display area of any of the following shapes ,with reqired inputs entered by the user for the desired shape: a)The menu should keep reappearing till the user chooses an option Exit to exit the program execution b) a.Area of a rectangle b. Area of a triangle c. Area of Circle
-
Write a c program to create simple calculator using switch case.
- Write a c program to check whether a number is positive ,negative or zero using switch case.
- Write a c program to check whether a number is even or odd using switch case.
- Write a program in c to print 1 to 10 numbers.
- Write a program in c to add 1 to 10 numbers.
- write a program in c take number as input from the user and generate table
- Write a program in c to find even numbers in 1 to 50.
- Write a program in c to find odd numbers in 1 to 50.
- Write a program in c to display a range of alphabets in reversed & alternative order.
-
Write a program in c to display the numbers in reverse order.
Example :
Number : 1345
The number in reverse order is : 5431
-
Write a program in c to display the pattern like right angle triangle with number.
1
12
123
1234
12345 -
Write a C program that makes a pattern such as below.
1 22 333 4444 55555
-
Write a C program that makes a pattern such as below.
55555 4444 333 22 1
-
Write a program in c that makes a pattern such as below.
1 2 3 4 5 6 7 8 9 10
-
Write a program in c that makes a pattern such as below.
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
-
Write a program in c that makes a pattern such as below.
* * * * * * * * * * * * * * *
-
Write a program in c that makes a pattern such as below.
* * * * *
* * * *
* * *
* *
* -
Write a program in c that makes a pattern such as below.
* * * * *
* * * *
* * *
* *
* - Write a c program to take input 10 number in two array and find out addition of two array .
- Write a c program to count total number of elements in an array.
- Write a c program to array of matrices.
- Take 10 integer inputs from user and store them in an array. Now, copy all the elements in another array but in reverse order.
- Write a c program to take input 10 number in array and find sum of all number and product.
- Write a c program to take input 5 number in array and find out square of all number.
- Write a program in c Take 10 integer as inputs from user in array and find out all even number and all odd number.
- Write a c program to take input 5 subject of marks in array and find out total marks and percentage.
- Write a c program to print all negative elements in an array.
- Write a c program to take 10 number as input from user in array and find out the largest element of array.
- Write a c program to take 10 number as input from user in array and find out the Smallest element of array.
- Write a c program to take 10 number as input from user in array and find out the Second largest element of array.
- Write a c program to take 10 number as input from user in array and find out the Second Smallest element of array.
- Write a c program to addition two matrices.
- Write a c program to check whether two matrices are equal or not.
- Write a bubble sort program in c.
- Write a linear search programming in c.
- Write a Insertion sorting program in c.
- Write a searching program in c.
- Write Binary Search program in c language.
- Write a c program to take 10 number as input from user in array and then take any number as input in another variable then search this number is exist or not.
- Write a c program to find length of a string.
- Write a c program to copy one string to another string.
- Write a c program to concatenate two strings.
- Write a c program to compare two strings.
- Write a c program to convert lowercase string to uppercase.
- Write a c program to convert uppercase string to lowercase.
- Write a c program to toggle case of character of a string.
- Write a c program to find reverse of a string.
- Write a c program to reverse order of words in a given string.
- Write a c program to find cube of any number using function.
- Write a c program to find diameter,circumference and area of circle using functions.
- Write a c program to check whether a number is even or odd using functions.
- Write a program in C to swap elements using call by reference.
- Write a c program to find factorial of any number using recursion.
- Write a c program to print all natural numbers between 1 to n using recursion.
- Create a structure called "Student" with members name, age, and total marks. Write a C program to input data for two students, display their information, and find the average of total marks.
- Define a structure named Time with members hours, minutes, and seconds. Write a C program to input two times, add them, and display the result in proper time format.
- Create a structure named Book to store book details like title, author, and price. Write a C program to input details for three books,an display Inforamtion.
- Define a structure named Circle to represent a circle with a radius. Write a C program to calculate the area circle and display the results.
- Create a structure named "Employee" to store employee details such as employee ID, name, and salary. Write a program to input data for three employees, find the highest salary employee, and display their information.
- Create a structure named "Date" with members day, month, and year. Write a C program to display information.
- Write a c program to add two numbers using pointers.
- Write a c program to swap two numbers using pointers.
- write a c program to find length of string using poinetrs
- write a c program to reverse an array using pointers.
- Write a c program to find reverse of a string using pointers.
Q. Write a program in c to input your name, father name, college name, and course name as input from the user then print it.
#include<stdio.h>
#include<conio.h>
int main(){
char name[50],f_name[50],c_name[50],co_name[20];
//take the input using scanf
printf("Enter your name:");
scanf("%s",&name);
printf("Enter your father name:");
scanf("%s",&f_name);
printf("Enter your college name:");
scanf("%s",&c_name);
printf("Enter your course name:");
scanf("%s",&co_name);
//print the data
printf("\n========Output============\n");
printf("\nNAME: %s ",name);
printf("\nFATHER NAME: %s",f_name);
printf("\nCOLLEGE NAME: %s",c_name);
printf("\nCOURSE NAME: %s",co_name);
getch();
return 0;
}
2.Write a program in c take two numbers as input from the user and find out the addition of two numbers.
//Write a program in c take two numbers as input from the user and find out the addition of two numbers.
#include<stdio.h>
#include<conio.h>
int main(){
int a,b,sum;
printf("ENTER THE FIRST NUMBER:");
scanf("%d",&a);
printf("ENTER THE SECOND NUMBER:");
scanf("%d",&b);
sum=a+b;
printf("THE SUM IS:%d",sum);
getch();
return 0;
}
3.Write a program in c take two numbers as input from the user and find out the subtraction of two numbers.
//Write a program in c take two numbers as input from the user and find out the subtraction of two numbers.
#include<stdio.h>
#include<conio.h>
int main(){
int a,b;
printf("ENTER THE NUMBER:");
scanf("%d",&a);
printf("ENTER THE SECOND NUMBER:");
scanf("%d",&b);
int sub=a-b;
printf("THE SUBTRACTON IS: %d",sub);
getch();
return 0;
}
4.Write a program in c take input of five subjects from the user and find out total marks and percentage.
//Write a program in c take input of five subjects from the user and find out total marks and percentage.
#include<stdio.h>
#include<conio.h>
int main(){
int eng,mar,math,sci,hin;
printf("ENTER THE MARKS OF FIVE SUBJECTS:");
scanf("%d %d %d %d %d",&eng,&mar,&math,&sci,&hin);
int total=eng+mar+math+sci+hin;
float per=(float)(total*100)/500;
printf("THE TOTAL IS : %d",total);
printf("\nTHE PERCENTAGE IS : %f",per);
getch();
return 0;
}
5.Write a program in c take two numbers and input through the keyboard into two locations C and D interchange the contents of C and D.
// C Program to Swap Two Numbers using a Temporary Variable
#include <stdio.h>
int main() {
int a = 5, b = 10, temp;
printf("Before swapping: a = %d, b = %d\n", a, b);
// Swapping values of a and b
temp = a;
a = b;
b = temp;
printf("After swapping: a = %d, b = %d\n", a, b);
return 0;
}
6.Write a program in c to take two numbers from the user and swap them without temp.
#include<stdio.h>
int main()
{
int a=10, b=20;
printf("Before swap a=%d b=%d",a,b);
a=a+b;//a=30 (10+20)
b=a-b;//b=10 (30-20)
a=a-b;//a=20 (30-10)
printf("\nAfter swap a=%d b=%d",a,b);
return 0;
}
7.Write a program in c to take length and width as input from the user to find the Area and Perimeter of a Rectangle.
// C program to demonstrate the
// area and perimeter of rectangle
#include <stdio.h>
int main()
{
int l,b;
printf("ENTER THE LENGTH:");
scanf("%d",&l);
printf("ENTER THE BREADTH:");
scanf("%d",&b);
int A, P;
A = l * b;
P = 2 * (l + b);
printf("Area of rectangle is : %d", A);
printf("\nPerimeter of rectangle is : %d", P);
return 0;
}
8.Write a program in c take the input radius from the user and find the circumference of circle and the area of a circle.
#include <stdio.h> // Standard input-output header file
// Define the constant value of Pi (p)
#define PI 3.14159
int main() {
double radius, area, circumference;
// Prompt the user to enter the radius of the circle
printf("Enter the radius of the circle: ");
// Read the user input and store it in the variable 'radius'
scanf("%lf", &radius);
// Calculate the area of the circle using the formula: Area = pr^2
area = PI * radius * radius;
// Calculate the circumference of the circle using the formula: Circumference = 2pr
circumference = 2 * PI * radius;
// Display the calculated area
printf("The area of the circle is: %lf\n", area);
// Display the calculated circumference
printf("The circumference of the circle is: %lf\n", circumference);
return 0; // Return 0 to indicate successful execution
}
9.Write a program in c that takes input as two numbers from the user finds the sum of numbers finds the sum of numbers and square of that sum result and then also calculates the cube of square result.
//Write a program in c that takes input as two numbers from the user finds the sum of numbers finds the sum of numbers and square of that sum result and then also calculates the cube of square result.
#include<conio.h>
#include<stdio.h>
int main()
{
int a,b,sum,square,cube;
printf("ENTER TWO NUMBERS:");
scanf("%d %d",&a,&b);
sum=a+b;
square=sum*sum;
cube=sum*sum*sum;
printf("THE SUM IS : %d",sum);
printf("\nTHE SQUARE OF THE RESULT IS : %d",square);
printf("\nTHE CUBE OF THE RESULT IS : %d",cube);
return 0;
}
10.Write a program in c to take input as the temperature in degrees Celsius and convert it to Fahrenheit.
#include<stdio.h>
int main()
{
float fahrenheit, celsius;
printf("ENTER TEMPERATURE IN CELCIUS:");
scanf("%f",&celsius);
fahrenheit =( (celsius*9)/5)+32;
printf("\n\n Temperature in fahrenheit is: %f",fahrenheit);
return (0);
}
11.Write a program in c to take input P, T, and R from the user and find out simple interests.
#include <stdio.h>
int main()
{
float principle, time, rate, SI;
/* Input principle, rate and time */
printf("Enter principle (amount): ");
scanf("%f", &principle);
printf("Enter time: ");
scanf("%f", &time);
printf("Enter rate: ");
scanf("%f", &rate);
/* Calculate simple interest */
SI = (principle * time * rate) / 100;
/* Print the resultant value of SI */
printf("Simple Interest = %f", SI);
return 0;
}
12.Write a program to print whether two numbers are equal or not.
#include <stdio.h> // Include the standard input/output header file.
int main()
{
int int1, int2; // Declare two integer variables 'int1' and 'int2'.
printf("Input the values for Number1 and Number2 : "); // Prompt the user to input values for Number1 and Number2.
scanf("%d %d", &int1, &int2); // Read and store the user's input in 'int1' and 'int2'.
if (int1 == int2) // Check if Number1 is equal to Number2.
printf("Number1 and Number2 are equal\n"); // Print a message if Number1 and Number2 are equal.
else
printf("Number1 and Number2 are not equal\n"); // Print a message if Number1 and Number2 are not equal.
return 0;
}
13.Write a c program to check whether a number is divisible by 5 or not.
#include <stdio.h>
int main()
{
int num;
printf("Enter any number: ");
scanf("%d", &num);
if(num % 5 ==0)
{
printf("Number is divisible by 5");
}
else
{
printf("Number is not divisible by 5");
}
return 0;
}
14.Write a c program to input week number and print week day.
#include <stdio.h>
int main()
{
int week;
/* Input week number from user */
printf("Enter week number (1-7): ");
scanf("%d", &week);
if(week == 1)
{
printf("Monday");
}
else if(week == 2)
{
printf("Tuesday");
}
else if(week == 3)
{
printf("Wednesday");
}
else if(week == 4)
{
printf("Thursday");
}
else if(week == 5)
{
printf("Friday");
}
else if(week == 6)
{
printf("Saturday");
}
else if(week == 7)
{
printf("Sunday");
}
else
{
printf("Invalid Input! Please enter week number between 1-7.");
}
return 0;
}
15.Write a c program to input any alphabet and check whether it is vowel or consonant.
#include <stdio.h>
int main() {
char c;
int lowercase_vowel, uppercase_vowel;
printf("Enter an alphabet: ");
scanf("%c", &c);
// evaluates to 1 if variable c is a lowercase vowel
lowercase_vowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
// evaluates to 1 if variable c is a uppercase vowel
uppercase_vowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
// evaluates to 1 (true) if c is a vowel
if (lowercase_vowel || uppercase_vowel)
printf("%c is a vowel.", c);
else
printf("%c is a consonant.", c);
return 0;
}
16.Write a program to check number is negative, positive, or zero in c.
#include<stdio.h>
int main()
{
int num;
printf("ENTER NUMBER:");
scanf("%d",&num);
if(num == 0)
printf("The Number is Zero");
else if(num < 0)
printf("Negative");
else
printf("Positive");
return 0;
}
17.Write a program in c to check whether the number is odd or even.
#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
// true if num is perfectly divisible by 2
if(num % 2 == 0)
printf("%d is even.", num);
else
printf("%d is odd.", num);
return 0;
}
18.Write a c program to input the customer ID, name, and electricity unit consumed by the user and calculate the total electricity bill according to the given condition.
• For the first 50 units Rs. 0.50/unit
• For the next 100 units Rs. 0.75/unit
• For the next 100 units Rs. 1.20/unit
.For units above 250 Rs. 1.50/unit
• An additional surcharge of 20% is added to the bill
#include <stdio.h>
int main() {
int customerID;
char customerName[50];
float unitsConsumed, bill, totalBill;
// Input customer details
printf("Enter Customer ID: ");
scanf("%d", &customerID);
printf("Enter Customer Name: ");
scanf(" %[^\n]s", customerName); // Read string with spaces
printf("Enter Units Consumed: ");
scanf("%f", &unitsConsumed);
// Calculate the bill based on the units consumed
if (unitsConsumed <= 50) {
bill = unitsConsumed * 0.50;
} else if (unitsConsumed <= 150) {
bill = (50 * 0.50) + ((unitsConsumed - 50) * 0.75);
} else if (unitsConsumed <= 250) {
bill = (50 * 0.50) + (100 * 0.75) + ((unitsConsumed - 150) * 1.20);
} else {
bill = (50 * 0.50) + (100 * 0.75) + (100 * 1.20) + ((unitsConsumed - 250) * 1.50);
}
// Add a surcharge of 20%
totalBill = bill + (0.20 * bill);
// Output the total bill
printf("\nCustomer ID: %d\n", customerID);
printf("Customer Name: %s\n", customerName);
printf("Units Consumed: %.2f\n", unitsConsumed);
printf("Total Electricity Bill: Rs. %.2f\n", totalBill);
return 0;
}
19.write a c program to enter marks of five subjects and calculate the Total, Percentage, and find Grade according to the following Conditions:.
Percentage >= 90% : Grade A
Percentage >= 80% : Grade B
Percentage >= 70% : Grade C
Percentage >= 60% : Grade D
Percentage >= 40% : Grade E
Percentage < 40% : Grade F
#include <stdio.h>
int main() {
float marks[5];
float total = 0.0, percentage;
char grade;
// Input marks for five subjects
printf("Enter marks for five subjects:\n");
for (int i = 0; i < 5; i++) {
printf("Subject %d: ", i + 1);
scanf("%f", &marks[i]);
total += marks[i]; // Calculate total marks
}
// Calculate percentage
percentage = (total / 500) * 100; // Assuming each subject is out of 100
// Determine grade based on percentage
if (percentage >= 90) {
grade = 'A';
} else if (percentage >= 80) {
grade = 'B';
} else if (percentage >= 70) {
grade = 'C';
} else if (percentage >= 60) {
grade = 'D';
} else if (percentage >= 40) {
grade = 'E';
} else {
grade = 'F';
}
// Output total, percentage, and grade
printf("\nTotal Marks: %.2f\n", total);
printf("Percentage: %.2f%%\n", percentage);
printf("Grade: %c\n", grade);
return 0;
}
20.write a c programm to take input absent days and find out Total Fine fees accourding to below Condition.
1 week pay 5 rs per day
2 week pay 10 rs per day
3 week pay 15 rs per day
Rest 20 rupees per days.
#include <stdio.h>
int main() {
int absentDays;
int totalFine = 0;
// Ask user to input the number of absent days
printf("Enter the number of absent days: ");
scanf("%d", &absentDays);
// Calculate the fine based on the conditions
if (absentDays <= 7) {
totalFine = absentDays * 5;
} else if (absentDays <= 14) {
totalFine = 7 * 5 + (absentDays - 7) * 10;
} else if (absentDays <= 21) {
totalFine = 7 * 5 + 7 * 10 + (absentDays - 14) * 15;
} else {
totalFine = 7 * 5 + 7 * 10 + 7 * 15 + (absentDays - 21) * 20;
}
// Print the total fine
printf("Total Fine: %d rupees\n", totalFine);
return 0;
}
21.Write a c program to check you are eligible for vote or not/drive or not.
#include <stdio.h>
int main() {
int age;
// Ask user to input their age
printf("Enter your age: ");
scanf("%d", &age);
// Check eligibility for voting
if (age >= 18) {
printf("You are eligible to vote.\n");
} else {
printf("You are not eligible to vote.\n");
}
// Check eligibility for driving
if (age >= 16) {
printf("You are eligible to drive.\n");
} else {
printf("You are not eligible to drive.\n");
}
return 0;
}
22.Write a program in c take two numbers from user and find out largest number using conditional operator.
#include <stdio.h>
int main() {
int num1, num2, largest;
// Ask user to input two numbers
printf("Enter first number: ");
scanf("%d", &num1);
printf("Enter second number: ");
scanf("%d", &num2);
// Use conditional logic to assign the largest number
if (num1 > num2) {
largest = num1; // num1 is larger
} else {
largest = num2; // num2 is larger or both are equal
}
// Output the largest number
printf("The largest number is: %d\n", largest);
return 0;
}
23.Write a program in c take three numbers are input from user and find the greatest number among three.
#include <stdio.h>
int main() {
int num1, num2, num3;
// Ask user to input three numbers
printf("Enter first number: ");
scanf("%d", &num1);
printf("Enter second number: ");
scanf("%d", &num2);
printf("Enter third number: ");
scanf("%d", &num3);
// Find the greatest number using if-else statements
if (num1 >= num2 && num1 >= num3) {
printf("The greatest number is: %d\n", num1);
} else if (num2 >= num1 && num2 >= num3) {
printf("The greatest number is: %d\n", num2);
} else {
printf("The greatest number is: %d\n", num3);
}
return 0;
}
24.Write a program in c to check number is prime or not.
#include <stdio.h>
int main() {
int num, i, isPrime = 1;
// Ask the user to enter a number
printf("Enter a number: ");
scanf("%d", &num);
// Handle edge cases for numbers less than 2
if (num <= 1) {
isPrime = 0; // 0 and 1 are not prime numbers
} else {
// Check divisibility from 2 to sqrt(num)
for (i = 2; i * i <= num; i++) {
if (num % i == 0) {
isPrime = 0; // Not a prime number if divisible by i
break;
}
}
}
// Print whether the number is prime or not
if (isPrime) {
printf("%d is a prime number.\n", num);
} else {
printf("%d is not a prime number.\n", num);
}
return 0;
}
check using function
#include<stdio.h>
#include<stdbool.h>
bool check_prime(int num)
{
bool isPrime=true;
int i;
if(num==0||num==1)
{
isPrime=false;
return isPrime;
}
for(i=2;i<=num/2;i++)
{
if(num%i==0)
{
return isPrime=false;
}
}
return isPrime;
}
int main()
{
int n,i;
printf("Enter a Number");
scanf("%d",&n);
if(check_prime(n))
{
printf("its prime number");
}
else
{
printf("its not prime number");
}
return 0;
}
using function between 1 to nth term
#include<stdio.h>
#include<stdbool.h>
bool check_prime(int num)
{
bool isPrime=true;
int i;
if(num==0||num==1)
{
isPrime=false;
return isPrime;
}
for(i=2;i<=num/2;i++)
{
if(num%i==0)
{
return isPrime=false;
}
}
return isPrime;
}
int main()
{
int n,i;
printf("Enter n Number for find prime number ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(check_prime(i))
{
printf("%d , ",i);
}
}
return 0;
}
nsertion sorting in c
// Insertion sort in C
#include <stdio.h>
int main() {
int data[50] ,step,i,n;
printf("Enter Size of array (Max 50 )");
scanf("%d",&n);
printf("Enter array elements in array \n");
for(i=0;i<n;i++)
{
scanf("%d",&data[i]);
}
for ( i = 1; i < n; i++) {
int key = data[i];
int j = i - 1;
while (key < data[j] && j >= 0) {
data[j + 1] = data[j];
--j;
}
data[j + 1] = key;
}
printf("Sorted array in ascending order:\n");
for (i = 0; i < n; i++) {
printf("%d ", data[i]);
}
}
Linear Search program in c language
#include<stdio.h>
int main()
{
int num[50],data,found,i,n,loc;
printf("Enter Size of array (Max 50 )");
scanf("%d",&n);
printf("Enter array elements in array \n");
for(i=0;i<n;i++)
{
scanf("%d",&num[i]);
}
printf("enter element to be searched for\n");
scanf("%d",&data);
for(i=0;i<n;i++)
{
if(num[i]==data)
{
found=1;
loc=i;
}
}
if(found==1)
{
printf("Data Found Possition at %d",loc+1);
}
else
{
printf("Data not found");
}
return 0;
}
Binary Search program in c language.
#include<stdio.h>
int main()
{ //in binary search first check mid point is equal
//or not with item
int num[50],data,beg,last,n,mid,x=0,l,i; // if item is greater then chenge mid with beg
printf("Enter Size of array (Max 50 )"); //if item is smaller then change mid with last
scanf("%d",&n);
printf("Enter array elements in asc order \n");
for(i=0;i<n;i++)
{
scanf("%d",&num[i]);
}
printf("enter element to be searched for\n");
scanf("%d",&data);
beg=0;
last=n-1;
while(beg<=last && !x)
{
mid=(beg+last)/2;
if(data==num[mid])
{
x=1;
l=mid;
}
else if(data>num[mid])
{
beg=mid+1;
}
else
{
last=mid-1;
}
}
if(x==1)
{
printf("data Found possition at %d",l+1);
}
else
{
printf("not found");
}
return 0;
}
Last Updated on : 10th Dec 2024 15:56:44 PM
Latest Update
- JavaScript Interview Question MongoDb Command Curd Operation Node MonogoDb Express EJSC Practice Question Example Data Structure with CPPjava practice questionCurd operation with localstorage in javascriptComplete curd operation in react with json server and axios and router-domCPP Practice Question React Interview Question Java Pattern Program