Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Introduction to C Programming Language

Posted by Tushar Bedekar
C is a programming language developed by AT & T’s Bell Laboratories of USA in 1972. It was designed and written by a man named Dennis Richie. C is reliable, simple and easy to use.
One can easily learn C++ , JAVA or any other programming language if one has a knowledge of C.

Basic features:-

  • It is 16 bit programming language. 
  • Many of the popular and robust languages available today requires a basic knowledge of "c Programming". 
  • Many major components of popular operating systems like Windows, UNIX, LINUX is still written in C.
  • We all are now familiar with the smart phones, this smartness comes from a microprocessor,operating system and program mes embedded within that smart phones.Generally all these program-mes are written basically in "c Programming " languages.
  • Because of the fast execution f the c program-mes.
  • many popular gaming frame works(such as Direct X) have been built using c programming language.
  • It is simply and easy for the Beginners who are learning to do computer programming

C- Character Set:-


Similar to the other programming languages the C languages also include character set which includes alphabets, numbers an special symbols. following are the some character that we use in "C Programming" languages.
  • Alphabets :- A to B (ASCII value from 65 to 90)       a to b(ASCII value from 97 to 122)  
  • Digits:- 0 to 9(ASCII value from 48 to 57) 
  • Special Characters:- #,*,7,%,4 and 2 etc.(ASCII values as per the character) 
These ASCII values can be found by the help of a "C program me" for program me please click the link given below. Coming soon

Read More

Source Code Vs Object Code

Posted by Tushar Bedekar

Source Code:-

http://www.allaboutcomputing.net/In computing, source code is any collection of       computer instructions (possibly with comments) written using some human-readable computer    language, usually as text. The source code of a program is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source code. The source code is often transformed by a compiler program into low-level machine code understood by the computer. The machine code might then be stored for execution at a later time. Alternatively, an interpreter can be used to analyze and perform the outcomes of the source code program directly on the fly.

Most computer applications are distributed in a form that includes executable files, but not their source code. If the source code were included, it would be useful to a user, programmer, or system administrator, who may wish to modify the program or understand how it works.


Aside from its machine-readable forms, source code also appears in books and other media; often in the form of small code snippets, but occasionally complete code bases; a well-known case is the source code of PGP.



Object Code:-


Object code, or sometimes an object module, is what a computer compiler produces. In a general sense object code is a sequence of statements or instructions in a computer language, usually a machine code language (i.e., 1's and 0's)[citation needed] or an intermediate language such as RTL.



Object files can in turn be linked to form an executable file or library file. In order to be used, object code must either be placed in an executable file, a library file, or an object file.

Object code is a portion of machine code that hasn't yet been linked into a complete program. It's the machine code for one particular library or module that will make up the completed product. It may also contain placeholders or offsets not found in the machine code of a completed program that the linker will use to connect everything together. Machine code is binary (1's and 0's)[citation needed] code that can be executed directly by the cpu. If you were to open a "machine code" file in a text editor you would see garbage, including unprintable characters. Object code is a variant of machine code, with a difference that the jumps are sort of parameterized such that a linker can fill them in. An assembler is used to convert assembly code into machine code (object code). A linker links several object (and library) files to generate an executable.


Source:-Wikipedia

Read More

Byte Code Vs Machine Code

Posted by Tushar Bedekar
Generally, "machine code" refers to the data that can be executed by a certain computer, while "byte code" refers to data that can be executed by a virtual machine. The virtual machine takes the byte code and produces machine code appropriate for the actual machine it is running on.



Machine Code:-

Machine code or machine language is a set of instructions executed directly by a computer's central processing unit (CPU). Each instruction performs a very specific task, such as a load, a jump, or an ALU operation on a unit of data in a CPU register or memory. Every program directly executed by a CPU is made up of a series of such instructions.


Numerical machine code  may be regarded as the lowest-level representation of a compiled and/or assembled computer program or as a primitive and hardware-dependent programming language. While it is possible to write programs directly in numerical machine code, it is tedious and error prone to manage individual bits and calculate numerical addresses and constants manually. It is therefore rarely done today, except for situations that require extreme optimization or debugging.


