Sep 30, 2011

C Program to mask password text with *

C Program to mask password text with *. This program is to illustrate how user authentication is made before allowing the user to access the secured resources. It asks for the user name and then the password. The password that you enter will not be displayed, instead that character is replaced by '*'. Read more about C Programming Language .


/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                        Happy Coding
***********************************************************/

#include <stdio.h>
#include <conio.h>

void main()
{
 char pasword[10],usrname[10], ch;
 int i;

 clrscr();

 printf("Enter User name: ");
 gets(usrname);
 printf("Enter the password <any 8 characters>: ");

 for(i=0;i<8;i++)
 {
  ch = getch();
  pasword[i] = ch;
  ch = '*' ;
  printf("%c",ch);
 }

 pasword[i] = '\0';

 /*If you want to know what you have entered as password, you can print it*/
 printf("\nYour password is :");

 for(i=0;i<8;i++)
 {
  printf("%c",pasword[i]);
 }
}
Read more Similar C Programs
Searching in C

C Strings

You can easily select the code by double clicking on the code area above.



To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C Program: Insert into an array

Arrays in C
Write a C program to insert a particular element in a specified position in a given array.Read more about C Programming Language .


/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                          Happy Coding
***********************************************************/

                                                        */

#include <stdio.h>
#include <conio.h>

void main()
{
 int  x[10];
 int  i, j, n, m, temp, key, pos;

 clrscr();

 printf("Enter how many elements\n");
 scanf("%d", &n);

 printf("Enter the elements\n");
 for(i=0; i<n; i++)
 {
  scanf("%d", &x[i]);
 }

 printf("Input array elements are\n");
 for(i=0; i<n; i++)
 {
  printf("%d\n", x[i]);
 }

 for(i=0; i< n; i++)
 {
  for(j=i+1; j<n; j++)
  {
   if (x[i] > x[j])
   {
    temp = x[i];
    x[i] = x[j];
    x[j] = temp;
   }
  }
 }

 printf("Sorted list is\n");
 for(i=0; i<n; i++)
 {
  printf("%d\n", x[i]);
 }

 printf("Enter the element to be inserted\n");
 scanf("%d",&key);

 for(i=0; i<n; i++)
 {
  if ( key < x[i] )
  {
   pos = i;
   break;
  }
 }

 m = n - pos + 1 ;

 for(i=0; i<= m ; i++)
 {
  x[n-i+2] = x[n-i+1] ;
 }

 x[pos] = key;

 printf("Final list is\n");
 for(i=0; i<n+1; i++)
 {
  printf("%d\n", x[i]);
 }
}           /* End of main() */
Read more Similar C Programs
Array In C

Simple C Programs
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C Program: Array Summation Using Pointers

Arrays in C.
Write a C program to read N integers and store them in an array A, and so find the sum of all these elements using pointer. Output the given array and and the computed sum with suitable heading. Read more about C Programming Language .
/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                       Happy Coding
***********************************************************/

    

#include <stdio.h>
#include <conio.h>
#include <malloc.h>

void main()
{
 int i,n,sum=0;
 int *a;

 clrscr();

 printf("Enter the size of array A\n");
 scanf("%d", &n);

 a=(int *) malloc(n*sizeof(int));   /*Dynamix Memory Allocation */

 printf("Enter Elements of First List\n");
 for(i=0;i<n;i++)
 {
  scanf("%d",a+i);
 }

 /*Compute the sum of all elements in the given array*/
 for(i=0;i<n;i++)
 {
  sum = sum + *(a+i);
 }

 printf("Sum of all elements in array = %d\n", sum);

}     /* End of main() */
Read more Similar C Programs
Array In C

Simple C Programs

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed! and the computed sum with suitable heading. Read more about C Programming Language .

C program: Sum Of Elements In A Matrix

