C Articles

Page 91 of 96

Print values of ‘a’ in equation (a+b) <= n and a+b is divisible by x

Sunidhi Bansal
Sunidhi Bansal
Updated on 30-Jul-2019 159 Views

Given with equation program must find the value of ‘a’ where a+b Declare start variables b=10, x=9, n=40 and flag=0, divisible Step 2 -> Loop For divisible = (b / x + 1 ) * x and divisible = 1       Print divisible-1       Set flag=1    End END STOPExample#include int main(int argc, char const *argv[]) {    int b=10, x=9, n=40, flag = 0;    int divisible;    for (divisible = (b / x + 1 ) * x ; divisible = 1) {          printf("%d ", divisible - b );          flag = 1;       }    }    return 0; }Outputif we run above program then it will generate following output8 17 26

Read More

Print the given pattern recursively

Sunidhi Bansal
Sunidhi Bansal
Updated on 30-Jul-2019 4K+ Views

Here, as per the given problem pattern needs to be displayed using recursive approach.Recursive function is the one that calls itself n number of times. There can be ‘n’ number of recursive function in a program. The problem working with recursive function is their complexity.AlgorithmSTART Step 1 -> function int printpattern(int n)    If n>0       Printpattern(n-1)       Print *    End IF End Step 2 -> function int pattern(int n)    If n>0       pattern(n-1)    End IF    Printpattern(n)    Print End STOPExample#include int printpattern(int n) {    if(n>0) { ...

Read More

Difference between %p and %x in C/C++

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 10K+ Views

Here we will see what are the differences between %p and %x in C or C++. The %p is used to print the pointer value, and %x is used to print hexadecimal values. Though pointers can also be displayed using %u, or %x. If we want to print some value using %p and %x then we will not feel any major differences. The only difference that can be noticed is that the %p will print some leading zeros, but %x doesn’t.Example#include main() {    int x = 59;    printf("Value using %%p: %p", x);    printf("Value using %%x: %x", x); ...

Read More

A comma operator question in C/C++ ?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 358 Views

Comma Operator in C/C++ programming language has two contexts −As a Separator −As an operator − The comma operator { , } is a binary operator that discards the first expression (after evaluation) and then use the value of the second expression. This operator has the least precedence.Consider the following codes and guess the output −Example Live Demo#include int main(void) {    char ch = 'a', 'b', 'c';    printf("%c", ch);    return 0; }OutputIt gives an error because the works as a separator.prog.c: In function ‘main’: prog.c:5:20: error: expected identifier or ‘(’ before 'b' char ch = 'a', 'b', ...

Read More

C Program to print hollow pyramid and diamond pattern

George John
George John
Updated on 30-Jul-2019 3K+ Views

Here we will see how to generate hollow pyramid and diamond patterns using C. We can generate solid Pyramid patterns very easily. To make it hollow, we have to add some few tricks.Hollow PyramidFor the pyramid at the first line it will print one star, and at the last line it will print n number of stars. For other lines it will print exactly two stars at the start and end of the line, and there will be some blank spaces between these two starts.Example Code#include int main() {    int n, i, j;    printf("Enter number of lines: ...

Read More

An Uncommon representation of array elements in C/C++

Nitya Raut
Nitya Raut
Updated on 30-Jul-2019 152 Views

This is a simple C++ program of an uncommon representation of array elements.#include using namespace std; int main() { int array[5] = {7,7,7, 6, 6}; for (int i = 0; i < 5; i++) cout

Read More

Octal literals in C

Jennifer Nicholas
Jennifer Nicholas
Updated on 30-Jul-2019 5K+ Views

In C/C++ we can use octal literals by typing a zero before the actual number. For example, if an octal number is 25, then we have to write 025.Example Code#include int main() {    int a = 025;    int b = 063;    printf("Decimal of 25(Octal) is %d", a);    printf("Decimal of 63(Octal) is %d", b); }OutputDecimal of 25(Octal) is 21 Decimal of 63(Octal) is 51

Read More

Write a C program that does not terminate when Ctrl+C is pressed

Arjun Thakur
Arjun Thakur
Updated on 30-Jul-2019 2K+ Views

In this section we will see how to write a program in C that cannot be terminated by the Ctrl + C key.The Ctrl + C generates the keyboard interrupt, and it stops the execution of the current process. Here when we will press the Ctrl + C key, it will print a message then continues the execution. To use this functionality, we will use the signal handling technique in C. When the Ctrl + C is pressed it generates SIGINT signal. There are some other signals and their functionalities in the following list.SignalDescriptionSIGABRTIndicates Abnormal terminationSIGFPE Indicates floating point exceptionSIGILL Indicates invalid ...

Read More

Does Ternary operation exist in MySQL just like C or C++?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 155 Views

Yes, let us first see the working of ternary operator in C or C++ language.X=(X > 10 && ( X-Y) < 0) ?: X:(X-Y);Here is the demo code in C language. After that we will check in MySQL. The C code is as follows −#include int main() {    int X;    int Y;    int result;    printf("Enter the value for X:");    scanf("%d", &X);    printf("Enter the value for Y:");    scanf("%d", &Y);    result=( X > 1 && (X-Y) < 0) ? X: (X-Y);    printf("The Result is=%d", result);    return 0; }The snapshot of C ...

Read More

C program to print characters without using format specifiers

George John
George John
Updated on 30-Jul-2019 863 Views

In this article we will see how we can print some characters without using any kind of format specifiers. The format specifiers in C are %d, %f, %c etc.These are used to print characters and numbers in C using the printf() function.Here we will see another way to print characters without using %c format specifier. This can be done by putting ASCII values directly in hexadecimal form.Example Code#include main () { printf("\x41 "); //41 is ASCII of A in Hex printf("\x52 "); //41 is ASCII of A in Hex printf("\x69 ...

Read More
Showing 901–910 of 953 articles
« Prev 1 89 90 91 92 93 96 Next »
Advertisements