C Program to accept a string and a substring and check if the substring is present in the given string

C Strings:
Write a C program to accept a string and a substring and check if the substring is present in the given string. Program search’s given substring is in the string or not, and prints the appropriate message. 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 [email protected]
* 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 str[80],search[10];
int count1=0,count2=0,i,j,flag;


clrscr();

puts("Enter a string:");
gets(str);

puts("Enter search substring:");
gets(search);

while (str[count1]!='')
count1++;

while (search[count2]!='')
count2++;

for(i=0;i<=count1-count2;i++)
{
for(j=i;j<i+count2;j++)
{
flag=1;
if (str[j]!=search[j-i])
{
flag=0;
break;
}
}
if (flag==1)
break;
}
if (flag==1)
puts("SEARCH SUCCESSFUL!");
else
puts("SEARCH UNSUCCESSFUL!");
getch();
}
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 Follow @c_program

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) www.c-program-example.com

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 [email protected]
* 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 An");
scanf("%d", &n);

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

printf("Enter Elements of First Listn");
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 = %dn", 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 Follow @c_program

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) www.c-program-example.com

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 [email protected]
* 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 matrixn");
scanf("%d %d", &row, &col);

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

printf("Input matrix isn");
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 = %dn", i+1, rowsum);
}

for(j=0; j<col; j++)
{
colsum = Addcol(arr,j,row);
printf("Sum of column %d = %dn", 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 = %dn", 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 Follow @c_program

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) www.c-program-example.com

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 [email protected]
* 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 Nn");
scanf("%d", &N);

printf("Enter %d namesn", 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 NamestSorted namesn");
printf("------------------------------------------n");
for(i=0; i< N ; i++)
{
printf("%stt%sn",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 Follow @c_program

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) www.c-program-example.com

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 [email protected]
* 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 Nn");
scanf("%d",&N);

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

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

} /* 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 Follow @c_program

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) www.c-program-example.com

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 [email protected]
* 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 Nn");
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 elementsn");
for(i=0; i< N ; i++)
{
printf("%+3dn",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 = %dn",negsum);
printf("Sum of all positive numbers = %dn", posum);
printf("nAverage of all input numbers = %.2fn", 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 Follow @c_program

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) www.c-program-example.com

C program to find the value of cos(x)

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 [email protected]
* 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 resultn");
 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       = %fn", cosx);
 printf("Using Library function cos(%d) = %fn", 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 Follow @c_program

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) www.c-program-example.com

C program to find the value of sin(x)

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 [email protected]
* 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 resultn");
 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         = %fn", sinx);
 printf("Using Library function sin(%d) = %fn", 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 Follow @c_program

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) www.c-program-example.com

C Program To Swap Two Variables

C Program To Swap Two Variables without using the third variable. This type of C programs are asked in various Interviews.There are various methods to achieve this one. For example, a=a+b;
b=a-b;
a=a-b;
Here we use the XOR(^) operator to Swap Two Variables without using the third variable. 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 [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/


#include<stdio.h>

int main()
{
int a=20;
int b=10;
printf("Values of a and b before swappingn");
printf("a=%dnb=%dn",a,b);
a=a^b;
b=b^a;
a=b^a;
printf("Values of a and b After swappingn");
printf("a=%dnb=%dn",a,b);
return 0;
}
Read more Similar C Programs
C Interview Questions

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 Follow @c_program

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) www.c-program-example.com

C Program to find the number and sum of all integers from 100 to 200 which is divisible by 7

Example programs to solve the problems of Arrays in C.
C program to find the number and sum of all integers from 100to 200 which is divisible by 7. Read more about C Programming Language .

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 Follow @c_program

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) www.c-program-example.com