Write a C program to read a matrix A (MxN) and to find the following using functions
a) Sum of the elements of each row
b) Sum of the elements of each column
c) Find the sum of all the elements of the matrix
Output the computed results with suitable headings.
Read more about C Programming Language .
/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                   Happy Coding
***********************************************************/


#include <stdio.h>
#include <conio.h>

void main()
{
 int arr[10][10];
 int i, j, row, col, rowsum, colsum,sumall=0;

 /* Function declaration */
 int Addrow(int A[10][10], int k, int c);
 int Addcol(int A[10][10], int k, int c);

 clrscr();

 printf("Enter the order of the matrix\n");
 scanf("%d %d", &row, &col);

 printf("Enter the elements of the matrix\n");
 for(i=0; i<row; i++)
 {
  for(j=0; j< col; j++)
  {
   scanf("%d", &arr[i][j]);
  }
 }

 printf("Input matrix is\n");
 for(i=0; i<row; i++)
 {
  for(j=0;j<col;j++)
  {
   printf("%3d", arr[i][j]);
  }
  printf("\n");
 }

 /* computing row sum */
 for(i=0; i<row; i++)
 {
  rowsum = Addrow(arr,i,col);
  printf("Sum of row %d = %d\n", i+1, rowsum);
 }

 for(j=0; j<col; j++)
 {
  colsum = Addcol(arr,j,row);
  printf("Sum of column  %d = %d\n", j+1, colsum);
 }

 /* computation of all elements */
 for(j=0; j< row; j++)
 {
  sumall = sumall + Addrow(arr,j,col);
 } 

 printf("Sum of all elements of matrix = %d\n", sumall);

}

/* Function to add each row */
int Addrow(int A[10][10], int k, int c)
{
 int rsum=0, i;
 for(i=0; i< c; i++)
 {
  rsum = rsum + A[k][i];
 }
 return(rsum);
}

/* Function to add each column */
int Addcol(int A[10][10], int k, int r)
{
 int csum=0, j;
 for(j=0; j< r; j++)
 {
  csum = csum + A[j][k];
 }
 return(csum);
}
Read more Similar C Programs
Matrix Programs
Learn C Programming
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C Program to find the Multiplication of two matrices

C Program to find the Multiplication of two matrices. C Program Develop functions
a) To read a given matrix
b) To output a matrix
c) To compute the product of two matrices
Use the above functions to read in two matrices A (MxN) B (NxM), to compute the product of the two matrices, to output the given matrices and the computed matrix in a main function
Read more about C Programming Language .


/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/

#include <stdio.h>
#include <conio.h>
#define MAXROWS 10
#define MAXCOLS 10

void main()
{
 int A[MAXROWS][MAXCOLS], B[MAXROWS][MAXCOLS], C[MAXROWS][MAXCOLS];
 int M, N;

 /*Function declarations*/

 void readMatrix(int arr[][MAXCOLS], int M, int N);
 void printMatrix(int arr[][MAXCOLS], int M, int N);
 void productMatrix(int A[][MAXCOLS], int B[][MAXCOLS], int C[][MAXCOLS],
   int M, int N);

 clrscr();

 printf("Enter the value of M and N\n");
 scanf("%d %d",&M, &N);
 printf ("Enter matrix A\n");
 readMatrix(A,M,N);
 printf("Matrix A\n");
 printMatrix(A,M,N);

 printf ("Enter matrix B\n");
 readMatrix(B,M,N);
 printf("Matrix B\n");
 printMatrix(B,M,N);

 productMatrix(A,B,C, M,N);

 printf ("The product matrix is\n");
 printMatrix(C,M,N);
}

/*Input matrix A*/
void readMatrix(int arr[][MAXCOLS], int M, int N)
{
 int i, j;
 for(i=0; i< M ; i++)
 {
  for ( j=0; j < N; j++)
  {
   scanf("%d",&arr[i][j]);
  }
 }
}
void printMatrix(int arr[][MAXCOLS], int M, int N)
{
 int i, j;
 for(i=0; i< M ; i++)
 {
  for ( j=0; j < N; j++)
  {
   printf("%3d",arr[i][j]);
  }
  printf("\n");
 }
}

