Skip to main content

Featured

C Program to Solve Two Sum Using Brute Force (With Algorithm & Output)

 Introduction The Two Sum problem is a popular coding interview question where we must find two indices of an array whose values add up to a given target. This program demonstrates a simple brute-force solution in C using nested loops and dynamic memory allocation. Problem Statement Given an integer array and a target value, return the indices of the two numbers such that they add up to the target. Each input has exactly one solution, and the same element cannot be used twice. The result should return the indices, not the values. If no solution exists, return NULL.  Algorithm / Logic Explanation Start the program. Traverse the array using a loop from index 0 to numsSize - 1 . Inside this loop, use another loop starting from i + 1 to numsSize - 1 . For every pair (i, j) , check if nums[i] + nums[j] == target . If condition becomes true: Allocate memory for 2 integers using malloc() . Store indices i and j . Set returnSize = 2 . Return the result poi...

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

🌙