Posts

Showing posts with the label Maths

C Program to Calculate Sum of Array Elements

Array is a mile stone of C Program which we may use almost everywhere. Here is a basic program to understand array, memory locations and structure of array etc. What is an array? An array is a group of continuous memory locations which we can access by the address. An array of a particular datatype can only store values of that data type(often it convert and use the given data). Array initialization The syntax of array initialization in C is : datatype array_name[size]; Algorithm Here the array named 'array' of type 'int' is used to store different numbers and adding them by separately accessing the array elements using for loop. //Program //Program #include <stdio.h< voide main() {     int n, i;        float num[100], sum = 0.0, average;     printf("Enter the numbers of elements: ");     scanf("%d", &n);     while (n > 100 || n <= 0)     { ...

C Program to Disply Armstrong Number Series

What is an Armstrong number? An Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits. This definition depends on the base b of the number system used, e.g., b  = 10 for the decimal system or b  = 2 for the binary system. (Read more about Armstrong number) For generating Armstrong number series we use the following algorithm. Algorithm A positive integer is called an Armstrong number of order n if abcd... = a n + b n + c n + d n + ...   In case of 3 digit Armstrong numbers the sum of cubes of the digits of the number will be equal to the actual number. Thus we can use a conditional statement to split a number, multiply, add and check with original number.   #include < stdio .h > #include < math .h > int main() { int low, high, i, temp1, temp2, remainder, n = 0, result = 0; printf("Enter two numbers(intervals): "); scanf("%d %d", &low, &high); pri...

C Program to Display Prime Number series

This is a simple program. Here the technique used is to generate prime numbers from one lower limit to one upper limit using loop. For more details refer our previous program : C Program to Check Whether a Number is Prime or Not. //Program #include < stdio.h > int main() {     int low, high, i, flag;     printf("Enter two numbers(intervals): ");     scanf("%d %d", &low, &high);     printf("Prime numbers between %d and %d are: ", low, high);     while (low < high)     {         flag = 0;         for(i = 2; i <= low/2; ++i)         {             if(low % i == 0)             {             ...

C Program to Check Whether a Number is Prime or Not

What is an Armstrong number? An Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits. This definition depends on the base b of the number system used, e.g., b  = 10 for the decimal system or b  = 2 for the binary system. (Read more about Armstrong number) For generating Armstrong number series we use the following algorithm. Algorithm A positive integer is called an Armstrong number of order n if abcd... = a n + b n + c n + d n + ...   In case of 3 digit Armstrong numbers the sum of cubes of the digits of the number will be equal to the actual number. Thus we can use a conditional statement to split a number, multiply, add and check with original number.   #include < stdio .h > #include < math .h > int main() { int low, high, i, temp1, temp2, remainder, n = 0, result = 0; printf("Enter two numbers(intervals): "); scanf("%d %d", &low, &high); pri...