Last active
March 24, 2018 01:06
-
-
Save saifsmailbox98/85509ab718af84bb3e24d9ccded1a5bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
void main() | |
{ | |
float a, b, c, D; | |
printf("ax^2+bx+c=0.\n"); | |
printf("Enter the values of a, b and c.\n"); | |
scanf("%f %f %f", &a, &b, &c); | |
// printf("%fx^2+%fx+%f=0", a, b, c); | |
D = pow(b,2)-4*a*c; | |
if(D==0){ | |
printf("The quadratic equation has real and equal roots.\n"); | |
printf("Both the roots are %f.", -b/(2*(float)a)); | |
}else if(D>0){ | |
printf("The quadratic equation has real and distinct roots.\n"); | |
printf("The roots are %f and %f.", (-b+sqrt(D))/(2*a),(-b-sqrt(D))/(2*a) ); | |
}else{ | |
printf("The quadratic equation has imaginary roots."); | |
} | |
} | |
******************************** | |
******************************** | |
/****************************************************************************** | |
Online C Compiler. | |
Code, Compile, Run and Debug C program online. | |
Write your code in this editor and press "Run" button to compile and execute it. | |
*******************************************************************************/ | |
#include <stdio.h> | |
#include <math.h> | |
int fact(int n){ | |
int product = 1; | |
while(n){ | |
product *= n; | |
n--; | |
} | |
return product; | |
} | |
void main() | |
{ | |
int n, i = 0; | |
float sum = 0; | |
printf("Enter the number of terms: "); | |
scanf("%d", &n); | |
for(i = 1; i <=n; i++){ | |
sum += pow(i,i)/fact(i); | |
} | |
printf("The sum of the series upto %d terms is %f.", n, sum); | |
} | |
/****************************************************************************** | |
Online C Compiler. | |
Code, Compile, Run and Debug C program online. | |
Write your code in this editor and press "Run" button to compile and execute it. | |
*******************************************************************************/ | |
#include <stdio.h> | |
int main() | |
{ | |
int i, n, arr[50], temp,a , b; | |
printf("Enter the number of elements: "); | |
scanf("%d", &n); | |
for(i=0; i<n;i++){ | |
scanf("%d", &arr[i]); | |
} | |
a = 0; | |
b = 0; | |
for(i=0; i<n;i++){ | |
if(arr[i]>arr[a]){ | |
a=i; | |
} | |
if(arr[i]<arr[b]){ | |
b=i; | |
} | |
} | |
temp = arr[a]; | |
arr[a] = arr[b]; | |
arr[b] = temp; | |
printf("Array after swapping:\n"); | |
for(i=0; i<n;i++){ | |
printf("%d ", arr[i]); | |
} | |
} | |
/****************************************************************************** | |
Online C Compiler. | |
Code, Compile, Run and Debug C program online. | |
Write your code in this editor and press "Run" button to compile and execute it. | |
*******************************************************************************/ | |
#include <stdio.h> | |
int main() | |
{ | |
int arr[5][3], max; | |
for(int i = 0; i < 5; i++){ | |
printf("Enter the marks for the student #%d:\n", i+1); | |
for(int j=0; j<3;j++){ | |
printf("Enter the marks in subject#%d: ", j+1); | |
scanf("%d", &arr[i][j]); | |
} | |
} | |
for(int j = 0; j < 3; j++){ | |
max = arr[0][j]; | |
for(int i = 0; i < 5; i++){ | |
if(arr[i][j]> max){ | |
max = arr[i][j]; | |
} | |
} | |
printf("\nHighest marks in subject #1: %d.",max); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment