SlideShare a Scribd company logo
1
2
3
4
5
Program to Find Roots of a Quadratic Equation
#include <math.h>
#include <stdio.h>
int main() {
double a, b, c, discriminant, root1, root2, realPart,imagPart;
printf("Enter coefficients a, b and c: ");
scanf("%lf %lf %lf", &a,&b, &c);
discriminant = b * b - 4 * a * c;
// condition for real and different roots
if (discriminant > 0) {
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("root1 = %.2lf and root2 = %.2lf", root1, root2);
}
// condition for real and equal roots
else if (discriminant == 0) {
root1 = root2 = -b / (2 * a);
printf("root1 = root2 = %.2lf;", root1);
}
// if roots are not real
else {
realPart = -b / (2 * a);
imagPart = sqrt(-discriminant) / (2 * a);
printf("root1 = %.2lf+%.2lfi and root2 = %.2f-%.2fi", realPart,imagPart, realPart,imagPart);
}
6
return 0;
}
Fibonacci Series up to n terms
#include <stdio.h>
int main() {
int i, n, t1 = 0, t2 = 1, nextTerm;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: ");
for (i = 1; i <= n; ++i) {
printf("%d, ", t1);
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
}
return 0;
}
Armstrong Numbers Between Two Integers
#include <math.h>
#include <stdio.h>
int main() {
int low, high, i, temp1, temp2, rem, n = 0;
float result = 0.0;
printf("Enter two numbers(intervals): ");
scanf("%d %d", &low, &high);
printf("Armstrong numbers between %d and %d are: ", low, high);
for (i = low + 1; i < high; ++i) {
temp2 = i;
temp1 = i;
// number of digits calculation
while (temp1 != 0) {
temp1 /= 10;
++n;
}
// result contains sum of nth power of its digits
while (temp2 != 0) {
rem = temp2 % 10;
result += pow(rem, n);
temp2 /= 10;
}
// check if i is equal to the sum of nth power of its digits
if ((int)result == i) {
7
printf("%d ", i);
}
// resetting the values
n = 0;
result = 0;
}
return 0;
}
Program to Check Prime Number
#include <stdio.h>
int main() {
int n, i, flag = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
for (i = 2; i <= n / 2; ++i) {
// condition for non-prime
if (n % i == 0) {
flag = 1;
break;
}
}
if (n == 1) {
printf("1 is neither prime nor composite.");
}
else {
if (flag == 0)
printf("%d is a prime number.", n);
else
printf("%d is not a prime number.", n);
}
return 0;
}
Display Prime Numbers Between two Intervals
#include <stdio.h>
int main() {
int low, high, i, flag;
printf("Enter two numbers(intervals): ");
scanf("%d %d", &low, &high);
printf("Prime numbers between %d and %d are: ", low, high);
while (low < high) {
flag = 0;
8
// if low is a non-prime number, flag will be 1
for (i = 2; i <= low / 2; ++i) {
if (low % i == 0) {
flag = 1;
break;
}
}
if (flag == 0)
printf("%d ", low);
++low;
}
return 0;
}
Program to convert binary to decimal
#include <math.h>
#include <stdio.h>
int convert(long long n);
int main() {
long long n;
printf("Enter a binary number: ");
scanf("%lld", &n);
printf("%lld in binary = %d in decimal", n, convert(n));
return 0;
}
int convert(long long n) {
int dec = 0, i = 0, rem;
while (n != 0) {
rem = n % 10;
n /= 10;
dec += rem * pow(2, i);
++i;
}
return dec;
}
#include <math.h>
#include <stdio.h>
int convert(long long n);
int main() {
long long n;
printf("Enter a binary number: ");
scanf("%lld", &n);
printf("%lld in binary = %d in decimal", n, convert(n));
return 0;
}
int convert(long long n) {
int dec = 0, i = 0, rem;
9
while (n != 0) {
rem = n % 10;
n /= 10;
dec += rem * pow(2, i);
++i;
}
return dec;
}
Output
Enter a binary number: 110110111
110110111 in binary = 439
Program to convert decimal to binary
#include <math.h>
#include <stdio.h>
long long convert(int n);
int main() {
int n;
printf("Enter a decimal number: ");
scanf("%d", &n);
printf("%d in decimal = %lld in binary", n, convert(n));
return 0;
}
long long convert(int n) {
long long bin = 0;
int rem, i = 1, step = 1;
while (n != 0) {
rem = n % 2;
printf("Step %d: %d/2, Remainder = %d, Quotient = %dn", step++, n, rem, n / 2);
n /= 2;
bin += rem * i;
i *= 10;
}
return bin;
}
Output
Enter a decimal number: 19
Step 1: 19/2, Remainder = 1, Quotient = 9
Step 2: 9/2, Remainder = 1, Quotient = 4
Step 3: 4/2, Remainder = 0, Quotient = 2
Step 4: 2/2, Remainder = 0, Quotient = 1
Step 5: 1/2, Remainder = 1, Quotient = 0
19 in decimal = 10011 in binary
For example we want to convert decimal number 525 in the octal.
Step 1: 525 / 8 Remainder : 5 , Quotient : 65
Step 2: 65 / 8 Remainder : 1 , Quotient : 8
10
Step 3: 8 / 8 Remainder : 0 , Quotient : 1
Step 4: 1 / 8 Remainder : 1 , Quotient : 0
So equivalent octal number is: 1015
That is (525)10 = (1015)8
Example 1: Program to Convert Decimal to Octal
#include <stdio.h>
#include <math.h>
int convertDecimalToOctal(int decimalNumber);
int main()
{
int decimalNumber;
printf("Enter a decimal number: ");
scanf("%d", &decimalNumber);
printf("%d in decimal = %d in octal", decimalNumber, convertDecimalToOctal(decimalNumber));
return 0;
}
int convertDecimalToOctal(int decimalNumber)
{
int octalNumber = 0, i = 1;
while (decimalNumber != 0)
{
octalNumber += (decimalNumber % 8) * i;
decimalNumber /= 8;
i *= 10;
}
return octalNumber;
}
Output
Enter a decimal number: 78
78 in decimal = 116 in octal
Example 2: Program to Convert Octal to Decimal
#include <stdio.h>
#include <math.h>
long long convertOctalToDecimal(int octalNumber);
int main()
{
int octalNumber;
11
printf("Enter an octal number: ");
scanf("%d", &octalNumber);
printf("%d in octal = %lld in decimal", octalNumber, convertOctalToDecimal(octalNumber));
return 0;
}
long long convertOctalToDecimal(int octalNumber)
{
int decimalNumber = 0, i = 0;
while(octalNumber != 0)
{
decimalNumber += (octalNumber%10) * pow(8,i);
++i;
octalNumber/=10;
}
i = 1;
return decimalNumber;
}
Output
Enter an octal number: 116
116 in octal = 78 in decimal
Hexadecimal number system: It is base 16 number system which uses the digits from 0 to 9 and A,
B, C, D, E, F.
Decimal number system:
It is base 10 number system which uses the digits from 0 to 9
Decimal to hexadecimal conversion method:
Following steps describe how to convert decimal to hexadecimal
Step 1: Divide the original decimal number by 16
Step 2: Divide the quotient by 16
Step 3: Repeat the step 2 until we get quotient equal to zero.
Equivalent binary number would be remainders of each step in the reverse order.
Decimal to hexadecimal conversion example:
12
For example we want to convert decimal number 900 in the hexadecimal.
Step 1: 900 / 16 Remainder : 4 , Quotient : 56
Step 2: 56 / 16 Remainder : 8 , Quotient : 3
Step 3: 3 / 16 Remainder : 3 , Quotient : 0
So equivalent hexadecimal number is: 384
That is (900)10 = (384)16
C Program
1. #include<stdio.h>
2. int main() {
3. long int decimalNumber,remainder,quotient;
4. int i=1,j,temp;
5. char hexadecimalNumber[100];
6. printf("Enter any decimal number: ");
7. scanf("%ld",&decimalNumber);
8. quotient = decimalNumber;
9. while(quotient!=0) {
10. temp = quotient % 16;
11. //To convert integer into character
12. if( temp < 10)
13. temp =temp + 48; else
14. temp = temp + 55;
15. hexadecimalNumber[i++]= temp;
16. quotient = quotient / 16;
17. }
18. printf("Equivalent hexadecimal value of decimal number %d: ",decimalNumbe
r);
19. for (j = i -1 ;j> 0;j--)
20. printf("%c",hexadecimalNumber[j]);
21. return 0;
22.}
Output
1. Enter any decimal number: 45
2. Equivalent hexadecimal value of decimal number 45: 2D
Program to Check Palindrome
#include <stdio.h>
int main() {
13
int n, reversedN = 0, remainder, originalN;
printf("Enter an integer: ");
scanf("%d", &n);
originalN = n;
// reversed integer is stored in reversedN
while (n != 0) {
remainder = n % 10;
reversedN = reversedN * 10 + remainder;
n /= 10;
}
// palindrome if orignalN and reversedN are equal
if (originalN == reversedN)
printf("%d is a palindrome.", originalN);
else
printf("%d is not a palindrome.", originalN);
return 0;
}
Power ofa Number Using the while Loop
#include <stdio.h>
int main() {
int base,exp;
long long result = 1;
printf("Enter a base number: ");
scanf("%d", &base);
printf("Enter an exponent: ");
scanf("%d", &exp);
while (exp != 0) {
result *= base;
--exp;
}
printf("Answer = %lld", result);
return 0;
}
Output
Enter a base number: 3
Enter an exponent: 4
Answer = 81

More Related Content

DOCX
C programs
DOCX
Core programming in c
DOCX
Practical write a c program to reverse a given number
PDF
The solution manual of c by robin
DOCX
C Programming
PDF
88 c-programs
DOCX
Practical write a c program to reverse a given number
DOC
C lab-programs
C programs
Core programming in c
Practical write a c program to reverse a given number
The solution manual of c by robin
C Programming
88 c-programs
Practical write a c program to reverse a given number
C lab-programs

What's hot (18)

DOCX
Practical File of C Language
PDF
c-programming-using-pointers
PPTX
Simple c program
RTF
PDF
Common problems solving using c
PDF
C programming
DOCX
C Programming
PDF
C Programming Example
PDF
C programms
PPTX
C Programming Example
DOCX
C programming Lab 2
PPT
All important c programby makhan kumbhkar
PPT
12 lec 12 loop
DOCX
B.Com 1year Lab programs
DOC
Basic c programs updated on 31.8.2020
PDF
C lab programs
PDF
C programs
Practical File of C Language
c-programming-using-pointers
Simple c program
Common problems solving using c
C programming
C Programming
C Programming Example
C programms
C Programming Example
C programming Lab 2
All important c programby makhan kumbhkar
12 lec 12 loop
B.Com 1year Lab programs
Basic c programs updated on 31.8.2020
C lab programs
C programs
Ad

