C Program To Reverse An Array

C Program To Reverse An Array. If you are looking for C Program for Reverse Array, here in this tutorial we will help you to learn how to write a C program to reverse an array elements.

C Program To Reverse An Array

Learn how to write a C program to reverse an array. Writing a C reverse array program can be done using various techniques but here in this program, we show how to write a program to reverse an array logic in a proper way.

Reversing An Array Elements Example

These are some examples of reversing array elements.

Input : arr[] = {11, 12, 13}
Output : arr[] = {13, 12, 11}

Input : arr[] = {41, 51, 11, 21}
Output : arr[] = {21, 11, 51, 41}

C Program To Reverse An Array Source Code

Find the below source code to reverse an array and how to write c program to reverse an array using while loop.

/* C Proram to reverse an array using while loop - ReverseArray.C */

#include<stdio.h>

int main() {
//variable declaration
 int arr[30], i, j, num, temp;
//asking user to enter size of an array elements
printf("\nEnter no of elements : ");
 scanf("%d", &num);

//Reading elements in an array
 for (i = 0; i < num; i++) {
 scanf("%d", &arr[i]);
 }

j = i - 1; // j will Point to last element of an array
 i = 0; // i will be pointing to first element of ann array

while (i < j) {
 temp = arr[i];
 arr[i] = arr[j];
 arr[j] = temp;
 i++; // increment i
 j--; // decrement j
 }

//Printing output of an array elements in a reverse order
 printf("\nThe result after reversing of an array : ");
 for (i = 0; i < num; i++) {
 printf("%d \t", arr[i]);
 }

return (0);
}

C Program To Reverse An Array Output

Enter no of elements : 3

41     51     11     21

The result after reversing of an array

21     11     51     41

C PROGRAMMING TUTORIALS

  1. C Program For Pascal Triangle
  2. C Program to Print Prime Numbers from 1 to 100
  3. C Program to Find LCM and GCD of Two Numbers
  4. C Program to Add Spaces in a String
  5. C Program To Add Digits Of A Number
  6. C Program To Find Leap Year
  7. C Program To Append Data Into A File
  8. C Program to Accept Only Integer Values
  9. C Program To Arrange Numbers In Descending Order
  10. C Program to Add Days to Date
  11. C Program to Add Two Fractions
  12. C Program To Reverse A Number
  13. C Program to Find Maximum and Minimum Numbers
  14. C Program to Read a Text File
  15. C Program to Convert Decimal to Hexadecimal
  16. C Program to Convert Decimal to Binary
  17. C Program to Convert Celsius to Fahrenheit
  18. C Program To Find Absolute Value
  19. Ternary Operator Program in C
  20. C Program For Addition Table Using For Loop

C Program To Print Pascal Triangle

C Program To Print Pascal Triangle. If you are looking for C Program for Pascal Triangle, here in this tutorial we will help you to learn how to write a C program to display Pascal triangle.

C Program to Print Pascal Triangle

Learn how to write a C program to print Pascal Triangle. Writing a Pascal Triangle C program can be done using various techniques but here in this program, we show how to write a pascal triangle logic in a proper way.

Pascal Triangle Example

           1
         1   1
       1   2   1
     1   3   3    1
   1  4    6   4   1
 1  5   10   10  5   1 

C Program to Print Pascal Triangle Source Code

/* C Program to print pascal traiangle - PascalTriangle.C */

#include <stdio.h>
int main()
{
//variable declaration
 int rows, coef = 1, space, i, j;

//asking user to enter number of rows and reading
printf("Enter number of rows: ");
 scanf("%d",&rows);

//logic for printing pascal triangle
for(i=0; i<rows; i++)
 {
 for(space=1; space <= rows-i; space++)
 printf(" ");

for(j=0; j <= i; j++)
 {
 if (j==0 || i==0)
 coef = 1;
 else
 coef = coef*(i-j+1)/j;

printf("%4d", coef);
 }
 printf("\n");
 }

return 0;
}

C Program to Print Pascal Triangle Output

Enter number of rows: 6


           1
         1   1
       1   2   1
     1   3   3    1
   1  4    6   4   1
 1  5   10   10  5   1 