/* Multiplication of matrices */
void productMatrix(int A[][MAXCOLS], int B[][MAXCOLS], int C[][MAXCOLS],
  int M, int N)
{
 int i, j, k;
 for(i=0; i< M ; i++)
 {
  for ( j=0; j < N; j++)
  {
   C[i][j] = 0 ;
   for (k=0; k < N; k++)
   {
    C[i][j] = C[i][j] + A[i][k] * B[k][j];
   }
  }
 }
}
Read more Similar C Programs
Matrix Programs
Learn C Programming
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C program to sort given N elements using SELECTION sort method

Write a C program to sort given N elements using SELECTION sort method using functions :
a) To find maximum of elements
b) To swap two elements
Selection sort is comparison based sorting technique, It finds the minimum value in list and swaps that value to the first position and so on. Selection sort is inefficient on larger data. Read more about C Programming Language .


/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/


#include <stdio.h>
#include <conio.h>

void main()
{
 int array[10];
 int i, j, N, temp;

 int findmax(int b[10], int k);      /* function declaration */
 void exchang(int b[10], int k);

 clrscr();

 printf("Enter the value of N\n");
 scanf("%d",&N);

 printf("Enter the elements one by one\n");
 for(i=0; i<N ; i++)
 {
  scanf("%d",&array[i]);

 }

 printf("Input array elements\n");
 for(i=0; i<N ; i++)
 {
  printf("%d\n",array[i]);
 }

 /* Selection sorting begins */
 exchang(array,N);

 printf("Sorted array is...\n");
 for(i=0; i< N ; i++)
 {
  printf("%d\n",array[i]);
 }

}   /* End of main*/

/* function to find the maximum value */
int findmax(int b[10], int k)
{
 int max=0,j;
 for(j = 1; j <= k; j++)
 {
  if ( b[j] > b[max])
  {
   max = j;
  }
 }
 return(max);
}


void exchang(int b[10],int k)
{
 int  temp, big, j;
 for ( j=k-1; j>=1; j--)
 {

  big = findmax(b,j);
  temp = b[big];
  b[big] = b[j];
  b[j] = temp;
 }
 return;
}
Read more Similar C Programs

Data Structures


C Sorting

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C Program To Sort Names

Write a C program to read N names, store them in the form of an array and sort them in alphabetical order.Output the given names and the sorted names in two columns side by side with suitable heading.Program will sort the name strings using Bubble Sort technique. Read more about C Programming Language .


/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                        Happy Coding
***********************************************************/


#include <stdio.h>
#include <conio.h>
#include <string.h>

void main()
{
 char name[10][8], Tname[10][8], temp[8];
 int i, j, N;

 clrscr();

 printf("Enter the value of N\n");
 scanf("%d", &N);

 printf("Enter %d names\n", N);
 for(i=0; i< N ; i++)
 {
  scanf("%s",name[i]);
  strcpy (Tname[i], name[i]);
 }

 for(i=0; i < N-1 ; i++)
 {
  for(j=i+1; j< N; j++)
  {
   if(strcmpi(name[i],name[j]) > 0)
   {
    strcpy(temp,name[i]);
    strcpy(name[i],name[j]);
    strcpy(name[j],temp);
   }
  }
 }

 printf("\n----------------------------------------\n");
 printf("Input Names\tSorted names\n");
 printf("------------------------------------------\n");
 for(i=0; i< N ; i++)
 {
  printf("%s\t\t%s\n",Tname[i], name[i]);
 }
 printf("------------------------------------------\n");

}    /* End of main() */
Read more Similar C Programs

Data Structures


 C Sorting
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C Program to read an English sentence and replace lowercase characters by uppercase and vice-versa.