Almost all practical programs today are written in higher-level languages or assembly language, and translated to executable machine code by a compiler and/or assembler and linker. Programs in interpreted languages[1] are not translated into machine code however, although their interpreter (which may be seen as an executor or processor) typically consists of directly executable machine code (generated from assembly and/or high level language source code).

Byte Code:-

Byte code, also known as p-code (portable code), is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, byte codes are compact numeric codes, constants, and references (normally numeric addresses) which encode the result of parsing and semantic analysis of things like type, scope, and nesting depths of program objects. They therefore allow much better performance than direct interpretation of source code.

The name byte code stems from instruction sets which have one-byte op codes followed by optional parameters. Intermediate representations such as byte code may be output by programming language implementations to ease interpretation, or it may be used to reduce hardware and operating system dependence by allowing the same code to run on different platforms. Byte code may often be either directly executed on a virtual machine (i.e. interpreter), or it may be further compiled into machine code for better performance
.

Since byte code instructions are processed by software, they may be arbitrarily complex, but are nonetheless often akin to traditional hardware instructions; virtual stack machines are the most common, but virtual register machines have also been built.Different parts may often be stored in separate files, similar to object modules, but dynamically loaded during execution.


Source:-Wikipedia 
Read More

SORTING A STRING IN AN ALPHABETICAL ORDER:-

Posted by Tushar Bedekar


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

void sort_string(char*);

int main()
{
   char string[100];

   printf("Enter some text\n");
   gets(string);

   sort_string(string);
   printf("%s\n", string);

   return 0;
}

void sort_string(char *s)
{
   int c, d = 0, length;
   char *pointer, *result, ch;

   length = strlen(s);

   result = (char*)malloc(length+1);       //use of pointer here 

   pointer = s;

   for ( ch = 'a' ; ch <= 'z' ; ch++ )
   {
      for ( c = 0 ; c < length ; c++ )
      {
         if ( *pointer == ch )
         {
            *(result+d) = *pointer;
            d++;
         }
         pointer++;
      }
      pointer = s;
   }
   *(result+d) = '\0';

   strcpy(s, result);
   free(result);

}


Read More

C ANAGRAM PROGRAMMING CODE

Posted by Tushar Bedekar


#include <stdio.h>

int check_anagram(char [], char []);

int main()
{
   char a[100], b[100];
   int flag;

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

   printf("Enter second string\n");
   gets(b);

   flag = check_anagram(a, b);

   if (flag == 1)
      printf("\"%s\" and \"%s\" are anagrams.\n", a, b);
   else
      printf("\"%s\" and \"%s\" are not anagrams.\n", a, b);

   return 0;
}

int check_anagram(char a[], char b[])
{
   int first[26] = {0}, second[26] = {0}, c = 0;

   while (a[c] != '\0')
   {
      first[a[c]-'a']++;
      c++;
   }

   c = 0;

   while (b[c] != '\0')
   {
      second[b[c]-'a']++;
      c++;
   }

   for (c = 0; c < 26; c++)
   {
      if (first[c] != second[c])
         return 0;
   }

   return 1;
}

OUTPUT OF THE PROGRAM ME:-

Download Anagram Programme

Read More

c program me to get IP address of your computer

Posted by Tushar Bedekar 4 Comments


 
 #include<stdlib.h>

int main()
{
system("C:\\Windows\\System32\\ipconfig");


return 0;
}
 

 

 Download ip address programme

Read More

Write a C program to Sort the list of integers using Bubble Sort

Posted by Tushar Bedekar


#include(stdio.h)                                 //note place '<' & '>' in place of '(' & ')'
#include(conio.h)
void bubble(int [ ], int);                                           // func. declaration
void main( )
{
 int a[10],n,i;
clrscr();
printf("Enter the no. of elements u want to fill:");
scanf("%d",&n);
printf("\nEnter the array elements:");
for(i=0; i< n; i++)
scanf("%d",&a[i]);

bubble(a,n);                                                             // calling function
getch();
}

void bubble(int b[], int no)                                            // called function
{
int i,j,temp;
for(i=0; i< no-1; i++)
{
for(j=0; j< no-i; j++)
{
if(b[j]>b[j+1])
{
temp=b[j];
b[j]=b[j+1];
b[j+1]=temp;
}
}
}
printf("\nAfter sorting : ");
for(i=0; i< no; i++)
printf("%5d",b[i] );
}