C PROGRAMMING TUTORIALS

  1. C Program to Print Prime Numbers from 1 to 100
  2. C Program to Find LCM and GCD of Two Numbers
  3. C Program to Add Spaces in a String
  4. C Program To Add Digits Of A Number
  5. C Program To Find Leap Year
  6. C Program To Append Data Into A File
  7. C Program to Accept Only Integer Values
  8. C Program To Arrange Numbers In Descending Order
  9. C Program to Add Days to Date
  10. C Program to Add Two Fractions
  11. C Program To Reverse A Number
  12. C Program to Find Maximum and Minimum Numbers
  13. C Program to Read a Text File
  14. C Program to Convert Decimal to Hexadecimal
  15. C Program to Convert Decimal to Binary
  16. C Program to Convert Celsius to Fahrenheit
  17. C Program To Find Absolute Value
  18. Ternary Operator Program in C
  19. C Program For Addition Table Using For Loop
  20. Denomination Program in C

C Program To Print Prime Numbers From 1 To 100

C program to print prime numbers from 1 to 100. If you are looking for C program to find prime numbers, here in this tutorial we will help you to learn how to write a C program for prime numbers.

C Program to Print Prime Numbers

Learn how to write a C program to print all Prime numbers between 1 to 100. Writing a C program to display prime numbers between two intervals can be done using various techniques but here in this program, we show how to write a C program to print prime numbers from 1 to 100 in a proper way.

C Program to Print Prime Numbers Source Code

/* C Program to print prime numbers from 1 to 100 - PrimeNumbers.C */

#include <stdio.h>
#include <stdlib.h>
 
void main()
{
//variable declaration
 int num1, num2, i, j, flag, temp, count = 0;
 
//asking user to enter lower and upper limit numbers and reading
 printf("Enter the value of num1 and num2 \n");
 scanf("%d %d", &num1, &num2);
//logic to finding and printing prime numbers from 1 to 100
 if (num2 < 2)
 {
   printf("There are no primes upto %d\n", num2);
   exit(0);
 }
 
 printf("Prime numbers are \n");
 temp = num1;
 
 if ( num1 % 2 == 0)
 {
   num1++;
 }
 
 for (i = num1; i <= num2; i = i + 2)
 {
 flag = 0;
 for (j = 2; j <= i / 2; j++)
 {
 if ((i % j) == 0)
 {
 flag = 1;
 break;
 }
 }
 if (flag == 0)
 {
 printf("%d\n", i);
 count++;
 }
 }
 printf("Number of primes between %d & %d = %d\n", temp, num2, count);
}

C Program to Print Prime Numbers Output

Enter the value of num1 and num2

1

100

Prime numbers are

2     3    5     7    11    13    17    19     23      29

31      37      41      43      47      53      59      61

67      71     73      79      83      89      97

Number of primes between 1 & 100 = 25

C PROGRAMMING TUTORIALS

  1. C Program to Find LCM and GCD of Two Numbers
  2. C Program to Add Spaces in a String
  3. C Program To Add Digits Of A Number
  4. C Program To Find Leap Year
  5. C Program To Append Data Into A File
  6. C Program to Accept Only Integer Values
  7. C Program To Arrange Numbers In Descending Order
  8. C Program to Add Days to Date
  9. C Program to Add Two Fractions
  10. C Program To Reverse A Number
  11. C Program to Find Maximum and Minimum Numbers
  12. C Program to Read a Text File
  13. C Program to Convert Decimal to Hexadecimal
  14. C Program to Convert Decimal to Binary
  15. C Program to Convert Celsius to Fahrenheit
  16. C Program To Find Absolute Value
  17. Ternary Operator Program in C
  18. C Program For Addition Table Using For Loop
  19. Denomination Program in C
  20. C Program to Print Multiplication Table 

C Program To Find LCM GCD Of Two Numbers

C Program To Find LCM GCD Of Two Numbers. If you are looking for C program to calculate LCM and GCD of two numbers, here in this tutorial we will help you to learn how to write a program to find LCM in C language.

C Program to Find LCM and GCD

Learn how to write a C program to find LCM. Writing C Program to finding GCD of a number can be done using various techniques but here in this program, we show how to write a C program to find LCM GCD of two numbers in a proper way.

