Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
71 views

Turbo C Example Programs

This document contains code for 3 C programs: 1) A basic if/else program that checks if a number is less than, equal to, or greater than 100. 2) A program to calculate the average of N numbers by inputting numbers, summing them, and dividing the sum by N. 3) A program to find all the factors of a number by using a for loop to check if the number is evenly divisible by integers from 1 to half the number.

Uploaded by

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

Turbo C Example Programs

This document contains code for 3 C programs: 1) A basic if/else program that checks if a number is less than, equal to, or greater than 100. 2) A program to calculate the average of N numbers by inputting numbers, summing them, and dividing the sum by N. 3) A program to find all the factors of a number by using a for loop to check if the number is evenly divisible by integers from 1 to half the number.

Uploaded by

Jenil Fillarca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Basic ifelse condition program:

#include<stdio.h>
int main(){

int number;
printf("Please enter a number:\n");
scanf("%d",&number);
/*
For single statements we can skip the curly brackets
*/
if(number < 100)
printf("Number is less than 100!\n");
else if(number == 100)
printf("Number is 100!\n");
else
printf("Number is greater than 100!\n");
return 0;}

Program to find average of N Numbers


#include<stdio.h>
int main(){
int n, i;
float sum = 0, x;

printf("Enter number of elements: ");


scanf("%d", &n);
printf("\n\n\nEnter %d elements\n\n", n);
for(i = 0; i < n; i++)
{
scanf("%f", &x);
sum += x;
}
printf("\n\n\nAverage of the entered numbers is = %f", (sum/n));
return 0;}
Program to find Factors of a Number
#include<stdio.h>

int main(){
int num, i;
printf("Enter the number to find the factors of : ");
scanf("%d",&num);
printf("\n\n\nFactors of %d are \n\n", num);

for(i = 1; i <= num/2; i++)


{
if(num%i == 0)
printf("\t\t\t%d\n", i);
}

return 0;}

You might also like