Output:- Enter the no. of elements u want to fill: 5
Enter the array elements : 8  1  90  5  4
After sorting : 1  4  5  8  90
Read More

Write a C program to print the Given pyramid

Posted by Tushar Bedekar




      1


    1 2  
   1 2 3 
  1 2 3 4 
 1 2 3 4 5
  .
  .
  .
  n

Solution:-#include(stdio.h)                        // note place '<' & '>' in place of '(' & ')'
#include(conio.h)
int main( )
{
int r,c,n,sp;
clrscr( );
printf("Enter the no. of rows u want to print:");
scanf("%d", &n);
for(r=1; r<=n; r++)

for(sp=n; sp>=r; sp--)
printf(" ");                                                 // give one space in betw quotations.
for(c=1; c<=r; c++)
printf("%2d", c);
printf("\n");
}
getch( );
return 0;
}
Read More

Write a C program to find GCD of each of the two consecutive elements of an array. write a function GCD(a,b) that would take two consecutive elements of the array as arguments and return the GCD

Posted by Tushar Bedekar

#include(stdio.h)                                  // Note place '<' & '>' in place of '(' & ')'
int gcd(int,int);
void main()
{
  int a[10],n,i,b[10];
  int x,y;
  clrscr();
  printf("Enter the size of the array:");
  scanf("%d",&n);
  printf("\nEnter the array elements:");
  for(i=0; i< n ;i++)
    scanf("%d",&a[i]);
 for(i=0; i< n-1 ;i++)
  {
     x=a[i];
     y=a[i+1];
     b[i]=gcd(x,y);
    printf("\nG.C.D of %d and %d is : %d",x,y,b[i]);
  }
getch();
}
int gcd(int a,int b)
{
  int rem;
  for(;;)
  {
    rem=a%b;
    if(rem==0)
       break;
    a=b;
    b=rem;
  }
 return b;
}
Read More

Write a C program to get the maximum and minimum values of a Data type

Posted by Tushar Bedekar

#include(stdio.h)                                     // note place '<' & '>' in place of '(' & ')'
#include(conio.h) 
void main( )
{
int x, y;
clrscr( );
x=1;  
while( x > 0)
{
y = x;
x + + ;
}
printf("\nMaximum value : %d ", y );
printf("\nMinimum value : %d", x);
getch( );
}

Output:- Maximum value : 32767
Minimum value : -32768

Similarly we can find the below datatypes,
long int ( %ld ) 
char ( %d ) 
unsigned ( %u )
.....
Read More

Write a C function that defines two strings as parameters, as follows, and checks whether the second string (str2) is a substring of the first one (str1).

Posted by Tushar Bedekar



int substring_finder(char* str1, char* str2);
The function should return an integer as follows:
• 2 if str2 is a substring of str1 and also of same length
o e.g. str1 = "Hello" and str2= "Hello"
• 1 if str2 is a substring of str1 and of different lengths
o e.g. str1 = "Hello World" and str2= "Hello"
• 0 if str2 is not a substring of str1
o e.g. str1 = "Hello" and str2= "Helo"


 

program me starts from here:-

#include(string.h)                                         //  note place '<' & '>' in place of '(' & ')'
#include(stdio.h)
int substring_finder(char *,char *);
int main()
{
  char *str1,*str2;
  int fl;
  clrscr();
  printf("Enter the main string:");
  gets(str1);
  printf("Enter the sub-string:");
  gets(str2);
  fl=substring_finder(str1,str2);

  if(fl==0)
    printf("\n'str2' is not a substring of 'str1'");
  else if(fl==1)
    printf("\n'str2' is a substring of 'str1'");
  else if(fl==2)
    printf("\nBoth are equal");

getch();
return 0;
}
int substring_finder(char *str,char *sub)
{
  int flag;
  if(strcmp(str,sub)==0)
     flag=2;
  else if(strstr(str,sub))
     flag=1;
  else
     flag=0;

  return flag;
}
Read More

Write a C program that prints a given positive integer in reverse order and also sum of the individual digits involved in the given integer.

Posted by Tushar Bedekar

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

