ProblemWrite a program to find the sum of perfect square elements in an array.Given a number of elements in array as input and the sum of all the perfect square of those elements present in the array is output.SolutionFor example, Input= 1, 2, 3, 4, 5, 9, 10, 11, 16 The perfect squares are 1, 4, 9, 16. Sum = 1 + 4 + 9 +16 = 30 Output: 30AlgorithmRefer an algorithm given below to add the perfect square elements in an array.Step 1 − Read number of elements in array at runtime.Step 2 − Input the elements.Step 3 − ... Read More
The spiral pattern to represent the numbers is shown below −The logic applied to print the numbers in spiral pattern is as follows −for(i=1;i
ProblemWrite a C Program to find the array type that we need to check, whether the given elements in an array are even numbers or odd numbers or combination of both by using pointers.SolutionThe user has to enter an array of integers, then, display the type of the array.Example 1 − Input: 5 3 1, Output: odd arrayExample 2 − Input: 2 4 6 8, Output: even arrayExample 3 − Input: 1 2 3 4 5, Output: mixed arrayAlgorithmRefer an algorithm given below to find the array type entered by user with the help of pointers.Step 1: Read the size ... Read More
Refer an algorithm given below for the C program to display the numbers in X pattern.AlgorithmStep 1: Start Step 2: Declare variables Step 3: Read number of rows Step 4: for loop satisfiesif(i==j || i+j==rows-1)print i+1Print " "Step 5: Print new line Step 6: StopThe logic to print numbers in X pattern is as follows −for(i=0;i
ProblemWrite a C Program to find the array type which we need to check, whether the given elements in an array are even numbers or odd numbers or combination of both.SolutionSo, user has to enter an array of integers, then, display the type of the array.Example 1 − Input: 5 3 1, Output: odd array.Example 2 − Input: 2 4 6 8, Output: even array.Example 3 − Input: 1 2 3 4 5, Output: mixed array.AlgorithmRefer an algorithm given below to find the array type entered by the user.Step 1 − Read the size of array at runtime.Step 2 − ... Read More
There are some predefined functions available in "ctype.h" library for analyzing the character input and converting them.Analysis FunctionsThe character analysis functions are listed below −FunctionChecks whether entered character isisalphaAn alphabet (or) notisdigitA digit (or) notisspace QA space, a newline (or) tabispunct (A special symbol (or) notislowerA lower case letter of alphabetisupper QAn upper case letter of alphabetisalphanumericAn alphabet/digit or notConverting FunctionsThe converting functions are listed below −FunctionConversiontolower()Converts an upper case alphabet to lower casetoupper QConverts a lower case alphabet to upper caseProgramFollowing is the C program for character analysis and conversion functions which are used to test the character type ... Read More
Write a program to find out that a given character is upper case, lower case, number or special character.SolutionIf an entered character is capital letter then, it displays the upper case.Example: Input =H Output: upper case letterIf an entered character is small letter then, it displays the lower case letter.Example: Input= g Output: lower case letterIf an entered character is number then, it displays the digit.Example: Input=3 Output: digitIf an entered character is a special character then, it displays the special character.Example: Input= & Output: special characterAlgorithmRefer an algorithm given below to find out that a given character is upper ... Read More
User has to enter total number of days. We need to convert the total number of days into months and left-over days in coming month.The formula to convert days into months is as follows − Month=days/30The logic to find left-over days for the coming month is as follows − Days=days %30AlgorithmRefer an algorithm given below to convert days into months and number of days.Step 1: Start Step 2: Declare month and days Step 3: Read total number of days Step 4: Compute months months=days/30 Step 5: Compute days Days= days ... Read More
All mathematical related functions are stored in math.h header file in C programming language. The functions are explained below in detail.sin()This function is used to find the sin value of its argument.The syntax of sin() function is as follows −double sin(double a);For example, double a=sin(3.14/2);The output is as follows −a=1 (approx.)cos()It is used to find the cos value of its argument.The syntax for cos() function is as follows −double cos(double a); For example, double a=cos(3.14/2);The output is as follows −a=0 (approx.)tan()It is used to find the tan value of its argument.The syntax for tan() function is as follows −double tan ... Read More
ProblemWrite a program to find the quadrant in which the given coordinates lie.User has to enter a coordinate at runtime and we need to find the quadrant in which these coordinates lie.SolutionIf both numbers are positive then, it displays the first quadrant.Example: Input =2, 3 Output = 1st quadrantIf the first number is negative and the second number is positive then, it displays the second quadrant.Example: Input = -4, 3 Output= 2nd quadrantIf the first number is negative and the second number is also negative then, it displays the third quadrant.Example: Input = -5, -7 Output= 3rd quadrantIf the first ... Read More