### C program to compute the area and perimeter of a rectangle

Write a program to compute the area and perimeter of a rectangle with a width of three inches and a […]

C, tutorial, beginners, programming, ANSI, simple, examples, language basics, literals, data types, functions, loops, arrays, pointers, structures, input and output, memory management, pre-processors, directives.

WRITE A C PROGRAM TO CALCULATE ROOTS OF A QUADRATIC EQUATION

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
/* How do you write a c program to solve quadratic equation */ #include<stdio.h> #include<math.h> int main(){ float a,b,c; float d,root1,root2; printf("Enter a, b and c of quadratic equation: "); printf("\nA : "); scanf("%f",&a); printf("\nB : "); scanf("%f",&b); printf("\nC : "); scanf("%f",&c); d = b * b - 4 * a * c; if(d < 0){ printf("Roots are complex number.\n"); printf("Roots of quadratic equation are: "); printf("%.3f%+.3fi",-b/(2*a),sqrt(-d)/(2*a)); printf(", %.3f%+.3fi",-b/(2*a),-sqrt(-d)/(2*a)); return 0; } else if(d==0){ printf("Both roots are equal.\n"); root1 = -b /(2* a); printf("Root of quadratic equation is: %.3f ",root1); return 0; } else{ printf("Roots are real numbers.\n"); root1 = ( -b + sqrt(d)) / (2* a); root2 = ( -b - sqrt(d)) / (2* a); printf("Roots of quadratic equation are: %.3f , %.3f",root1,root2); } return 0; } /* OUTPUT: Enter a, b and c of quadratic equation: A : 2 B : -2 C : -1 Roots are real numbers. Roots of quadratic equation are: 1.366 , -0.366 */ |

C – How do I get the directory that a program is running from? In this Tutorial We will learn […]

in this post we will learn how to write a C Program to find area and circumference of circle. Area of […]

In this post we will learn how to Write a c program to reverse a string using C. C already […]

In this post we will learn how to write a C Program to Convert Decimal Numbers to Binary Numbers. Example […]

What is Factorial? The Factorial of a specified number refers to the product of a given series of consecutive whole […]

Here we will learn how to write a C program inorder to check the given number is ARMSTRONG or not. […]

In this example we will learn how to Check if the particular number is Palindrome or not. C – PALINDROMIC NUMBERS […]

C program to reverse a number

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
/** C program to reverse a number by codebind.com */ #include <stdio.h> int main() { int n, reverse = 0; printf("Enter a number to reverse : \n"); scanf("%d", &n); while (n != 0) { reverse = reverse * 10; reverse = reverse + n%10; n = n/10; } printf("Reverse of entered number is = %d\n", reverse); return 0; } /* OUTPUT: Enter a number to reverse : 12345 Reverse of entered number is = 54321 */ |

C program to reverse number using recursion

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
/** C program to reverse number using recursion by codebind.com */ #include <stdio.h> long Reverse(long n) { static long reversed_number = 0; if (n == 0) return 0; reversed_number = reversed_number * 10; reversed_number = reversed_number + n % 10; Reverse(n/10); return reversed_number; } int main() { long number, reversed_result; printf("Enter a number to reverse : \n"); scanf("%ld", &number); reversed_result = Reverse(number); printf("Reverse of entered number is = %ld\n", reversed_result); return 0; } /* OUTPUT: Enter a number to reverse : 12345 Reverse of entered number is = 54321 */ |

Prime Numbers A prime number is an integer greater than 1 that has exactly two divisors, 1 and itself. The […]

C program to find power of two numbers using built in functions pow

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/** C program to find power of two numbers using built in functions pow by codebind.com */ #include<stdio.h> #include<conio.h> #include<math.h> int main() { double number; number = pow(2.0, 4.0); printf("Value of 2^4 = %f", number); getch(); } /* OUTPUT Value of 2^4 = 16.000000 */ |

C program find power of number […]

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/** Write a C Program to Find the Number of Digits in an entered number by codebind.com */ #include<stdio.h> #include<string.h> int main() { int num, digits; char ch[10]; printf("\nEnter the Number : "); scanf("%d", &num); sprintf(ch, "%d", num); digits = strlen(ch); printf("\nNumber of Digits : %d\n", digits); return(0); } /* OUTPUT Enter the Number : 54321 Number of Digits : 5 */ |

Swapping numbers in C means exchanging the values of two C variables with each other. In this lesson we will […]

Write a C Program to find if the number is Odd or Even. Basically Even numbers are those which are […]

Copyright © 2018 | WordPress Theme by MH Themes