Write a C program to read an English sentence and replace lowercase characters by uppercase and vice-verso. Output the given sentence as well as the case converted sentence on two different lines. Read more about C Programming Language .


/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/


#include <stdio.h>
#include <ctype.h>
#include <conio.h>

void main()
{
 char sentence[100];
 int count, ch, i;

 clrscr();

 printf("Enter a sentence\n");
 for(i=0; (sentence[i] = getchar())!='\n'; i++)
 {
  ;
 }

 sentence[i]='\0';

 count = i; /*shows the number of chars accepted in a sentence*/

 printf("The given sentence is   : %s",sentence);

 printf("\nCase changed sentence is: ");
 for(i=0; i < count; i++)
 {
  ch = islower(sentence[i]) ? toupper(sentence[i]) : tolower(sentence[i]);
  putchar(ch);
 }

} /*End of main()*/
Read more Similar C Programs

C Strings


Data Structures


C Sorting
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C program to read a string and check whether it is a palindrome or not (without using library functions).

Write a C program to read a string and check whether it is a palindrome or not (without using library functions). Output the given string along with suitable message.Palindrome is a word, sentence, group of characters, or number, that remains same, when reversed.
For example: GADAG, 9009... Read more about C Programming Language .

/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/

#include <stdio.h>
#include <conio.h>
#include <string.h>

void main()
{
 char string[25], revString[25]={'\0'};
 int  i,length = 0, flag = 0;

 clrscr();

 fflush(stdin);

 printf("Enter a string\n");
 gets(string);

 for (i=0; string[i] != '\0'; i++) /*keep going through each */
 {                                 /*character of the string */
  length++;                     /*till its end */
 }

 for (i=length-1; i >= 0 ; i--)
 {
  revString[length-i-1] = string[i];
 }

 /*Compare the input string and its reverse. If both are equal
   then the input string is palindrome. Otherwise it is
   not a palindrome */

 for (i=0; i < length ; i++)
 {
  if (revString[i] == string[i])
   flag = 1;
  else
   flag = 0;
 }

 if (flag == 1)
  printf ("%s is a palindrome\n", string);
 else
  printf("%s is not a palindrome\n", string);

}   /*End of main()*/
Read more Similar C Programs
Searching in C

C Strings
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C program to find the transpose of a given Matrix.

Write a C program to read A (MxN), find the transpose of a given matrix and output both the input matrix and the transposed matrix.
Transpose of a matrix is the interchanging the rows and columns, If A is matrix of order(i*j), where i is the row and j is the column, then Transpose of A is A(j*i). Read more about C Programming Language .

/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/

    */

#include <stdio.h>
#include <conio.h>

void main()
{
 int i,j,M,N;
 int A[10][10], B[10][10];

 int transpose(int A[][10], int r, int c);  /*Function prototype*/

 clrscr();

 printf("Enter the order of matrix A\n");
 scanf("%d %d", &M, &N);

 printf("Enter the elements of matrix\n");
 for(i=0;i<M;i++)
 {
  for(j=0;j<N;j++)
  {
   scanf("%d",&A[i][j]);
  }
 }

 printf("Matrix A is\n");
 for(i=0;i<M;i++)
 {
  for(j=0;j<N;j++)
  {
   printf("%3d",A[i][j]);
  }
  printf("\n");
 }

 /* Finding Transpose of matrix*/
 for(i=0;i<M;i++)
 {
  for(j=0;j<N;j++)
  {
   B[i][j] =  A[j][i];
  }
 }

 printf("Its Transpose is\n");
 for(i=0;i<M;i++)
 {
  for(j=0;j<N;j++)
  {
   printf("%3d",B[i][j]);
  }
  printf("\n");
 }

}  /*End of main()*/
Read more Similar C Programs
Matrix Programs
Learn C Programming
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C Program to find Matrix addition,Subtraction and trace.

