Skip to main content

Featured

C Program to Check Prime Number Using Efficient Logic

  Introduction A prime number is a number that has exactly two distinct positive divisors: 1 and itself. In this program, we check whether a given number is prime or not using a simple and efficient logic. This type of program is commonly used in mathematics, competitive programming, and basic algorithm learning for beginners in C programming. Problem Statement The task is to write a C program that determines whether a given integer is a prime number or not. The program takes a single integer input from the user and analyzes its divisibility. If the number has no divisors other than 1 and itself, it should be identified as a prime number; otherwise, it is not prime. This problem is important in number theory and has practical relevance in areas such as cryptography, data validation, and algorithm design.  Algorithm / Logic Explanation To check whether a number is prime, we need to verify that it is not divisible by any number other than 1 and itself. The algorithm follows a si...

WAP to print the grade for a given percentage

 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.");

    }

     


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


sample input;

Enter the percentage:95

sample output;

The Grade is A

Comments

Popular Posts

🌙