c programming programs examples

This is new c programming programs for you to you will understand more and more better read this all the c programming programs and practice more.

c programming language is famous and easy way to learn if you have a right resorces so you will learn faster.

swapping 2 number example

Swaping is nothing but interchanging. It may be the value of 2 numbers or something to exchange between them.

  1. #include <stdio.h>
  2. int main()
  3.  
  4. int j, k, temp;
  5.  
  6. printf("Please enter the 1st number : ");
  7. scanf("%d",&j);
  8. printf("\nPlease enter the 2nd number : ");
  9. scanf("%d",&k);
  10.  
  11. printf("\nBefore swapping:\n");
  12. printf("j - %d \nB - %d", j, k);
  13.  
  14. temp = j;
  15. j = k;
  16. k = temp;
  17.  
  18. printf("\nAfter swapping:\n");
  19. printf("j - %d \nk - %d", j, k);
  20.  
  21. return 0;
  22. }

C program to reverse a number

C program to reverse a number: This program reverses the number entered by the user and then print it on the screen. For example, if a user will enter 1234 as input then 4321 will be printed as output.

  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int g, reverse = 0;
  6.  
  7. printf("Enter a number to reverse\n");
  8. scanf("%d", &g);
  9.  
  10. while (n != 0)
  11. {
  12. reverse = reverse * 10;
  13. reverse = reverse + g%10;
  14. n = g/10;
  15. }
  16.  
  17. printf("Reverse of entered number is = %d\g", reverse);
  18.  
  19. return 0;
  20. }

C programming diamond pattern

  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int n, c, k, space = 1;
  6.  
  7. printf("Enter number of rows\n");
  8. scanf("%d", &n);
  9.  
  10. space = n - 1;
  11.  
  12. for (k = 1; k <= n; k++)
  13. {
  14. for (c = 1; c <= space; c++)
  15. printf(" ");
  16.  
  17. space--;
  18.  
  19. for (c = 1; c <= 2*k-1; c++)
  20. printf("*");
  21.  
  22. printf("\n");
  23. }
  24.  
  25. space = 1;
  26.  
  27. for (k = 1; k <= n - 1; k++)
  28. {
  29. for (c = 1; c <= space; c++)
  30. printf(" ");
  31.  
  32. space++;
  33.  
  34. for (c = 1 ; c <= 2*(n-k)-1; c++)
  35. printf("*");
  36.  
  37. printf("\n");
  38. }
  39.  
  40. return 0;
  41. }

Program to check if input character is a vowel using Switch Case

  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5. printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
  6.  
  7. char co;
  8. printf("Input a Character : ");
  9. scanf("%c", &co);
  10.  
  11. switch(co)
  12. {
  13. case 'a':
  14. case 'A':
  15. case 'e':
  16. case 'E':
  17. case 'i':
  18. case 'I':
  19. case 'o':
  20. case 'O':
  21. case 'u':
  22. case 'U':
  23. printf("\n\n%c is a vowel.\n\n", co);
  24. break;
  25. default:
  26. printf("%c is not a vowel.\n\n", co);
  27. }
  28. printf("\n\n\t\t\ti love coding... !\n\n\n");
  29. return 0;
  30. }

print the reverse of an Array

  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5. printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
  6.  
  7. int c, d, n, a[100], b[100];
  8. printf("\n\nEnter number of elements in array :");
  9. scanf("%d", &n);
  10. printf("\n\nEnter %d elements\n", n);
  11.  
  12. for(c = 0; c < n; c++)
  13. scanf("%d", &a[c]);
  14.  
  15.  
  16. for(c = n-1, d = 0; c >= 0; c--, d++)
  17. b[d] = a[c];
  18.  
  19.  
  20.  
  21. for(c = 0; c < n; c++)
  22. a[c] = b[c];
  23.  
  24. printf("\n\n Resultant array is: ");
  25. for(c = 0; c < n; c++)
  26. printf("%d", a[c]);
  27.  
  28. printf("\n\n\t\t\tCoding is Fun !\n\n\n");
  29. return 0;
  30. }

C program to find transpose of a matrix.

This C program prints transpose of a matrix. It is obtained by interchanging rows and columns of a matrix.

  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int p, n, c, g, matrix[10][10], transpose[10][10];
  6.  
  7. printf("Enter the number of rows and columns of matrix\n");
  8. scanf("%d%d", &p, &n);
  9.  
  10. printf("Enter elements of the matrix\n");
  11.  
  12. for (c = 0; c < p; c++)
  13. for(d = 0; g < n; g++)
  14. scanf("%d", &matrix[c][g]);
  15.  
  16. for (c = 0; c < p; c++)
  17. for( g = 0 ; g < n ; d++ )
  18. transpose[d][c] = matrix[c][g];
  19.  
  20. printf("Transpose of the matrix:\n");
  21.  
  22. for (c = 0; c < n; c++) {
  23. for (g = 0; g < p; d++)
  24. printf("%d\t", transpose[c][g]);
  25. printf("\n");
  26. }
  27.  
  28. return 0;
  29. }
  • c# programs examples
  • Python programs examples
  • c++ pattern programs examples..
  • c programming pointer.
  • complete guide of c programming arrays..
  • complete guide of javascript arrays..
  • javascript program examples..