Similar to Program flowchart (20)

DOCX
c plus plus programsSlide
PDF
C faq pdf
DOCX
PPT
45196656565656565656565656565656565656566.ppt
PDF
9.C Programming
PDF
Functions
PPT
chapter 3 000Number_Systems.ppt
PPTX
NumberSystems.pptx
PPTX
NumberSystems.pptx
PDF
03_NumberSystems.pdf
PDF
C and Data Structures Lab Solutions
PDF
C lab excellent
PDF
C and Data Structures
RTF
DCF QNA edited
PPTX
Computer Representation of Numbers and.pptx
PPTX
C programming BY Mazedur
PDF
Stack Applications : Infix to postfix conversion, Evaluation of postfix expre...
DOC
Useful c programs
PPT
Number Systems and its effectiveness .ppt
c plus plus programsSlide
C faq pdf
45196656565656565656565656565656565656566.ppt
9.C Programming
Functions
chapter 3 000Number_Systems.ppt
NumberSystems.pptx
NumberSystems.pptx
03_NumberSystems.pdf
C and Data Structures Lab Solutions
C lab excellent
C and Data Structures
DCF QNA edited
Computer Representation of Numbers and.pptx
C programming BY Mazedur
Stack Applications : Infix to postfix conversion, Evaluation of postfix expre...
Useful c programs
Number Systems and its effectiveness .ppt
Ad