int main( )
{
int no, rev=0, rem, sum=0;
clrscr( );
printf("Enter the required integer:");
scanf("%d", &no);
while(no>0)
{
rem = no%10;
rev = (10*rev)+rem;
sum = sum+rem;
no=no/10;
}
printf("\nReverse Number : %d", rev);
printf("\nSum of the individual digits : %d", sum);
getch( );

return 0;
}
Read More

Write C programs that use both recursive and non-recursive functions to find the factorial of a given integer.

Posted by Tushar Bedekar

(a).without using recursive function.

#include(stdio.h)                              // place this '<' & '>' instead of '(' & ')' before stdio.h
#include(conio.h)
int fact( int);                                        // function declaration
int main( )
{
int no,result;
clrscr( );
printf("Enter the required number:");
scanf("%d", &no);
result = fact( no);
printf("\n %d Factorial is : %d", no, result);
getch( );
return 0;
}
int fact(int n)
{
int ft,
for( ft=1; n>=1; n--)
ft=ft*n;
return ft;
}

Output:- 4 Factorial is : 24

(b).using recursive function.

#include(stdio.h)                           // place this '<' & '>' instead of '(' & ')' before stdio.h
#include(conio.h)
int fact( int);                                      // function declaration
int main( )
{
int no,result;
clrscr( );
printf("Enter the required number:");
scanf("%d", &no);
result = fact( no);
printf("\n %d Factorial is : %d", no, result);
getch( );
return 0;
}
int fact(int n)
{
int ft,
if( n==1)
return 1;
else
ft= n*fact (n-1);
return ft;
}
Read More

Write a C program to find the roots of a quadratic equation using Pointers and Functions.

Posted by Tushar Bedekar

 #include(stdio.h)                    // place this '<' & '>' instead of '(' & ')' before stdio.h
#include(math.h)
void quadratic_roots(double *,double *, double *);
int main(void)
{
double a, b, c;
clrscr( );
printf("Enter the values of a,b and c :");
scanf("%lf %lf %lf", &a, &b, &c);
printf("\nThe required quadratic equation is : ax^2 + bx + c = 0");
printf("\nGiven Values: a = %lf \n b= %lf \n c= %lf ",a ,b, c);
quadratic_roots(&a,&b,&c);
getch( );
return 0;
}

