Untitled
unknown
plain_text
4 years ago
2.2 kB
11
Indexable
#include <stdio.h>
int findSum(int n)
{
if (n % 2 == 0)
return (n/2) * (n+1);
else
return ((n+1)/2)*n;
}
int main()
{
int n;
printf("Please Enter Value of N \n ");
scanf("%d",&n);
printf("Sum of N natural numbers: %d",findSum(n));
return 0;
}
#include <stdio.h>
int evenSum(int n)
{
return (n * (n + 1));
}
int main()
{
int n;
printf("Please Enter Value of N \n ");
scanf("%d",&n);
printf("Sum of first %d Even numbers is: %d",n,evenSum(n));
return 0;
}
#include <stdio.h>
int oddSum(int n)
{
return (n * n);
}
int main()
{
int n;
printf("Please Enter Value of N \n ");
scanf("%d",&n);
printf("Sum of first %d Odd numbers is: %d",n,oddSum(n));
return 0;
}
#include <stdio.h>
#include <math.h>
int main() {
float a, b, c;
float root1, root2, imaginary;
float discriminant;
printf("Enter values of a, b, c of quadratic equation (aX^2 + bX + c): ");
scanf("%f%f%f", &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("Two distinct and real roots exists: %.2f and %.2f", root1, root2);
}
else
if (discriminant == 0) {
root1 = root2 = -b / (2 * a);
printf("Two equal and real roots exists: %.2f and %.2f", root1, root2);
}
else if (discriminant < 0) {
root1 = root2 = -b / (2 * a);
imaginary = sqrt(-discriminant) / (2 * a);
printf("Two distinct complex roots exists: %.2f + i%.2f and %.2f - i%.2f", root1, imaginary, root2,
imaginary);
}
return 0;
}
#include<stdio.h>
int main()
{
int n,i; float c,big;
printf("\nEnter the number of elements you wish to find the greatest element of: ");
scanf("%d", &n);
printf("\nEnter %d numbers :\n", n);
printf("\tElement 1: "); scanf("%f", &big);
for(i = 2; i <= n; i++)
{
printf("\tElement %d : ", i); scanf("%f", &c);
if(big < c)
big = c;
}
printf("\nThe largest of the %d numbers is %f ", n, big);
return 0;
}
Editor is loading...