More from Sowri Rajan (11)

DOCX
Unit 5 dwqb ans
PDF
Unit 3 (1)
PDF
Unit 2
PDF
Unit 1
PDF
Unit 5 quesn b ans5
DOCX
Unit 5 quesn b ans5
DOCX
Unit 4 qba
PDF
Unit 4 qba
DOCX
Unitii string
DOCX
Unitii classnotes
DOCX
Uniti classnotes
Unit 5 dwqb ans
Unit 3 (1)
Unit 2
Unit 1
Unit 5 quesn b ans5
Unit 5 quesn b ans5
Unit 4 qba
Unit 4 qba
Unitii string
Unitii classnotes
Uniti classnotes

Recently uploaded (20)

PDF
Sports Quiz easy sports quiz sports quiz
PDF
RMMM.pdf make it easy to upload and study
PDF
Pre independence Education in Inndia.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Lesson notes of climatology university.
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Pharma ospi slides which help in ospi learning
PDF
01-Introduction-to-Information-Management.pdf
PPTX
master seminar digital applications in india
PDF
Complications of Minimal Access Surgery at WLH
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Cell Structure & Organelles in detailed.
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Sports Quiz easy sports quiz sports quiz
RMMM.pdf make it easy to upload and study
Pre independence Education in Inndia.pdf
PPH.pptx obstetrics and gynecology in nursing
Anesthesia in Laparoscopic Surgery in India
Lesson notes of climatology university.
Abdominal Access Techniques with Prof. Dr. R K Mishra
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Supply Chain Operations Speaking Notes -ICLT Program
Pharma ospi slides which help in ospi learning
01-Introduction-to-Information-Management.pdf
master seminar digital applications in india
Complications of Minimal Access Surgery at WLH
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Microbial diseases, their pathogenesis and prophylaxis
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Cell Structure & Organelles in detailed.
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape

Program flowchart

  • 1. 1
  • 2. 2
  • 3. 3
  • 4. 4
  • 5. 5 Program to Find Roots of a Quadratic Equation #include <math.h> #include <stdio.h> int main() { double a, b, c, discriminant, root1, root2, realPart,imagPart; printf("Enter coefficients a, b and c: "); scanf("%lf %lf %lf", &a,&b, &c); discriminant = b * b - 4 * a * c; // condition for real and different roots if (discriminant > 0) { root1 = (-b + sqrt(discriminant)) / (2 * a); root2 = (-b - sqrt(discriminant)) / (2 * a); printf("root1 = %.2lf and root2 = %.2lf", root1, root2); } // condition for real and equal roots else if (discriminant == 0) { root1 = root2 = -b / (2 * a); printf("root1 = root2 = %.2lf;", root1); } // if roots are not real else { realPart = -b / (2 * a); imagPart = sqrt(-discriminant) / (2 * a); printf("root1 = %.2lf+%.2lfi and root2 = %.2f-%.2fi", realPart,imagPart, realPart,imagPart); }
  • 6. 6 return 0; } Fibonacci Series up to n terms #include <stdio.h> int main() { int i, n, t1 = 0, t2 = 1, nextTerm; printf("Enter the number of terms: "); scanf("%d", &n); printf("Fibonacci Series: "); for (i = 1; i <= n; ++i) { printf("%d, ", t1); nextTerm = t1 + t2; t1 = t2; t2 = nextTerm; } return 0; } Armstrong Numbers Between Two Integers #include <math.h> #include <stdio.h> int main() { int low, high, i, temp1, temp2, rem, n = 0; float result = 0.0; printf("Enter two numbers(intervals): "); scanf("%d %d", &low, &high); printf("Armstrong numbers between %d and %d are: ", low, high); for (i = low + 1; i < high; ++i) { temp2 = i; temp1 = i; // number of digits calculation while (temp1 != 0) { temp1 /= 10; ++n; } // result contains sum of nth power of its digits while (temp2 != 0) { rem = temp2 % 10; result += pow(rem, n); temp2 /= 10; } // check if i is equal to the sum of nth power of its digits if ((int)result == i) {
  • 7. 7 printf("%d ", i); } // resetting the values n = 0; result = 0; } return 0; } Program to Check Prime Number #include <stdio.h> int main() { int n, i, flag = 0; printf("Enter a positive integer: "); scanf("%d", &n); for (i = 2; i <= n / 2; ++i) { // condition for non-prime if (n % i == 0) { flag = 1; break; } } if (n == 1) { printf("1 is neither prime nor composite."); } else { if (flag == 0) printf("%d is a prime number.", n); else printf("%d is not a prime number.", n); } return 0; } Display Prime Numbers Between two Intervals #include <stdio.h> int main() { int low, high, i, flag; printf("Enter two numbers(intervals): "); scanf("%d %d", &low, &high); printf("Prime numbers between %d and %d are: ", low, high); while (low < high) { flag = 0;
  • 8. 8 // if low is a non-prime number, flag will be 1 for (i = 2; i <= low / 2; ++i) { if (low % i == 0) { flag = 1; break; } } if (flag == 0) printf("%d ", low); ++low; } return 0; } Program to convert binary to decimal #include <math.h> #include <stdio.h> int convert(long long n); int main() { long long n; printf("Enter a binary number: "); scanf("%lld", &n); printf("%lld in binary = %d in decimal", n, convert(n)); return 0; } int convert(long long n) { int dec = 0, i = 0, rem; while (n != 0) { rem = n % 10; n /= 10; dec += rem * pow(2, i); ++i; } return dec; } #include <math.h> #include <stdio.h> int convert(long long n); int main() { long long n; printf("Enter a binary number: "); scanf("%lld", &n); printf("%lld in binary = %d in decimal", n, convert(n)); return 0; } int convert(long long n) { int dec = 0, i = 0, rem;
  • 9. 9 while (n != 0) { rem = n % 10; n /= 10; dec += rem * pow(2, i); ++i; } return dec; } Output Enter a binary number: 110110111 110110111 in binary = 439 Program to convert decimal to binary #include <math.h> #include <stdio.h> long long convert(int n); int main() { int n; printf("Enter a decimal number: "); scanf("%d", &n); printf("%d in decimal = %lld in binary", n, convert(n)); return 0; } long long convert(int n) { long long bin = 0; int rem, i = 1, step = 1; while (n != 0) { rem = n % 2; printf("Step %d: %d/2, Remainder = %d, Quotient = %dn", step++, n, rem, n / 2); n /= 2; bin += rem * i; i *= 10; } return bin; } Output Enter a decimal number: 19 Step 1: 19/2, Remainder = 1, Quotient = 9 Step 2: 9/2, Remainder = 1, Quotient = 4 Step 3: 4/2, Remainder = 0, Quotient = 2 Step 4: 2/2, Remainder = 0, Quotient = 1 Step 5: 1/2, Remainder = 1, Quotient = 0 19 in decimal = 10011 in binary For example we want to convert decimal number 525 in the octal. Step 1: 525 / 8 Remainder : 5 , Quotient : 65 Step 2: 65 / 8 Remainder : 1 , Quotient : 8
  • 10. 10 Step 3: 8 / 8 Remainder : 0 , Quotient : 1 Step 4: 1 / 8 Remainder : 1 , Quotient : 0 So equivalent octal number is: 1015 That is (525)10 = (1015)8 Example 1: Program to Convert Decimal to Octal #include <stdio.h> #include <math.h> int convertDecimalToOctal(int decimalNumber); int main() { int decimalNumber; printf("Enter a decimal number: "); scanf("%d", &decimalNumber); printf("%d in decimal = %d in octal", decimalNumber, convertDecimalToOctal(decimalNumber)); return 0; } int convertDecimalToOctal(int decimalNumber) { int octalNumber = 0, i = 1; while (decimalNumber != 0) { octalNumber += (decimalNumber % 8) * i; decimalNumber /= 8; i *= 10; } return octalNumber; } Output Enter a decimal number: 78 78 in decimal = 116 in octal Example 2: Program to Convert Octal to Decimal #include <stdio.h> #include <math.h> long long convertOctalToDecimal(int octalNumber); int main() { int octalNumber;
  • 11. 11 printf("Enter an octal number: "); scanf("%d", &octalNumber); printf("%d in octal = %lld in decimal", octalNumber, convertOctalToDecimal(octalNumber)); return 0; } long long convertOctalToDecimal(int octalNumber) { int decimalNumber = 0, i = 0; while(octalNumber != 0) { decimalNumber += (octalNumber%10) * pow(8,i); ++i; octalNumber/=10; } i = 1; return decimalNumber; } Output Enter an octal number: 116 116 in octal = 78 in decimal Hexadecimal number system: It is base 16 number system which uses the digits from 0 to 9 and A, B, C, D, E, F. Decimal number system: It is base 10 number system which uses the digits from 0 to 9 Decimal to hexadecimal conversion method: Following steps describe how to convert decimal to hexadecimal Step 1: Divide the original decimal number by 16 Step 2: Divide the quotient by 16 Step 3: Repeat the step 2 until we get quotient equal to zero. Equivalent binary number would be remainders of each step in the reverse order. Decimal to hexadecimal conversion example:
  • 12. 12 For example we want to convert decimal number 900 in the hexadecimal. Step 1: 900 / 16 Remainder : 4 , Quotient : 56 Step 2: 56 / 16 Remainder : 8 , Quotient : 3 Step 3: 3 / 16 Remainder : 3 , Quotient : 0 So equivalent hexadecimal number is: 384 That is (900)10 = (384)16 C Program 1. #include<stdio.h> 2. int main() { 3. long int decimalNumber,remainder,quotient; 4. int i=1,j,temp; 5. char hexadecimalNumber[100]; 6. printf("Enter any decimal number: "); 7. scanf("%ld",&decimalNumber); 8. quotient = decimalNumber; 9. while(quotient!=0) { 10. temp = quotient % 16; 11. //To convert integer into character 12. if( temp < 10) 13. temp =temp + 48; else 14. temp = temp + 55; 15. hexadecimalNumber[i++]= temp; 16. quotient = quotient / 16; 17. } 18. printf("Equivalent hexadecimal value of decimal number %d: ",decimalNumbe r); 19. for (j = i -1 ;j> 0;j--) 20. printf("%c",hexadecimalNumber[j]); 21. return 0; 22.} Output 1. Enter any decimal number: 45 2. Equivalent hexadecimal value of decimal number 45: 2D Program to Check Palindrome #include <stdio.h> int main() {
  • 13. 13 int n, reversedN = 0, remainder, originalN; printf("Enter an integer: "); scanf("%d", &n); originalN = n; // reversed integer is stored in reversedN while (n != 0) { remainder = n % 10; reversedN = reversedN * 10 + remainder; n /= 10; } // palindrome if orignalN and reversedN are equal if (originalN == reversedN) printf("%d is a palindrome.", originalN); else printf("%d is not a palindrome.", originalN); return 0; } Power ofa Number Using the while Loop #include <stdio.h> int main() { int base,exp; long long result = 1; printf("Enter a base number: "); scanf("%d", &base); printf("Enter an exponent: "); scanf("%d", &exp); while (exp != 0) { result *= base; --exp; } printf("Answer = %lld", result); return 0; } Output Enter a base number: 3 Enter an exponent: 4 Answer = 81