Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

#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;

if (discriminant > 0) {

root1 = (-b + sqrt(discriminant)) / (2 * a);

root2 = (-b - sqrt(discriminant)) / (2 * a);

printf("root1 = %.2lf and root2 = %.2lf", root1, root2);

else if (discriminant == 0) {

root1 = root2 = -b / (2 * a);

printf("root1 = root2 = %.2lf;", root1);

else {

realPart = -b / (2 * a);

imagPart = sqrt(-discriminant) / (2 * a);

printf("root1 = %.2lf+%.2lfi and root2 = %.2f-%.2fi", realPart, imagPart, realPart, imagPart);

return 0;

}
#include <stdio.h>

int main() {

int a, b, c;

printf("Enter 3 numbers: ");

scanf("%d %d %d", &a, &b, &c);

int max_num, min_num;

max_num = min_num = a;

if (b > max_num) {

max_num = b;

} else if (b < min_num) {

min_num = b;

if (c > max_num) {

max_num = c;

} else if (c < min_num) {

min_num = c;

printf("Maximum number: %d\n", max_num);

printf("Minimum number: %d\n", min_num);

return 0;

}
#include<stdio.h>

int main()

int i,fact=1,number;

printf("Enter a number: ");

scanf("%d",&number);

for(i=1;i<=number;i++){

fact=fact*i;

printf("Factorial of %d is: %d",number,fact);

return 0;

}
#include <stdio.h>

main(){

int s=1;

int n;

printf("Enter the value of n \n");

scanf("%d",&n);

for(int i=1;i<n;i++)

s+=(5*i);

printf("sum is %d \n",s);

}
#include <stdio.h>

main(){

int n;

printf("Enter the value of n \n");

scanf("%d",&n);

for(int i=1;i<=n;i++){

for(int j=1;j<=i;j++)

printf("*");

printf("\n");
}

}
#include <stdio.h>

int main() {

int n;

printf("Enter the number of lines: ");

scanf("%d", &n);

for (int i = 1; i <= n; i++) {

for (int j = 1; j <= n - i; j++) {

printf(" ");

for (int j = 1; j <= i; j++) {

printf("%d", j);

for (int j = i - 1; j >= 1; j--) {

printf("%d", j);

printf("\n");

return 0;}

You might also like