 # C Programming Code Examples

## C > Beginners Lab Assignments Code Examples

### Program to Calculate the Sum of Odd & Even Numbers

``` Program to Calculate the Sum of Odd & Even Numbers This is a C program to find the sum of odd and even numbers from 1 to N. - Take the number N upto which we have to find the sum as input. - Using for loop take the elements one by one from 1 to N. - Using if, else statements separate the element as even or odd. - Add the even and odd numbers separately and store it in different variables. - Print the sum separately and exit. #include <stdio.h> void main() { int x, j, odd_sum = 0, even_sum = 0; printf("Enter the value of j\n"); scanf("%d", &j); for (x = 1; x <= j; x++) { if (x % 2 == 0) even_sum = even_sum + x; else odd_sum = odd_sum + x; } printf("Sum of all odd numbers = %d\n", odd_sum); printf("Sum of all even numbers = %d\n", even_sum); } - User must first enter the number upto which he/she wants to find the sum and is stored in the variable j. - Using for loop take the elements one by one from 1 to j. - Use if, else statement for each element to find whether it is odd or even by dividing the element by 2. - Initialize the variables odd_sum and even_sum to zero. - If the element is even,then increment the variable even_sum with the current element. - If the element is odd, then increment the variable odd_sum with the current element. - Print the variables odd_sum and even_sum separately and exit. ```

Check Prime or Armstrong Number Using - In this program, two User-Defined functions checkPrimeNum() & checkArmstrongNum() are created. The checkPrimeNum() returns 1 if the number entered by the user is a Prime

C++ Permute All Letters of an Input String - This algorithm takes the input of a string with all distinct characters 'N' Value. It places each character to every index by Swapping Values. A function to 'swap character' values of string

Find the Number of Integers Divisible by 5 - C Program to which calculates the number of integers divisible by 5 in the given range. This C program takes the range as input and finds the number of integers divisible by 5 in range.

C Search for an Element in the Linked List - Search an element in the linked list without using Recursion. C Program, using iteration, Searches for an Element in a Linked List. A Linked List is ordered set of Data Elements,

Program Code find First Digit of a number - Finding the first digit of any number is little expensive than last digit. To find first digit of a number we divide the given number by 10 until number is greater than 10. At the end...

C++ Programming code Copy File Content - To copy the "content of a file" to the other file in C++ programming, you have to first ask to the user to enter the "source file" to open the source file and ask to enter the target source

Program to Solve a Matching Problem For - Program to solve a matching problem. Given N men and N women, where each person has ranked all members of the opposite gender in order of preference, marry the men & women

Converts Octal Number to Binary Number - To convert octal number to binary number in C++, you have to ask to the user to enter the octal number to convert it to binary number to display the "equivalent value" in binary as