Category: Programs

C Program to Compare Two Strings using strcmp()

include include int main(){char s1[20], s2[20];int result;printf(“\nEnter first string: “);gets(s1);printf(“\nEnter second string: “);gets(s2);result = strcmp(s1, s2);if (result == 0)printf(“\nBoth strings are equal”);elseprintf(“\nBoth strings are not equal”);return 0;}OUTPUT:Enter first string: Programming9.com Enter second string: Programming9.com Both strings are equal

Start reading C Program to Compare Two Strings using strcmp()

C Program to Implement Call By Value using Functions

include swap (int, int);main(){int a, b;printf(“\nEnter value of a & b: “);scanf(“%d %d”, &a, &b);printf(“\nBefore Swapping:\n”);printf(“\na = %d\n\nb = %d\n”, a, b);swap(a, b);printf(“\nAfter Swapping:\n”);printf(“\na = %d\n\nb = %d”, a, b);getch();}swap (int a, int b){int temp;temp = a;a = b;b = temp;}OUTPUT:Enter value of a & b: 10 20 Before Swapping: a = 10 b = …

Start reading C Program to Implement Call By Value using Functions

C Program to Find Number of Characters and Words in a String

include include int main(){char str[50];int i=0, word=0, chr=0;printf(“\nEnter Your String: “);gets(str);while (str[i] != ‘\0’){if (str[i] == ‘ ‘){word++;chr++;}elsechr++;i++;}printf(“\nNumber of characters: %d”, chr);printf(“\nNumber of words: %d”, word+1);return 0;}OUTPUT:Enter Your String: Welcome to Programming9 .com Number of characters: 28Number of words: 4

Start reading C Program to Find Number of Characters and Words in a String

C Program to Implement CONTINUE statement

include int main(){int i, n, a, sq;printf(“\n\tProgram finds square of positive numbers only\n”);printf(“\nHow many numbers you want to enter: “);scanf(“%d”, &n);for (i=1; i<=n; i++){printf(“\nEnter Number: “);scanf(“%d”, &a);if (a < 0)continue;sq = a * a;printf(“\nSquare of a Number : %d\n”, sq);}return 0;}OUTPUT:Program finds square of positive numbers only How many numbers you want to enter: 3 …

Start reading C Program to Implement CONTINUE statement

Swapping of Two Numbers Using Call By Reference in C

include swap (int *, int *);int main(){int a, b;printf(“\nEnter value of a & b: “);scanf(“%d %d”, &a, &b);printf(“\nBefore Swapping:\n”);printf(“\na = %d\n\nb = %d\n”, a, b);swap(&a, &b);printf(“\nAfter Swapping:\n”);printf(“\na = %d\n\nb = %d”, a, b);return 0;}swap (int *x, int *y){int temp;temp = *x;*x = *y;*y = temp;} OUTPUT:Enter value of a & b: 10 20 Before Swapping: …

Start reading Swapping of Two Numbers Using Call By Reference in C

C Program to Implement BINARY SEARCH

Program to Search an Element using BInary Search */ include /* Function Prototype Declaration */void binary_search(); /* Global Declaration of Variables */int a[50], n, item, loc, beg, mid, end, i; /* We used main() because it’s a C-Compiler.Use void main() or int main() if necessary */ main(){printf(“\nEnter size of an array: “);scanf(“%d”, &n); // Reading …

Start reading C Program to Implement BINARY SEARCH