Skip to main content

Featured

C++ Program to Perform Linear Search on a Vector

  C++ Program to Perform Linear Search on a Vector Introduction In this C++ program, we will learn how to perform a Linear Search on a vector. The program first takes the size of the vector and its elements as input. Then it asks the user for the element to search. If the element is found, it displays the index where it is located. Otherwise, it displays a message indicating that the element is not found. C++ Program #include<bits/stdc++.h> using namespace std; int main() { int num, search, found = 0; cout << "Enter the size of the vector:" << endl; cin >> num; vector<int> v(num); cout << "Enter " << num << " elements in vector:" << endl; for(int i = 0; i < num; i++) { cin >> v[i]; } cout << "Enter element that you want to search:" << endl; cin >> search; for(int i = 0; i < num; i++) { ...

Write a program to print the grade for a given percentage in c

Description : 

You have to read a interger value from user, it should be less than 100.

*) if percentage is greater than 90 and less than or equal to 100 - 'A'

*) if percentage is greater than 70 and less than 91 - 'B'

*) if percentage is greater than 50 and less than 71 - 'C'

*) if percentage is less than or equal to 50 - 'F'

Sample Execution : 

Test case 1 : 

Enter the percentage : 95

The Grade is A

Test case 2 :

Enter the percentage : 115

Error : Please enter the percentage less than or equal to 100. 


PROGRAM:

---------------------------------------------------------------------------------------------------------------------


#include<stdio.h>

int main()

{

    int percentage;

     // printf("Enter the percentage:");

    scanf("%d",&percentage);

     if(percentage>=90 && percentage <=100)

    {

        printf("The Grade is A");

    }

    else if(percentage>=70 && percentage <=91)

     {

        printf("The Grade is B");

    }

    else if(percentage>=51 && percentage <=71)

     {

        printf("The Grade is C");

    }

     else if(percentage<=50)

   {

        printf("The Grade is F");

    }

    else 

    {   printf("Error : Please enter the percentage less than or equal to 100.");

    }

     }

------------------------------------------------------------------------------------------------------------------------

Comments

Popular Posts

🌙