Write a C program to read two matrices A (MxN) and B(MxN) and perform addition ,subtraction of A and B, and Find the trace of the resultant matrix. Output the given matrix, their sum or Differences and the trace. Read more about C Programming Language .


/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/

#include <stdio.h>
#include <conio.h>

void main()
{
 int A[10][10], B[10][10], sumat[10][10], diffmat[10][10];
 int i, j, M,N, option;

 void trace (int arr[][10], int M, int N);

 clrscr();

 printf("Enter the order of the matrice A and B\n");
 scanf("%d %d", &M, &N);

 printf("Enter the elements of matrix A\n");
 for(i=0; i<M; i++)
 {
  for(j=0; j<N; j++)
  {
   scanf("%d",&A[i][j]);
  }
 }

 printf("MATRIX A is\n");
 for(i=0; i<M; i++)
 {
  for(j=0; j<N; j++)
  {
   printf("%3d",A[i][j]);
  }
  printf("\n");
 }

 printf("Enter the elements of matrix B\n");
 for(i=0; i<M; i++)
 {
  for(j=0; j<N; j++)
  {
   scanf("%d",&B[i][j]);
  }
 }

 printf("MATRIX B is\n");
 for(i=0; i<M; i++)
 {
  for(j=0; j<N; j++)
  {
   printf("%3d",B[i][j]);
  }
  printf("\n");
 }

 printf("Enter your option: 1 for Addition and 2 for Subtraction\n");
 scanf("%d",&option);

 switch (option)
 {
 case 1: for(i=0; i<M; i++)
 {
  for(j=0; j<N; j++)
  {
   sumat[i][j] = A[i][j] + B[i][j];
  }
 }

 printf("Sum matrix is\n");
 for(i=0; i<M; i++)
 {
  for(j=0; j<N; j++)
  {
   printf("%3d",sumat[i][j]) ;
  }
  printf("\n");
 }

 trace (sumat, M, N);
 break;

 case 2:for(i=0; i<M; i++)
 {
  for(j=0; j<N; j++)
  {
   diffmat[i][j] = A[i][j] - B[i][j];
  }
 }

 printf("Difference matrix is\n");
 for(i=0; i<M; i++)
 {
  for(j=0; j<N; j++)
  {
   printf("%3d",diffmat[i][j]) ;
  }
  printf("\n");
 }

 trace (diffmat, M, N);
 break;
 }

}    /* End of main() */

/*Function to find the trace of a given matrix and print it*/

void trace (int arr[][10], int M, int N)
{
 int i, j, trace = 0;
 for(i=0; i<M; i++)
 {
  for(j=0; j<N; j++)
  {
   if (i==j)
   {
    trace = trace + arr[i][j];
   }
  }
 }
 printf ("Trace of the resultant matrix is = %d\n", trace);

}
Read more Similar C Programs
Matrix Programs
Learn C Programming
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C Program to evaluate the given polynomial P(x)=AnXn + An-1Xn-1 + An-2Xn-2+... +A1X + A0, by reading its coefficents into an array.

Write a C program to evaluate the given polynomial P(x)=AnXn + An-1Xn-1 + An-2Xn-2+... +A1X + A0, by reading its coefficents into an array.A Polynomial is a mathematical expression involving a sum of powers in one or more variables multiplied by coefficients. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/



#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define MAXSIZE 10

