C program to add two number | Sum of two numbers This is a small program in C to add two number using arithmetic operators. Also Read : C program to add two numbers without using arithmetic operators Code for sum of two numbers #include<stdio.h> int main() { int a, b, sum; printf("\nEnter two no: "); scanf("%d %d", &a, &b); ...

Read More »## c program to swap two numbers without using a third variable

Swap two numbers without using a third variable | Swap Two numbers without using a temporary variable: There are 4 tricks to swap two numbers without using a third variable. You can use of them for your program. However the trick #4 is the smartest, fastest & easiest of all. The trick used is nothing but basic mathematics fundamentals like: multiplication, ...

Read More »## C program for dfs – Depth First Search

This is a c program for DFS – depth first search In which the the searching goes on to all the siblings first rather than the nodes i.e the first item searched is the leftmost leaf node. Moreover you have to enter the number of nodes in the graph and the adjacency matrix. Though leftmost node is searched still extra ...

Read More »## c program to find the square root of a number without using sqrt()

Can you write a c program to find the square root of a number without using sqrt() function or other predefined functions. This has been a great challenge in interview as you can do it by using newtons algorithm which you should previously know for implementing. However here are mentioned some useful methods to solve this question.

Read More »## c program for diamond shape pattern #16

This is a C program for diamond shape pattern which can be both filled and empty. However this choice is left for the user who can enter their choice as per their requirement. #include<stdio.h> int main() { char empty=' ',fill='e'; int i,j,height; printf("\n enter the height for Diamond (odd number) :"); scanf("%d",&height); printf("\nenter 'E' for empty and 'F' for filled ...

Read More »## c program for pattern#12

Pattern#12 1 12 123 1234 This pattern is also an easy one , where you have to indent each line accordingly. Here you can observe that the indentation is directly related to the numbers in each row. If no. of lines are n . then for ith row output is= (n-i)Blank spaces + (1 to i) numbers Also check: Alternate Java ...

Read More »## c program for pattern#14

Pattern #14 1 01 101 0101 10101 This is a tricky pattern where you have to reduce your coding otherwise it easy using if statement . Can you do it without if statement? Also see: Alternate Java program for pattern#14 #include<stdio.h> void main() { int i,j,calc; for(i=1;i<=5;i++) { for(j=0;j<i;j++) { calc=(i+j)%2; printf("%d",calc); } printf("\n"); } } OUTPUT:

Read More »## c program for pattern#15

1 123 12345 1234567 123456789 This is a simple pyramid pattern which can be implemented using nested loop – either while or for loop. #include<stdio.h> int main() { int n,i,j,p; // initialize the variables printf("Enter the number of lines in the pattern\n"); scanf("%d",&n); // number of lines to be printed for(i=1;i<=n;i++) // loop for spaces in 1st triangle { for(j=1;j<=n-i;j++) ...

Read More »## c program for Star Pattern

c program for Star Pattern * *** ***** ******* ********* Also see : Alternate Java program for pattern#6 #include<stdio.h> int main() { int n,i,j; // initialize the variables printf("Enter the number of rows in the pattern : "); scanf("%d",&n); // number of rows to be printed. for(i=1;i<=n;i++) // loop for number of rows in pyramid { for(j=1;j<=n-i;j++) // loop for ...

Read More »## c program for pattern#6

Pattern#6 * *** ***** ******* ********* Also see : Alternate Java program for pattern#6 #include<stdio.h> int main() { int n,i,j; // initialize the variables printf("Enter the number of rows in the pattern : "); scanf("%d",&n); // number of rows to be printed. for(i=1;i<=n;i++) // loop for number of rows in pyramid { for(j=1;j<=n-i;j++) // loop for spaces printf(" "); // ...

Read More »