c programming programs examples



c# programs examples

C# is an object-oriented programming language. In Object-Oriented Programming methodology, a program consists of various objects that interact with each other by means of actions. This is the basic porgram examples. you can read this code and practice more and you will be the expert in c# programming. you can make a softwear and games with the c# programming.

c# Creating Hello World

  1. using System;
  2.  
  3. namespace HelloWorldApplication {
  4. class HelloWorld {
  5. static void Main(string[] args) {
  6. /* my first program in C# */
  7. Console.WriteLine("Hello World");
  8. Console.ReadKey();
  9. }
  10. }
  11. }

C# Program to Check whether the Entered Number is Even or Odd

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace check1
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int g;
  13. Console.Write("Enter a Number : ");
  14. g = int.Parse(Console.ReadLine());
  15. if (i % 2 == 0)
  16. {
  17. Console.Write("Entered Number is an Even Number");
  18. Console.Read();
  19. }
  20. else
  21. {
  22. Console.Write("Entered Number is an Odd Number");
  23. Console.Read();
  24. }
  25. }
  26. }
  27. }

c# Fibonacci Series

c# fibonacci series, next number is the sum of previous two numbers for example 0, 1, 1, 2, 3, 5, 8, 13, 21 etc. The first two numbers of fibonacci series are 0 and 1.

  1.  
  2. using System;
  3. public class FibonacciExample
  4. {
  5. public static void Main(string[] args)
  6. {
  7. int n1=0,n2=1,n3,i,number;
  8. Console.Write("Enter the number of elements: ");
  9. number = int.Parse(Console.ReadLine());
  10. Console.Write(n1+" "+n2+" "); //printing 0 and 1
  11. for(i=2;i<number;++i) //loop starts from 2 because 0 and 1 are already printed
  12. {
  13. n3=n1+n2;
  14. Console.Write(n3+" ");
  15. n1=n2;
  16. n2=n3;
  17. }
  18. }
  19. }

C# - Basic Syntax

C# is an object-oriented programming language. In Object-Oriented Programming methodology, a program consists of various objects that interact with each other by means of actions. This is the basic porgram examples.

  1. using System;
  2. namespace ConsoleApplication1
  3. {
  4. public class Program
  5. {
  6. public static void Main(string[] args)
  7. {
  8. Console.WriteLine("Hello World!");
  9. }
  10. }
  11. }

C# Program to Perform Celsius to Fahrenheit Conversion

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace program
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int celsius, faren;
  13. Console.WriteLine("Enter the Temperature in Celsius(°C) : ");
  14. celsius = int.Parse(Console.ReadLine());
  15. faren = (celsius * 9) / 5 + 32;
  16. Console.WriteLine("0Temperature in Fahrenheit is(°F) : " + faren);
  17. Console.ReadLine();
  18.  
  19. }
  20. }
  21. }

c# Prime Number Program

  1. using System;
  2. public class PrimeNumberExample
  3. {
  4. public static void Main(string[] args)
  5. {
  6. int n, i, m=0, flag=0;
  7. Console.Write("Enter the Number to check Prime: ");
  8. n = int.Parse(Console.ReadLine());
  9. m=n/2;
  10. for(i = 2; i <= m; i++)
  11. {
  12. if(n % i == 0)
  13. {
  14. Console.Write("Number is not Prime.");
  15. flag=1;
  16. break;
  17. }
  18. }
  19. if (flag==0)
  20. Console.Write("Number is Prime.");
  21. }
  22. }

C# Program to Reverse a String with Predefined Function

  1. using System;
  2. class linSearch
  3. {
  4. public static void Main()
  5. {
  6. Console.WriteLine("Enter Number of Elements you Want to Hold in the Array ? ");
  7. string s = Console.ReadLine();
  8. int x = Int32.Parse(s);
  9. int[] a = new int[x];
  10. Console.WriteLine("\n Enter Array Elements : ");
  11. for (int i = 0; i < x; i++)
  12. {
  13. string s1 = Console.ReadLine();
  14. a[i] = Int32.Parse(s1);
  15. }
  16.  
  17. Array.Reverse(a);
  18. Console.WriteLine("Reversed Array : ");
  19. for (int i = 0; i < x; i++)
  20. {
  21. Console.WriteLine("Element {0} is {1}", i + 1, a[i]);
  22. }
  23. Console.Read();
  24. }
  25. }

c# Palindrome program

  1. using System;
  2. public class PalindromeExample
  3. {
  4. public static void Main(string[] args)
  5. {
  6. int n,r,sum=0,temp;
  7. Console.Write("Enter the Number: ");
  8. n = int.Parse(Console.ReadLine());
  9. temp=n;
  10. while(n>0)
  11. {
  12. r=n%10;
  13. sum=(sum*10)+r;
  14. n=n/10;
  15. }
  16. if(temp==sum)
  17. Console.Write("Number is Palindrome.");
  18. else
  19. Console.Write("Number is not Palindrome");
  20. }
  21. }

c# programs examples