C Program to Find LCM and GCD of Two Numbers Source Code

/* C program to find the LCM and GCD of two numbers - LcmGcd.C */

 #include <stdio.h>

void main()
 {
//variable declaration
 int num1, num2, gcd, lcm, remainder, numerator, denominator;

//asking user to enter two numbers and reading them
printf("Enter two numbers\n");
 scanf("%d %d", &num1, &num2);

//checking for bigger number
 if (num1 > num2)
 {
 numerator = num1;
 denominator = num2;
 }
 else
 {
 numerator = num2;
 denominator = num1;
 }

//calculating remainder
 remainder = numerator % denominator;

//logic to find gcd and lcm of two numbers
 while (remainder != 0)
 {
 numerator = denominator;
 denominator = remainder;
 remainder = numerator % denominator;
 }

//finding lcm and gcd of two numbers
 gcd = denominator;
 lcm = num1 * num2 / gcd;

//printing lcm and gcd of two numbers
 printf("GCD of %d and %d = %d\n", num1, num2, gcd);
 printf("LCM of %d and %d = %d\n", num1, num2, lcm);
 }

C Program to Find LCM and GCD of Two Numbers Output

Enter two numbers

65

30

GCD of 65 and 30 = 5

LCM of 65 and 30 = 390

C PROGRAMMING TUTORIALS

  1. C Program to Add Spaces in a String
  2. C Program To Add Digits Of A Number
  3. C Program To Find Leap Year
  4. C Program To Append Data Into A File
  5. C Program to Accept Only Integer Values
  6. C Program To Arrange Numbers In Descending Order
  7. C Program to Add Days to Date
  8. C Program to Add Two Fractions
  9. C Program To Reverse A Number
  10. C Program to Find Maximum and Minimum Numbers
  11. C Program to Read a Text File
  12. C Program to Convert Decimal to Hexadecimal
  13. C Program to Convert Decimal to Binary
  14. C Program to Convert Celsius to Fahrenheit
  15. C Program To Find Absolute Value
  16. Ternary Operator Program in C
  17. C Program For Addition Table Using For Loop
  18. Denomination Program in C
  19. C Program to Print Multiplication Table 
  20. C Program Array with Example

C Program To Print Hello World

C Program To Print Hello World. If you are looking for writing your first C program to Hello World, here in this tutorial we will help you to learn how to write a program to display Hello World in C language.

C Program To Print Hellow World

/* C program to print hello world - HelloWorld.C */

#include <stdio.h>
void main()
{
  printf("Hello World.!");
}

C Program To Print Hellow World Output

Hello World.!

C PROGRAMMING TUTORIALS

  1. C Program to Find Area of a Circle
  2. C Program to Add Spaces in a String
  3. C Program To Add Digits Of A Number
  4. C Program To Find Leap Year
  5. C Program To Append Data Into A File
  6. C Program to Accept Only Integer Values
  7. C Program To Arrange Numbers In Descending Order
  8. C Program to Add Days to Date
  9. C Program to Add Two Fractions
  10. C Program To Reverse A Number
  11. C Program to Find Maximum and Minimum Numbers
  12. C Program to Read a Text File
  13. C Program to Convert Decimal to Hexadecimal
  14. C Program to Convert Decimal to Binary
  15. C Program to Convert Celsius to Fahrenheit
  16. C Program To Find Absolute Value
  17. Ternary Operator Program in C
  18. C Program For Addition Table Using For Loop
  19. Denomination Program in C
  20. C Program to Print Multiplication Table 

C Program To Find Area Of A Circle

C Program To Find Area Of A Circle. If you are looking for C program to calculate area of a circle, here in this tutorial we will help you to learn how to write a program to find area of a circle in C language.

C Program to Find Area of a Circle

Learn how to write a C program to find area of a circle. Writing C Program to finding area of circle can be done using various techniques but here in this program, we show how to write a C program to calculate area of a circle in a proper way.

C Program to Calculate Area of a Circle Source Code

/* C program to calculate area of a circle - AreaOfCircle.C */
#include <stdio.h>
#include <math.h>
#define PI 3.142
 
void main()
{
 //variable declaration
 float radius, area; 
 //asking user to enter the radius of a circle
 printf("Enter the radius of a circle \n");
 //reading user entered radius value to calculate area
 scanf("%f", &radius);
 //logic to find area of a cirlce
 area = PI * pow(radius, 2); //area of a circle formula
 //printing area of a cirlce
 printf("Area of a circle = %5.2f\n", area);
}

C Program to Find Area of a Circle Source Code

/* C program to find area of a circle - AreaOfCircle.C */

#include<stdio.h>
 
int main() 
{
 //variables declaration
 float radius, area;
 //Taking input from user and reading it
 printf("\nEnter the radius of Circle : ");
 scanf("%d", &radius);
 //formula to find area of a circle
 area = 3.14 * radius * radius;
//printing area of a circle
 printf("\nArea of a Circle is: %f", area);
 
 return (0);
}

C Program to Find Area of a Circle Output

Enter the radius of Circle : 15

Area of a Circle is: 706.5

C PROGRAMMING tutorials

  1. C Program to Add Spaces in a String
  2. C Program To Add Digits Of A Number
  3. C Program To Find Leap Year
  4. C Program To Append Data Into A File
  5. C Program to Accept Only Integer Values
  6. C Program To Arrange Numbers In Descending Order
  7. C Program to Add Days to Date
  8. C Program to Add Two Fractions
  9. C Program To Reverse A Number
  10. C Program to Find Maximum and Minimum Numbers
  11. C Program to Read a Text File
  12. C Program to Convert Decimal to Hexadecimal
  13. C Program to Convert Decimal to Binary
  14. C Program to Convert Celsius to Fahrenheit
  15. C Program To Find Absolute Value
  16. Ternary Operator Program in C
  17. C Program For Addition Table Using For Loop
  18. Denomination Program in C
  19. C Program to Print Multiplication Table 
  20. C Program Array with Example

 

C Program To Add Spaces In A String

C Program To Add Spaces In A String. If you are looking for C program to add space to a string, here in this tutorial we will help you to learn how to write a C program to add space to a string.

C Program to Add Spaces in a String

Learn how to write a C program to add spaces in a string. Writing C Program to add space to a string can be done using various techniques but here in this program, we show how to write a C program to adding spaces in a string in a proper way.

C Program to Add Spaces in a String Source Code

/* C Program to add spaces in a string - AddSpacesInString.C */
#include <iostream>
//#include <iomanip>
#include <cctype>
#include <string>

using namespace std;

//void fixPuct(string);
void fixPuct(string&);



int main()
{
 //char *statement; // don't mix C strings with C++
 //statement = new char [60];
 cout << "Enter a statement with Caps at start of each new word ..." << endl;
 // Enter a statement with Caps at start of each new word ...

string statement; // construct an empty C++ string
 if( getline(cin, statement) )
 //if (statement != NULL)
 {
 //cout << "Enter a statement: ";
 //cin. getline(statement, 60);// see above re. using C++ strings with C++
 //getline( cin statement ); // see above re. using C++ strings with C++
 cout << "You entered " << '"' << statement << '"' << endl;

fixPuct(statement);
 cout << "Here it is fixed ...\n"
 << statement << endl;
 //delete [] statement;
 }
 
 cout << "\nPress 'Enter' to continue/exit ... " << flush;
 getline( cin, statement );
}



//void fixPuct(string s)
void fixPuct(string& s) // Note: NEED to pass in by reference so calling string gets updated ...
{
 int size = s.size();
 if(size)
 {
 string nLine(1, s[0]);
 for( int i=1; i<size; i++ )
 {
 if( isupper(s[i]) )
 {
 if( i > 0 && !isspace(s[i-1]) ) nLine += ' ';
 nLine += tolower(s[i]);
 }
 else nLine += s[i];
 }
 s = nLine;
 }
}

C Program to Add Spaces in a String Output

Enter a statement with Caps at start of each new word …

TheBig BrownBear sat OnTheLittleBlueBox.

Here it is fixed …

The big brown bear sat on the little blue box.

Press ‘Enter’ to continue/exit …

C PROGRAMMING EXAMPLES

  1. C Program To Add Digits Of A Number
  2. C Program To Find Leap Year
  3. C Program To Append Data Into A File
  4. C Program to Accept Only Integer Values
  5. C Program To Arrange Numbers In Descending Order
  6. C Program to Add Days to Date
  7. C Program to Add Two Fractions
  8. C Program To Reverse A Number
  9. C Program to Find Maximum and Minimum Numbers
  10. C Program to Read a Text File
  11. C Program to Convert Decimal to Hexadecimal
  12. C Program to Convert Decimal to Binary
  13. C Program to Convert Celsius to Fahrenheit
  14. C Program To Find Absolute Value
  15. Ternary Operator Program in C
  16. C Program For Addition Table Using For Loop
  17. Denomination Program in C
  18. C Program to Print Multiplication Table 
  19. C Program Array with Example
  20. Binary Search in C Program Using Recursion

C Program To Add Digits Of A Number

C Program To Add Digits Of A Number.  If you are looking find sum of the digits of a number program in C, here in this tutorial we will help you to learn how to write a C program to compute sum of digits in a given number.

C Program to Add Digits of a Number

Learn how to write a C program to find sum of digits of a number. Writing C Program to add digits of a given number can be done using various techniques but here in this program, we show how to write a C program to find sum of digits of a number using while loop in a proper way.

How do you find the sum of digits in C?

If a user enters a number 1234, then we have to write a logic to calculate sum of the digits of 1234. That is 1 + 2 + 3 + 4 = 10. The program should read the individual digits and then it should add digits and print sum of the digits in a given number.

C Program to Compute Digits of a Number Source Code

Just copy paste the below source code to find sum of the digits of a number in C compiler to test, how the source code works. Happy Learning.

/* C program to add digits of a number - AddDigits.C */

#include <stdio.h>
 
void main()
{
 long num, temp, digit, sum = 0;
 
 printf("Enter the number to find sum of the digits: \n");
 scanf("%ld", &num);
 temp = num;
 while (num > 0)
 {
  digit = num % 10;
  sum = sum + digit;
  num /= 10;
 }
 printf("Given number is = %ld\n", temp);
 printf("Sum of the digits of %ld = %ld\n", temp, sum);
}

C Program to Find Sum of Digits of a Number Output

Run the above program to add digits of a given number to print sum of digits. For this enter a number to check, the c compiler will execute the logic and display the sum of the digits of a number.

Output:

Enter the number to find sum of the digits: 1234

Given number is = 1234

Sum of the digits of 1234 = 10

C PROGRAMMING EXAMPLES

  1. C Program To Find Leap Year
  2. C Program To Append Data Into A File
  3. C Program to Accept Only Integer Values
  4. C Program To Arrange Numbers In Descending Order
  5. C Program to Add Days to Date
  6. C Program to Add Two Fractions
  7. C Program To Reverse A Number
  8. C Program to Find Maximum and Minimum Numbers
  9. C Program to Read a Text File
  10. C Program to Convert Decimal to Hexadecimal
  11. C Program to Convert Decimal to Binary
  12. C Program to Convert Celsius to Fahrenheit
  13. C Program To Find Absolute Value
  14. Ternary Operator Program in C
  15. C Program For Addition Table Using For Loop
  16. Denomination Program in C
  17. C Program to Print Multiplication Table 
  18. C Program Array with Example
  19. Binary Search in C Program Using Recursion
  20. Bubble Sort in C Using Pointers

 

C Program To Find Leap Year

C Program To Find Leap Year. If you are looking for checking leap year program in C, here in this tutorial we will help you to learn how to write a C program to check if a given year is leap year.

C Program To Find Leap Year

Learn how to write a C program to find leap year. Writing C Program to check if a given year is leap year can be done using various techniques but here in this program, we show how to write a C program to find if a given year is a leap year in a proper way.

C Program to Check Leap Year Source Code

Just copy paste the below source code to check whether a given year is leap or not in C compiler to test, how the source code works. Happy Learning.

/* C Program to Find Leap Year - LeapYear.C */

#include <stdio.h>
void main()
{
 int year; //variable declaration
 
 printf("Enter a year \n");
 scanf("%d", &year);
 
 //checking whether a year is leap year or not
 if ((year % 400) == 0)
 printf("%d is a leap year \n", year);

 else if ((year % 100) == 0)
 printf("%d is a not leap year \n", year);

 else if ((year % 4) == 0)
 printf("%d is a leap year \n", year);

 else
 printf("%d is not a leap year \n", year);
}

Checking Leap Year Using C Program Output

Run the above leap year program to check if a given year is leap year or not. For this enter a year to check, the c compiler will execute the logic and display whether the enteted year is leap year or not.

Output:

Enter a year
2020
2020 is a leap year

Enter a year
2017
2017 is not a leap year

C PROGRAMMING EXAMPLES

  1. C Program To Append Data Into A File
  2. C Program to Accept Only Integer Values
  3. C Program To Arrange Numbers In Descending Order
  4. C Program to Add Days to Date
  5. C Program to Add Two Fractions
  6. C Program To Reverse A Number
  7. C Program to Find Maximum and Minimum Numbers
  8. C Program to Read a Text File
  9. C Program to Convert Decimal to Hexadecimal
  10. C Program to Convert Decimal to Binary
  11. C Program to Convert Celsius to Fahrenheit
  12. C Program To Find Absolute Value
  13. Ternary Operator Program in C
  14. C Program For Addition Table Using For Loop
  15. Denomination Program in C
  16. C Program to Print Multiplication Table 
  17. C Program Array with Example
  18. Binary Search in C Program Using Recursion
  19. Bubble Sort in C Using Pointers
  20. Bubble Sort Program in C Using Recursion

C Program To Append Data Into A File

C Program To Append Data Into A File. If you are looking for append data into text file program in C, here in this tutorial we will help you to learn how to write a C program to append data into a text file.

C Program To Append Data Into A File

Learn how to write a C program to append data into a file. Writing appending data program in C can be done using various techniques but here in this program, we show how to write a c program to append data into a file in a proper way. Happy coding.

C Program to Append Data Into a File Source Code

Just copy paste the below source code to append data into a text file in C compiler to test, how the source code works. Happy Learning.

/* C Program to Append Data into a File - AppendFile.C */

#include <stdio.h>
#include <stdlib.h>
 
int main()
{
 FILE *fsring1, *fsring2, *ftemp;
 char ch, file1[20], file2[20], file3[20];
 
 printf("Enter name of first file ");
 gets(file1);

 printf("Enter name of second file ");
 gets(file2);

 printf("Enter name to store merged file ");
 gets(file3);

 fsring1 = fopen(file1, "r");
 fsring2 = fopen(file2, "r");

 if (fsring1 == NULL || fsring2 == NULL)
 {
   perror("Error has occured");
   printf("Press any key to exit...\n");
   exit(EXIT_FAILURE);
 }
 
 ftemp = fopen(file3, "w");
 if (ftemp == NULL)
 {
   perror("Error has occures");
   printf("Press any key to exit...\n");
   exit(EXIT_FAILURE);
 }
 while ((ch = fgetc(fsring1)) != EOF)
 fputc(ch, ftemp);

 while ((ch = fgetc(fsring2) ) != EOF)
 fputc(ch, ftemp);

 printf("Two files merged %s successfully.\n", file3);
 fclose(fsring1);
 fclose(fsring2);
 fclose(ftemp);
 return 0;
}

C PROGRAMMING EXAMPLES

  1. C Program to Accept Only Integer Values
  2. C Program To Arrange Numbers In Descending Order
  3. C Program to Add Days to Date
  4. C Program to Add Two Fractions
  5. C Program To Reverse A Number
  6. C Program to Find Maximum and Minimum Numbers
  7. C Program to Read a Text File
  8. C Program to Convert Decimal to Hexadecimal
  9. C Program to Convert Decimal to Binary
  10. C Program to Convert Celsius to Fahrenheit
  11. C Program To Find Absolute Value
  12. Ternary Operator Program in C
  13. C Program For Addition Table Using For Loop
  14. Denomination Program in C
  15. C Program to Print Multiplication Table 
  16. C Program Array with Example
  17. Binary Search in C Program Using Recursion
  18. Bubble Sort in C Using Pointers
  19. Bubble Sort Program in C Using Recursion
  20. Bubble Sort Program in C Using Array