voidmain()
{
 int a[MAXSIZE];
 int i, N,power;
 float x, polySum;

 clrscr();

 printf("Enter the order of the polynomial\n");
 scanf("%d", &N);

 printf("Enter the value of x\n");
 scanf("%f", &x);

 /*Read the coefficients into an array*/

 printf("Enter %d coefficients\n",N+1);
 for (i=0;i <= N;i++)
 {
  scanf("%d",&a[i]);
 }

 polySum = a[0];

 for (i=1;i<= N;i++)
 {
  polySum = polySum * x + a[i];
 }

 power = N;

 /*power--;*/

 printf("Given polynomial is:\n");
 for (i=0;i<= N;i++)
 {
  if (power < 0)
  {
   break;
  }

  /* printing proper polynomial function*/
  if (a[i] > 0)
   printf(" + ");
  else if (a[i] < 0)
   printf(" - ");
  else
   printf (" ");
  printf("%dx^%d  ",abs(a[i]),power--);

 }

 printf("\nSum of the polynomial = %6.2f\n",polySum);
}
Array In C Simple C Programs You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C Program to find the average of largest two of the given numbers in the array.

Example programs to solve the problems of Arrays in C.
Write a C program to read in four integer numbers into an array and find the average of largest two of the given numbers without sorting the array. The program should output the given four numbers and the average with suitable headings. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/



#include <stdio.h>
#include <conio.h>
#define MAX 4

void main()
{
 int a[MAX], i, l1,l2,temp;

 clrscr();

 printf("Enter %d integer numbers\n", MAX);
 for (i=0; i < MAX; i++)
 {
  scanf("%d", &a[i]);
 }

 printf("Input interger are\n");
 for (i=0; i < MAX; i++)
 {
  printf("%5d", a[i]);
 }

 printf("\n");

 l1 = a[0];  /*assume first element of array is the first largest*/
 l2 = a[1];  /*assume first element of array is the second largest*/

 if (l1 < l2)
 {
  temp = l1;
  l1 = l2;
  l2 = temp;
 }

 for (i=2;i<4;i++)
 {
  if (a[i] >= l1)
  {
   l2 = l1;
   l1 = a[i];
  }
  else if(a[i] > l2)
  {
   l2= a[i];
  }
 }

 printf("\n%d is the first largest\n", l1);
 printf("%d is the second largest\n", l2);
 printf("\nAverage of %d and %d = %d\n", l1,l2, (l1+l2)/2);

}
Read more Similar C Programs
Array In C

Simple C Programs

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C program to input real numbers and find the mean, variance and standard deviation

Write a C program to input real numbers and find the mean, variance and standard deviation.Mean is sum of values divided by the total number of values. Variance shows the how the data s are distributed. Standard deviation is the square root of its variance. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/


#include <stdio.h>
#include <conio.h>
#include <math.h>
#define MAXSIZE 10

void main()
{
 float x[MAXSIZE];
 int  i, n;
 float avrg, var, SD, sum=0, sum1=0;

 clrscr();

 printf("Enter the value of N\n");
 scanf("%d", &n);

 printf("Enter %d real numbers\n",n);
 for(i=0; i<n; i++)
 {
  scanf("%f", &x[i]);
 }

 /* Compute the sum of all elements */

 for(i=0; i<n; i++)
 {
  sum = sum + x[i];
 }
 avrg = sum /(float) n;

 /* Compute  varaience  and standard deviation  */

 for(i=0; i<n; i++)
 {
  sum1 = sum1 + pow((x[i] - avrg),2);
 }
 var = sum1 / (float) n;
 SD = sqrt(var);

 printf("Average of all elements  = %.2f\n", avrg);
 printf("Varience of all elements = %.2f\n", var);
 printf("Standard deviation       = %.2f\n", SD);
}  /*End of main()*/
Read more Similar C Programs
Array In C

Simple C Programs

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C Program To Demonstrate Linear search

Write a C program to input N numbers (integers or reals) and store them in an array. Conduct a linear search for a given key number and report success or failure in the form of a suitable message.
Linear search is the basic searching algorithm, also called as sequential search. Algorithm search's the element by comparing the each element in the list, until the desired element found. Read more about C Programming Language.


/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                        Happy Coding
***********************************************************/


#include <stdio.h>
#include <conio.h>

