Found 33676 Articles for Programming

What is a simple assertion in C language?

Bhanu Priya
Updated on 26-Mar-2021 07:47:41

287 Views

An assertion is a statement which is used to declare positively that a fact must be true when that line of code is reached.Assertions are useful for obtaining the expected conditions which are met.Simple AssertionSimple assertion can be implemented by using assert (expression) method, which is present in assert.h header file.The syntax for simple assertion is as follows −assert(expression)In simple assertion, When the condition passed to an assertion which is a true, then, there is no action.The behaviour on false statements depends completely on compiler flags.When assertions are enabled, a false input causes a program to halt.When assertions are disabled, ... Read More

C Program to find sum of perfect square elements in an array using pointers.

Bhanu Priya
Updated on 26-Mar-2021 07:45:42

2K+ Views

ProblemWrite a program to find the sum of perfect square elements in an array by using pointers.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 find the sum of perfect square elements in an array by using pointers. Step 1 − Read number of elements in array at ... Read More

C program to add all perfect square elements in an array.

Bhanu Priya
Updated on 26-Mar-2021 07:42:51

2K+ Views

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

C program to swap two strings

Bhanu Priya
Updated on 26-Mar-2021 07:45:27

11K+ Views

For swapping two strings from one location to another location, we use strcpy() function.An array of characters (or) collection of characters is called a string.DeclarationFollowing is the declaration for an array −char stringname [size];For example, char string[50]; string of length 50 characters.InitializationUsing single character constantchar string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constantschar string[10] = "Hello":;AccessingThere is a control string "%s" used for accessing the string till it encounters ‘\0’strcpy ( )This function is used for copying source string into destination string.The length of the destination string is greater than or equal to the source string.The syntax ... Read More

C program to represent the alphabets in spiral pattern

Bhanu Priya
Updated on 26-Mar-2021 07:44:06

282 Views

The spiral pattern to represent the alphabets is as follows −The logic used to represent the alphabets in spiral model is as follows −if(rows=1){    for(i=1;i

C program to represent the numbers in spiral pattern

Bhanu Priya
Updated on 26-Mar-2021 07:41:25

1K+ Views

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

C program to find array type entered by user using pointers.

Bhanu Priya
Updated on 26-Mar-2021 07:39:56

587 Views

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

C program to find type of array entered by the user.

Bhanu Priya
Updated on 26-Mar-2021 07:34:34

942 Views

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

C Program to display the numbers in X pattern

Bhanu Priya
Updated on 26-Mar-2021 07:37:30

2K+ Views

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

C program for testing the character type

Bhanu Priya
Updated on 26-Mar-2021 07:33:20

1K+ Views

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

Advertisements