void quadratic_roots(double *aa, double *bb, double *cc)
{
double root1, root2;
if((*bb)*(*bb)= = 4*(*aa)*(*cc))
{
root1= -(*bb)/2*(*aa);
printf("\nRoots are equal");
printf("\nvalue : %lf", root1);

else if((*bb)*(*bb) > 4*(*aa)*(*cc))
{
root1= (-(*bb) + sqrt((*bb)*(*bb) -(4*(*aa)*(*cc))))/(2*(*aa));
root2= (-(*bb) - sqrt((*bb)*(*bb) -(4*(*aa)*(*cc))))/(2*(*aa));
printf("\nThe roots of the equation are: %lf and %lf ", root1, root2);
}
else
{
printf("\nImaginary roots");
root1= (-(*bb) + sqrt((*bb)*(*bb) -(4*(*aa)*(*cc))))/(2*(*aa));
root2= (-(*bb) - sqrt((*bb)*(*bb) -(4*(*aa)*(*cc))))/(2*(*aa));
printf("roots are %f+i(%f) , %f-i(%f)",r1, r2, r1, r2);
}
}
Read More

Design of Pyramids IN C Programming

Posted by Tushar Bedekar


A B C D E F G G F E D C B A      
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A

solution:-#include<stdio.h>
#include<conio.h>
int main( )
{
  int r,c,askey;
  clrscr( );
  
  for( r=7; r>=1; r-- )
  {
    askey=65;
    for(c=1; c<=r; c++ )
      printf("%2c", askey++ );
    askey--; 
    for(c=r; c>=1; c-- )
       printf("%2c", askey--);
   
   printf("\n");
  }
  getch();
  return 0;
}

Output:- 
A B C D E F G G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A

Note:- 
'r' and 'c' means rows and columns .
'askey' variable is for disp. values.
Read More

Write a C program to delete an element from the array

Posted by Tushar Bedekar

#include< stdio.h>
#include< conio.h>
int main( )
{
int a[20], len, i, n, item, j;
clrscr( );
printf("Enter how many elements you want to enter:");
scanf("%d", &len);

printf("\nEnter the array elements:");
for(i=0; i<'len' ; i++)                                 // remove the single quotes in for loop
scanf("%d", &a[ i]);

printf("\nEnter the location, where you want to delete:");
scanf("%d", &n);

item= a[n-1];
printf("\nDeleted value is : %d", item);

for( j= n-1; j<'len-1; j++) 

{ a[ j]= a[ j+1]; }

len=len-1;
printf("\nThe new element list :");
for(i=0; i<'len; i++)

printf("%5d", a[i]);

getch( );
return 0;
}

Output:-
Enter how many elements you want to enter: 4
Enter the array elements:
10
20
30
40
Enter the location, where you want to delete: 3
Deleted value : 30
The new element list: 10 20 40
Read More

Write a C program to display the message "Welcome to C" without a Semicolon

Posted by Tushar Bedekar

// C program without a Semicolon.
This can done in three ways but one of them is infinite.(ie, while loop)
Solution:1
#include(stdio.h) // note place '<' & '>' in place of '(' & ')'
void main( )
{
if(printf("Welcome to C"))
{
}
}

Solution:2
void main( )
{
switch(printf("Welcome to C"))
{
}
}

Solution:3
void main( )
{
while(printf("Welcome to C")) //infinite loop
{
}
}
Read More

Write a C program that adds first seven terms of the following series 1/1! +2/2! + 3/3! + ..........

Posted by Tushar Bedekar


#include< stdio.h>
#include< conio.h>
int main( )
{
int n,i,j,fact;
float sum=0;
clrscr();
for(i=1; i<=7; i++) { fact=1; for(j=i; j>=1; j--)     // to find the factorial
fact=fact*j;

sum=sum+(float)i/fact;
}
printf("\nSum : %f",sum);
getch();
return 0;
}
Read More

Write a C program to find the greatest common divisor of the two given positive integers

Posted by Tushar Bedekar



#include< stido.h>
#include< conio.h>
int main( )
{
int a, b, res;
clrscr( );
printf("Enter the two integer values:");
scanf("%d%d", &a, &b);

for(  ;  ;  )                                                  //This is empty for loop.
{
res = a%b;
if( res = = 0) break;
a = b;
b = res;
}
printf("\n The GCF is : %d", res);
getch( );
return 0;
}
Read More

HEAP SORTING IN C

Posted by Tushar Bedekar



Q. Write a C program to sort 5 numbers using heap sorting method.


Ans.


/* c program for heap sorting method*/

#include<stdio.h>
#include<conio.h>
void manage(int *, int);
void heapsort(int *, int, int);
int main()
{
 int arr[20]; 
 int i,j,size,tmp,k;
 printf("\n\t------- Heap sorting method -------\n\n");
 printf("Enter the number of elements to sort : ");
 scanf("%d",&size);
 for(i=1; i<=size; i++)
 {
   printf("Enter %d element : ",i);
   scanf("%d",&arr[i]);
   manage(arr,i);
 }
 j=size;
 for(i=1; i<=j; i++)
 {
   tmp=arr[1];
   arr[1]=arr[size];
   arr[size]=tmp;
   size--;
   heapsort(arr,1,size);
 }
 printf("\n\t------- Heap sorted elements -------\n\n");
 size=j;
 for(i=1; i<=size; i++)
     printf("%d ",arr[i]);
 getch();
 return 0;
}


void manage(int *arr, int i)
{
 int tmp; 
 tmp=arr[i];
 while((i>1)&&(arr[i/2]<tmp))
 {
   arr[i]=arr[i/2];
   i=i/2;
 }
 arr[i]=tmp;
}


void heapsort(int *arr, int i, int size)
{
 int tmp,j;
 tmp=arr[i];
 j=i*2;
 while(j<=size)
 {
   if((j<size)&&(arr[j]<arr[j+1]))
      j++;
   if(arr[j]<arr[j/2]) 
      break;
   arr[j/2]=arr[j];
   j=j*2;
 }
 arr[j/2]=tmp;
}

/************* OUTPUT ***************/

Screen shot for Heap sorting C program





Read More
back to top