void main()
{
 int array[10];
 int i, N, keynum, found=0;

 clrscr();

 printf("Enter the value of N\n");
 scanf("%d",&N);

 printf("Enter the elements one by one\n");
 for(i=0; i<N ; i++)
 {
  scanf("%d",&array[i]);
 }
 printf("Input array is\n");
 for(i=0; i<N ; i++)
 {
  printf("%d\n",array[i]);
 }
 printf("Enter the element to be searched\n");
 scanf("%d", &keynum);

 /* Linear search begins */
 for ( i=0; i < N ; i++)
 {
  if( keynum == array[i] )
  {
   found = 1;
   break;
  }
 }
 if ( found == 1)
  printf("SUCCESSFUL SEARCH\n");
 else
  printf("Search is FAILED\n");

} /* End of main */
Read more Similar C Programs
C Basic

Search Algorithms.

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C Program To Find The Sum & Average

Example programs to solve the problems of Arrays in C.
C program to read N integers (zero, +ve and -ve) into an array A and to
a) Find the sum of negative numbers
b) Find the sum of positive numbers and
c) Find the average of all input numbers
Read more about C Programming Language .
/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                       Happy Coding
***********************************************************/
 
#include <stdio.h>
#include <conio.h>
#define MAXSIZE 10

void main()
{
 int array[MAXSIZE];
 int i, N, negsum=0, posum=0;
 float total=0.0, averg;

 clrscr();

 printf ("Enter the value of N\n");
 scanf("%d", &N);

 printf("Enter %d numbers (-ve, +ve and zero)\n", N);
 for(i=0; i< N ; i++)
 {
  scanf("%d",&array[i]);
  fflush(stdin);
 }

 printf("Input array elements\n");
 for(i=0; i< N ; i++)
 {
  printf("%+3d\n",array[i]);
 }

 /* Summing  begins */
 for(i=0; i< N ; i++)
 {

  if(array[i] < 0)
  {
   negsum = negsum +  array[i];
  }
  else if(array[i] > 0)
  {
   posum = posum + array[i];
  }
  else if( array[i] == 0)
  {
   ;
  }
  total = total + array[i] ;
 }

 averg = total / N;
 printf("\nSum of all negative numbers    = %d\n",negsum);
 printf("Sum of all positive numbers    = %d\n", posum);
 printf("\nAverage of all input numbers   = %.2f\n", averg);

}        /*End of main()*/
Read more Similar C Programs
Array In C

Simple C Programs

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C program to find the value of cos(x) using the series up to the given accuracy (without using user defined function) . Also print cos(x) using library function.

Write a C program to find the value of cos(x) using the series up to the given accuracy (without using user defined function) Also print cos(x) using library function. Read more about C Programming Language.



/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/


#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>

void main()
{
 int  n, x1;
 float  acc, term, den, x, cosx=0, cosval;

 clrscr();

 printf("Enter the value of x (in degrees)\n");
 scanf("%f",&x);

 x1 = x;

 /* Converting degrees to radians*/

 x = x*(3.142/180.0);
 cosval = cos(x);

 printf("Enter the accuary for the result\n");
 scanf("%f", &acc);
 term = 1;
 cosx = term;
 n = 1;

 do
 {
  den = 2*n*(2*n-1);
  term = -term * x * x / den;
  cosx = cosx + term;
  n = n + 1;
 } while(acc <= fabs(cosval - cosx));

 printf("Sum of the cosine series       = %f\n", cosx);
 printf("Using Library function cos(%d) = %f\n", x1,cos(x));
}         /*End of main() */
Read more Similar C Programs
C Basic

Search Algorithms.

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C program to find the value of sin(x) using the series up to the given accuracy (without using user defined function) Also print sin(x) using library function.

Write a C program to find the value of sin(x) using the series up to the given accuracy (without using user defined function) Also print sin(x) using library function. Read more about C Programming Language.

/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/


#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>

