Advertisement

Who is the inventor of c?(For correct answer::Dennis Ritchie)


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{     //Dennis Ritchie
clrscr();int i;char in[20];printf("Who is the inventor of C ?\n");i=0;
while(i<=2)
{
gets(in);if(strcmp("Dennis Ritchie",in)==0)
{
printf("Good");break;
}
else
{
printf("\nTry again");++i;
}
}
if(i==3)
printf("\nDennis Ritchie");
getch();
}

C PROGRAM FOR BINARY SEARCH

#include<stdio.h>
#include<conio.h>
void main()
{
int array[10];
int i, j, n, temp, num;
int low,mid,high;
clrscr();
printf("Enter the value of the array\t");
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]);
}
for(i=0;i<n;i++)
{
for(j=0;j<(n-i-1);j++)
{
if(array[j]>array[j+1])
{
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
printf("Sorted array is...\n");
for(i=0;i<n;i++)
{
printf("%d\n",array[i]);
}
printf("Enter the element to be searched\n");
scanf("%d",&num);
low=1;
high=n;
do
{
mid=(low+high)/2;
if(num<array[mid])
high=mid-1;
else if(num>array[mid])
low=mid+1;
}
while(num!=array[mid] && low<=high);
if(num==array[mid])
{
printf("\n\tis present at position %d",array[i],i+1);
}
else
{
printf("Search is FAILED\n");
}
getch();
}

Making the reverse using Arry

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

main()
{
   int n, c, j, temp, a[100];

   printf("Enter the number of elements in array\n");
   scanf("%d",&n);

   printf("Enter the array elements\n");

   for ( c = 0 ; c < n ; c++ )
      scanf("%d",&a[c]);

   if( n%2 == 0 )
      c = n/2 - 1;
   else
      c = n/2;

   for ( j = 0 ; j < c ; j++ )
   {
      temp = a[j];
      a[j] = a[n -j - 1];
      a[n-j-1] = temp;
   }

   printf("Reverse array is\n");

   for( c = 0 ; c < n ; c++ )
      printf("%d\n", a[c]);

   getch();
   return 0;
}

Making Double diamond with star

#include <stdio.h>
#include <conio.h>
#include <math.h>
 main ()
{
    int i,j,k,r,m;
    printf("put row number");
    scanf("%d",&r);
m=r;
   
    for(i=1;i<=r;++i) 
    {
                     for(j=m-i;j>=0;j--)
                     printf(" ");
                     for(k=1;k<=i;++k)      
                     printf("* ");
                      printf("\n");                            
     }
 
    for(i=1;i<=r;++i) 
    {
                     for(j=m-(i+1);j<r;j++)
                     printf(" ");
                     for(k=r;k>i;--k)      
                     printf("* ");
                      printf("\n");
                     
}      getch();
     return 0;
}

Basic Discussion


ANSI C supports four classes of data types.
1. Primary or Fundamental data types.
2. User-defined data types.
3. Derived data types.
4. Empty data set.

PRIMARY DATA TYPES
Integer Types

Type                         Size (bits)                      Range
int or signed int            16                        -32,768 to 32767
unsigned int                  16                            0 to 65535
short int                         8                          -128 to 127
unsigned short int         8                                0 to 255
long int                         32      -2,147,483,648 to 2,147,483,647
unsigned long int         32                           0 to 4,294,967,295

Floating Point Types
Type                                    Size(bits)                                             Range
float                                       32                                           3.4E-38 to 3.4E+38
double                                   64                                           1.7E-308 to 1.7E+308
long double                           80                                       3.4E-4932to 1.1E+4932

Character Types

Type                                  Size (bits)                                              Range
char                                       8                                                    -128 to 127
unsigned char                      8                                                       0 to 255

Some Basic discussion


Letters
Uppercase A….Z
Lowercase a…..z
Digits
All decimal digits 0…..9

Special characters::
, Comma                            & A m persand
. Period                              ^ Caret
; Semicolon                       * Asterisk
: Colon                               - Minus
? Question mark                + Plus sign
‘ Apostrophe                    < Less than
“ Quotation mark             > Greater than
! Exclamation                   ( Left parenthesis
| Vertical Bar                     ) Right parentheses
/ Slash                              [ Left bracket
\ Back slash                      ] Right bracket
~ Tilde                             { Left brace
_ Underscore                   } Right brace
$ Dollar sign                     # Number sign
% Percent sign


Constant Meaning
‘\a’ audible alert
‘\b’ backspace
‘\f’ form feed
‘\n’ new line
‘\0’ null
‘\v’ vertical tab
‘\t’ horizontal tab
‘\r’ carriage return

This is a string. It input two words & output how many words and add of that two words


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{   clrscr();
    char a[50],b[50],c[100];
    int i,j,m,n;
    printf("Enter 1st name:");
    gets(a);
    printf("Enter 2nd name:");
    gets(b);
    m=strlen(a);
    n=strlen(b);
    printf("%d %d\n",m,n);
    for(i=0;i<m;i++)
   { c[i]=a[i]; }
    for(j=0;j<n;j++)
   { c[i]=b[j];
   i++;}
    c[i]='\0';
    puts(c);
    getch();}

This array search a number from given numbers::


#include<stdio.h>
#include<conio.h>
void main()
{ clrscr();
  int a[100],i,j,n,m;
  j=0;
  printf("How many number u want to search?=");
  scanf("%d",&n);
  printf("Enter that numbers=");
  for(i=0;i<n;i++)
{  scanf("%d",&a[i]);    }
  printf("Enter a number for search=");
  scanf("%d",&m);
  for(i=0;i<n;i++)
{  if(m==a[i])
  j++;   }
  if(j==0)
  printf("search result is empty");
  else
  printf("search result is found %d time(s)",j);
  getch();
}