Posts

Showing posts with the label Advanced C Concepts

A C program for sorting of strings alphabetically.

void main() { int i,j,n; char s[5][20],t[20]; printf("\n Enter any 5 strings separated by enter:"); for(i=0;i<5;i++) //Taking input strings { scanf("%s",s[i]); } for(i=1;i<5;i++) // Logic to sort the strings alphabetiaclly { for(j=1;j<5;j++) { if( strcmp( s[j-1] , s[j] ) > 0) { strcpy( t,s[j-1] ); strcpy( s[j-1] , s[j] ); strcpy( s[j] , t); } } } printf("\n The Strings in the order:"); for(i=0;i<5;i++) // Display the strings { printf("\n %s \n",s[i]); } }

C program for average of 10 numbers

void main() { int i,n,sum=0; float avg; clrscr(); printf("enter the 10 number\n"); for (i=1;i<=10;i++) { scanf("%d",&n); sum +=n; } avg=sum/10.0; printf("The sum of 10 no =%d\nThe Average of = %8.2f\n",sum,avg); getch(); } you can post your output in comment box...

Average of 10 numbers

 Program for finding average of 10 numbers void main() { int i,n,sum=0; float avg; clrscr();

Factorial of a number with & without using recursion

Image
Factorial of a number with & without using recursion In this article we will see how to calculate the factorial of a given number Following program is done without using recursion.  We can do this in multiple ways. though I'm specifying a simple way to do it. It's reader's responsibility to find out other ways.:)

Conversion of atoi, itoa and demonstration of clock() function

Image
Conversion of atoi, itoa and demonstration of clock() function In this article we will see the the conversion of integer to character using itoa() function   conversion of character to integer using atoi() function   and working of clock() function.

Matrix Addition and Multiplication info

Image
Matrix Addition & Multiplication In this article we will see the Addition and Multiplication of the two matrices //this program is designed to demonstrate Matrix Addition and Multiplication #include<stdio.h> #include<conio.h> void main() {             int a[3][3],b[3][3],add[3][3],mult[3][3];             int i,j,k,sum=0;

Matrix Addition and Multiplication

Matrix Addition and Multiplication

itoa() example

#include <stdio.h> #include <stdlib.h> void main () { int no; char c[33]; printf( "Enter an integer number: " );

Use of atoi

  ****PROGRAM****  #include <stdio.h> #include <stdlib.h> #include <string.h> void main() {    int a;    char s[20];    strcpy(s, "1111111");    a= atoi(s);    printf("\n String is  = %s,   \nstring in integer is = %d", s, a);    strcpy(s, "spccprogramming.blogspot.in");    a= atoi(s);    printf("\nString value = %s, \n Integer value is = %d\n", s , a); } OUTPUT: String is = 1111111, string in integer is = 1111111 String value = spccprogramming.blogspot.in, Int value = 0
Program for linear search Program for binary search

A program for linear search in C language.

Image
Linear Search        In this article we will see the working of linear search       In linear search we accept the elements of array from the user. We ask the user to enter a number to be  search in the array. If that element or number is found then we will display the position of the element in that array.      We compare the search element sequentially from the first element to the last element or till the number is found. As we search from first to last in linear way hence it is known as a linear search. //This program is designed to show you the working of Linear Search #include<stdio.h> #include<conio.h> void main() {             int i,n,num,a[100],flag=0;             clrscr();          ...

A program for binary search in C language.

Image
Binary Search      In this article we will see the working of Binary Search. In Binary Search, we need to store the elements in sequential order. This algorithm works in partition format.      We use three variables min, max and mid. First we need to calculate the value of mid, by taking the average of (min+max)/2. Then we need to check whether the search element match with the element at mid in the array. If it is then we break the condition and further checking and declare that the element is found at its respective position. But if not, then we need to check following two cases.      If the search element is greater than the element present at current position of mid then initialize the value of min as min=mid+1; and start searching again       If the search element is smaller than the element at mid , then change the value of max and initialize it as max=mid-1; and start searc...

Simple program to show different typesof input and output.

Image
*Second C Program*      In our previous article we have seen the very basic c program.      Now, in this article, I will show you the program that gives the information about how to accept a character value a numeric value and sequence of characters that is nothing but string. String is any combination of alphabets i.e. nothing but any word.      As we have seen in previous article when we you printf(); statement it displays the contents written in it. It means it is used to display the data. We can show the output using printf();      Likewise when we want to accept the data from user, we need to use scanf(); statement.      In scanf(); statement, ‘%d’ is used to accept integer values, ‘%c’ is used to accept character values and ‘%s’ is used to accept the string. ‘&’ is used as an address space. It stores the value at a particular location which is given by ...