void main()
{
 int n, x1;
 float  acc, term, den, x, sinx=0, sinval;

 clrscr();

 printf("Enter the value of x (in degrees)\n");
 scanf("%f",&x);

 x1 = x;

 /* Converting degrees to radians*/

 x = x*(3.142/180.0);
 sinval = sin(x);

 printf("Enter the accuary for the result\n");
 scanf("%f", &acc);

 term = x;
 sinx = term;
 n = 1;

 do
 {
  den = 2*n*(2*n+1);
  term = -term * x * x / den;
  sinx = sinx + term;
  n = n + 1;

 } while(acc <= fabs(sinval - sinx));

 printf("Sum of the sine series         = %f\n", sinx);
 printf("Using Library function sin(%d) = %f\n", x1,sin(x));

}         /*End of main() */
Read more Similar C Programs
C Basic

Search Algorithms.

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C program to find the GCD and LCM of two integers output the results along with the given integers. Use Euclids' algorithm.

Write a C program to find the GCD and LCM of two integers output the results along with the given integers. Use Euclids' algorithm to find the GCD and LCM.
Euclids' algorithm uses the division algorithm which repeatedly divides starting from the two numbers we want to find the GCD of until we get a remainder of 0. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/


#include <stdio.h>
#include <conio.h>

void main()
{
 int  num1, num2, gcd, lcm, remainder, numerator, denominator;
 clrscr();

 printf("Enter two numbers\n");
 scanf("%d %d", &num1,&num2);

 if (num1 > num2)
 {
  numerator = num1;
  denominator = num2;
 }
 else
 {
  numerator = num2;
  denominator = num1;
 }
 remainder = num1 % num2;
 while(remainder !=0)
 {
  numerator   = denominator;
  denominator = remainder;
  remainder   = numerator % denominator;
 }
 gcd = denominator;
 lcm = num1 * num2 / gcd;
 printf("GCD of %d and %d = %d \n", num1,num2,gcd);
 printf("LCM of %d and %d = %d \n", num1,num2,lcm);
}  /* End of main() */
Read more Similar C Programs

Data Structures


C Sorting

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C program to find the sum of 'N' natural numbers.

Write a C program to find the sum of 'N' natural numbers. Natural numbers are the whole numbers except zero, usually we used for counting.
Example:1, 2, 3, 4,----------- Read more about C Programming Language .

/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/



#include <stdio.h>
#include <conio.h>

void main()
{
 int i, N, sum = 0;

 clrscr();

 printf("Enter an integer number\n");
 scanf ("%d", &N);

 for (i=1; i <= N; i++)
 {
  sum = sum + i;
 }

 printf ("Sum of first %d natural numbers = %d\n", N, sum);
}
Read more Similar C Programs
Searching in C

Number Theory 
C Strings
 
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

C program to check whether a given integer number is positive or negative.

Write a C program to check whether a given integer number is positive or negative.Read more about C Programming Language . This program is available on GitHub https://github.com/snadahalli/cprograms/blob/master/posneg.c

/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/

#include <stdio.h>
#include <conio.h>

void main()
{
 int number;
 clrscr();

 printf("Enter a number\n");
 scanf ("%d", &number);

 if (number > 0)
  printf ("%d is a positive number\n", number);
 else if (number < 0)
  printf ("%d is a negative number\n", number);
 else
  printf("You entered 0\n");

}
Read more Similar C Programs
Searching in C

Number Theory 
C Strings
 
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!
-->

C program to check whether a given integer is odd or even.

Write a C program to check whether a given integer is odd or even.Read more about C Programming Language .
/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/



#include <stdio.h>
#include <conio.h>

void main()
{
 int ival, remainder;

 clrscr();

 printf("Enter an integer :");
 scanf ("%d", &ival);

 remainder = ival % 2;

 if (remainder == 0)
  printf ("%d, is an even integer\n", ival);
 else
  printf ("%d, is an odd integer\n", ival);

}
Read more Similar C Programs
Searching in C

Number Theory 
C Strings
 
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!