0% found this document useful (0 votes)
2 views3 pages

C Programming

The document contains multiple C programs that perform various tasks such as calculating the sum and average of numbers, finding the largest number in an array, sorting numbers in both descending and ascending order, and converting Fahrenheit to Celsius. Each program prompts the user for input and processes the data accordingly. The code snippets demonstrate fundamental programming concepts including loops, conditionals, and array manipulation.

Uploaded by

kalyanimahanta72
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

C Programming

The document contains multiple C programs that perform various tasks such as calculating the sum and average of numbers, finding the largest number in an array, sorting numbers in both descending and ascending order, and converting Fahrenheit to Celsius. Each program prompts the user for input and processes the data accordingly. The code snippets demonstrate fundamental programming concepts including loops, conditionals, and array manipulation.

Uploaded by

kalyanimahanta72
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

//sum and average of numbers

#include <stdio.h>
int main() {
int n, i;
float num[100], sum , avg;

printf("Enter the numbers of elements: ");


scanf("%d", &n);

while (n > 100 || n < 1) {


printf("Error! number should in range of (1 to 100).\n");
printf("Enter the number again: ");
scanf("%d", &n);
}

for (i = 0; i < n; ++i) {


printf("%d. Enter number: ", i + 1);
scanf("%f", &num[i]);
sum += num[i];
}

avg = sum / n;
printf("Sum = %.2f\n",sum);
printf("Average = %.2f", avg);
return 0;
}

//Print the largest numbers

#include <stdio.h>
int main() {
int n;
double arr[100];
printf("Enter the number of elements (1 to 100): ");
scanf("%d", &n);

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


printf("Enter number%d: ", i + 1);
scanf("%lf", &arr[i]);
}

// storing the largest number to arr[0]


for (int i = 1; i < n; ++i) {
if (arr[0] < arr[i]) {
arr[0] = arr[i];
}
}

printf("Largest element = %.2lf", arr[0]);

return 0;
}
/* sorting of numbers in descending order*/

#include <stdio.h>
int main ()
{
int number[30];
int i, j, a, n;
printf("Enter the number of elements:");
scanf("%d", &n);
for (i = 0; i < n; ++i){
printf("%[Link] the numbers:",i+1);
scanf("%d", &number[i]);
}

/* sorting begins ... */


for (i = 0; i < n; ++i)
{
for (j = i + 1; j < n; ++j)
{
if (number[i] < number[j])
{
a = number[i];
number[i] = number[j];
number[j] = a;
}

}
printf("The numbers arranged in descending order are given
below:");
for (i = 0; i < n; ++i)
{
printf("%d,", number[i]);
}
}

//sorting of numbers in ascending orders

#include <stdio.h>
int main()
{
int i, j, a, n, number[30];
printf("Enter the value of elements:");
scanf("%d", &n);
for (i = 0; i < n; ++i)
{
printf("%[Link] the numbers:",i+1);
scanf("%d", &number[i]);
}
/* sorting begins ... */
for (i = 0; i < n; ++i)
{
for (j = i + 1; j < n; ++j)
{
if (number[i] > number[j])
{
a = number[i];
number[i] = number[j];
number[j] = a;
}
}
}
printf("The numbers arranged in ascending order are given
below:");
for (i = 0; i < n; ++i)
printf("%d,", number[i]);
}

//Fahrenheit to Celsius table

#include <stdio.h>
main()
{
int fahr, celsius;
int lower, upper, step;
lower=0;
upper=100;
step=20;
fahr=lower;

while (fahr<=upper){
celsius=5.0*(fahr-32.0)/9.0;
printf("%3d %6d\n",fahr,celsius);
fahr = fahr + step;
}

You might also like