C Programs
C Programs
#include <math.h>
#include <stdio.h>
void main()
{
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);
}
getch();
}
Input
5.6
Output:
#include<stdio.h>
#include<conio.h>
void main()
{
int n1=0,n2=1,n3,i,number;
printf("Enter the number of elements:");
scanf("%d",&number);
printf("\n%d %d",n1,n2);
for(i=2;i<number;++i)
{
n3=n1+n2;
printf(" %d",n3);
n1=n2;
n2=n3;
}
getch();
}
Input:
Enter the number of elements:6
Output:
0
1
1
2
3
5
#include <stdio.h>
#include <math.h>
void main() {
double number, squareRoot;
input:
printf("Enter a positive number: ");
scanf("%lf", &number);
if (number < 0) {
printf("Invalid input. Please enter a positive number.\n");
goto input; }
squareRoot = sqrt(number);
printf("Square root of %.2f is %.2f\n", number, squareRoot);
getch();
}
Input
Output