Posts

Showing posts from August, 2012

Void Data Type

                                                                                                                          Void Data Type The void type has no values therefore we cannot declare it as variable as we did in case of integer and float. The void data type is usually used with function to specify its type and void has no range.   syntax :- void<function name>(<data type><space><identifier>) void div(int a)

Character Data Type

                                                                        Character Data Type Character type variable can hold a single character and are declared by using the keyword char. As there are singed and unsigned int (either short or long), in the same way there are signed and unsigned chars; both occupy 1 byte each, but having different ranges. Unsigned characters have values between 0 and 255, signed characters have values from –128 to 127. In c# all characters internally represented as integer value of example following are ASCII values of characters. A =65     a =97 B =66     b=98 C=67      c=99 and so on Signed character                      -128 to 127     2 7 Unsigned character                        255            2 8    Initialization of char type variable:- Syntax: char <variable name>; char ch = 'a'; char chh ='b'; Example : a, b, g, S, j. Here ch & chh are variable name & 'a' and 'A' are

Float Data Type

                                              Float  Data Type The float data type is used to store fractional numbers (real numbers) with 6 digits of precision. Floating point numbers are denoted by the keyword float. When the accuracy of the floating point number is insufficient, we can use the double to define the number. The double is same as float but with longer precision and takes double space (8 bytes) than float. To extend the precision further we can use long double which occupies 10 bytes of memory space. Syntax:   float <variable name>; float num1; double num2; long double num3; Example: 9.125, 3.1254. Floating Point Data Type Memory Allocation: float double long   double 1 byte 2 byte 4 byte   Initialization:- Syntax:-     float<value name>=<value>; float k=158.368; Runtime:- scanf("%f",&k);  

Integer Data Type

                                               Integer Data Types Integers are whole numbers with a range of values, range of values are machine dependent. Generally an integer occupies 2 bytes memory space and its value range limited to -32768 to +32767 (that is, -215 to +215-1). A signed integer use one bit for storing sign and rest 15 bits for number.To control the range of numbers and storage space, C has three classes of integer storage namely short int, int and long int. All three data types have signed and unsigned forms. A short int requires half the amount of storage than normal integer . Unlike signed integer , unsigned integers are always positive and use all the bits for the size of the number. Therefore, the range of an unsigned integer will be from 0 to 65535. The long integers are used to declare a longer range of values and it occupies 4 bytes of storage space. Syntax: int <variable name>; int num1; short int num2; long int num3; int

Primary Data types

                                                     Primary Data types                Data type                     Keyword                Formal Specifier         Size                  Data Range           Character                         char                            %c                    1 bytes                 -128 to  127         Unsigned Character      unsigned char               <-- -->                8 bytes                0   to 255          Integer                               int                              %d                   2 bytes              -32768 to 32767     Long integer                    long int                         %ld                   4 bytes              -2 31 to 2 31                     unsigned integer           unsigned int                      %u                    2 bytes               0 to 65535      Float                              float                               %f                    4 bytes            -3.4e

Data type

Image
                                                             Data Type         Data type can be defined as the type of data of variable or constant store.   Types of data types are as follows:- Primary data types Secondary data types

Variable

                                                                    Variable Variable are temporary storage in memory whose value changed during program excution according to given instruction. Declaration of variable       <data type> <identifier> ;       syntax:-       int k;       float g; Initialization of variable        <data type> <identifier> = <value> ;      Syntax:-      int k = 10 ;      float g = 3.14 ;

Keyword

                                                                                                                                           Keyword Keyword are reserved words which have predefined meaning, we cannot use them as identifier.  auto       break     case     char    const    continue    default    do    double    else     enum    extern    float       for         goto        if        int        long      register      return   short  signed  sizeof     static    struct    switch   typedef   union  unsigned void    volatile     while

Identifier

                                                              Identifier Identifier is a name given to various program element such as variable name,function name,array name etc. First letter must be an alphabet or underscore We can use use a-z,A-Z,0-9,underscore in identifiers .   We cannot use keyword as identifier because they are reserved words which have predefined meaning. We cannot use same name in different case both have predefined meaning  Valid or invalid identifiers:-          cguruankit             valid                 123cguruanki        invalid           _cguruankit          valid          Num cguruankit    invalid          int 2a;                   invalid          int a_2;                 valid          int a,A;                 valid          int a,a;                  invalid                      

Token

                                              Token                         Tokens are generally any unit that is not whitespace or a comment.  /*this is program*/ void main()  { int a,b,c; printf("enter values:"); scanf("%d%d",a,b); c=a+b; printf("%d",c); getch(); } /*these are token*/ void  main()  {  int  a, b, c; printf ("enter values:"); scanf ("%d%d",a,b); c = a + b; printf("%d",c); getch(); } Types of tokens Identifiers Variable Data Type Keyword  String Operator

Programming Code types

                                           Programming Code  Types of programming code:- Tokans Identifiers Variable Data Type Keyword String Operator

flowchart c program to exhange value of two variable without using third one

Image
 C program to exhange value of two variable without using third one   ( algorithm )  

flowchart c program to exchange values of variable using third variable

Image
C program to exchange values of variable using third variable ( algorithm )

flowchart c program to check input value is postive or negative

Image
 c program to check input value is postive or negative( algorithm )

flowchart c program to calculate percentage

Image
C program to calculate percentage( alogrithm )

flowchart c program to check input year is leap year or not

Image
C program to check input year is leap year or not( algorithm ) *correction: if year%4 and year%400 then its leap year else not

flowchart c program to check value is even or odd

Image
C program to check value is even or odd( algorithm )

flowchart c program to find area of triangle

Image
C program to find area of triangle( algorithm ) C program to find area of triangle( algorithm )

flowchart c program to find area of square

Image
                            C  program to find area of Square( algorithm )

flowchart c program to find area of circle

Image
                             C  program to find area of circle( algorithm )

flowchart C program to divide two number

Image
                             C  program to calculate average( algorithm )

flowchart of c program to add two numbers

Image
C program to add two number ( algorithm )

Flow Chart

Image
              Flow chart A Flowchart is a type of diagram that represent an algorithm or process,showing the step as boxes of various kinds,and their order  by connecting these with arrows .this diagrammatic representation can give a step-by-step solution to a given problem.process operations are represented in these boxes , and arrows connecting them represent flow of control.they are implied by the sequencing of operations.flowcharts are used in analyzing,managing a process or program in various fields. 

algorithm to check year is leap year or not

            C program check year is leap year or not( flowchart ) start  input x div=x/4 if rem=0print true otherwise print false stop

algorithm to input three value and calculate there percentage

            C program calculate there percentage ( flowchart ) start input a,b,c mul=a+b+c*100 div=mul/300 print div stop

algorithm to calculate area of the triangle

              C program calculate area of triangle( flowchart ) start  input b,h tri=0.5*b*h print tri stop

algorithm to calculate area of the circle

C program to calculate area of the circle( flowchart ) start  input r cir=3.14*r*r print cir stop

algorithm to calculate area of the rectangle

                    C program to calculate area of the rectangle( flowchart ) start  input l,b rec=l*b print rec stop

algorithm to calculate area of the square

                 C program to calculate area of the square( flowchart ) start  input x sq=x*x print sq stop

c program to exchange the value of 2 variables without using third variable algorithm

C program to exchange the value of 2 variables without using third variable( flowchart) start  input x,y x=X+y y=x-y x=x-y print x y stop

c program to exchange values of two numbers algorithm

C program to exchange values of two numbers( flowchart ) start input a,b,c c = a then a=b b=c print a,b stop 

c program to check number is even or odd algorithm

C program to check value is even or odd( flowchart ) start  input a a/2 if remender is 0 print even otherwize odd stop

c program to check number is positive or negative algorithm

C program to check number is positive or negative ( flowchart ) start input a if a>0 then  print positive otherwiese  print negative stop

average of any three number algorithm

C program to find average of any three number( flowchart ) start  input average <-sum/3 print average stop

Program solving

Program solving Algorithm Flowchart Programming code Algorithm:-  algorithm is finite set of instructions for solving a particular problem. Syntax:- start  Input/scan/accept logic print/write (output) stop Example:- adding two number:- start input a,b,c Sum<- a+b print sum   stop 

programming approach

Image
Programming approach Top level down approach Bottom up approach

translator,compiler,assembler

Translator it is software thar convert source code to object and vice versa.                                                       ------->                       --------> Source code Compiler:-          A compiler is a computer program (or set of programs) that transforms source code written in a programming language (the source language) into another computer language .   Assembler:-         a computer program to translate between lower-level representations of computer programs; it converts basic computer instructions into a pattern of bits which can be easily understood by a computer and the processor can use it to perform its basic operations. Interpreter:- an interpreter normally means a computer program that executes,that is performs , instructions written in a programming language. An interpreter may be a program that either executes the source code directly translates source code into some efficient intermediate representation (code

Basics of c language

A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine.       Types of Programming language:- Low level language/machine language Assembly language high level language    Machine language   Every command the computer sees is given as a number or sequence of numbers.  It is in binary, normally presented in hex to simplify and be more readable. Avantages of machine language:- Fast speed  trasnlator not required   Disadvantages of machine language:- Machine dependent Complex instruction set             Assembly language  This is the same as machine language, except the command numbers have been replaced by letter sequences which are more readable and easier to memorize. High level language  High-level languages are there to make programming ea

Escape sequence characters

\n    -   newline \t     -   horizontal tab \v    -   vertical tab \b    -   return backspace \r     -  carriage return \f     -  form feed \a    -  audible alert \\     -  backslash \?    -  question mark \'     -  single quote \\''   - couble quote

Write a c program which takes password from users

// author:ankit gehlot //website:http://ankitcguru.blogspot.com/   #include<stdio.h> #define MAX 500 int main(){ char password[MAX]; char p; //character declaration int i=0;//intiger declaration printf("Enter the password:"); while((p=getch())!= 13)//while loop { password[i++] = p; printf("*"); } password[i] = '\0'; if(i<6) //condition printf("\nWeak password"); printf("\nYou have entered: %s",password); return 0;//return value }

c program of structure with array

#include<conio.h> #include<stdio.h> struct stu { int roll,h,en,s,sum,per; char name[20];}; void main() {struct stu e[10]; int i,sum,per; clrscr(); for(i=0;i<=1;i++) { printf("enter emp no:\t"); scanf("%d",&e[i].roll); printf("enter name:\t"); scanf("%s",e[i].name); printf("enter marks of hindi,english,science:\n"); scanf("%d%d%d",e[i].h,e[i].en,e[i].s); sum=e[i].h+e[i].en+e[i].s; per=(sum*100)/3;} printf("Emp no.\t\tName\tHindi\tEnglish\tScience\tTotal\tPercentage\n"); for(i=0;i<=10;i++) { printf("%d\t\t%s\t%d\t%d\t%d\t%d\t%d\n",e[i].roll,e[i].name,e[i].h,e[i].en,e[i].s,sum,per); } getch(); }

Revers a string

#include<stdio.h> #include<string.h> main() {    char arr[100];    printf("Enter a string to reverse\n");    gets(arr);    strrev(arr);    printf("Reverse of entered string is \n%s\n",arr);    getch(); }

c program to print Floyd's triangle

#include <stdio.h>   int main() { int n, i, c, a = 1;   printf("Enter the number of rows of Floyd's triangle to print\n"); scanf("%d", &n);   for (i = 1; i <= n; i++) { for (c = 1; c <= i; c++) { printf("%d ",a); a++; } printf("\n"); }   return 0; }

c program to print Pascal triangle

#include <stdio.h>   int main() { int n, i, c, a = 1;   printf("Enter the number of rows of Floyd's triangle to print\n"); scanf("%d", &n);   for (i = 1; i <= n; i++) { for (c = 1; c <= i; c++) { printf("%d ",a); a++; } printf("\n"); }   return 0; }

c program for String concatenation

#include<stdio.h>   void concatenate_string(char*, char*);   main() { char original[100], add[100];   printf("Enter source string\n"); gets(original);   printf("Enter string to concatenate\n"); gets(add);   concatenate_string(original, add);   printf("String after concatenation is \"%s\"\n", original);   return 0; }   void concatenate_string(char *original, char *add) { while(*original) original++;   while(*add) { *original = *add; add++; original++; } *original = '\0'; }

Matrix multiplication in c

#include <stdio.h>   int main() { int m, n, p, q, c, d, k, sum = 0; int first[10][10], second[10][10], multiply[10][10];   printf("Enter the number of rows and columns of first matrix\n"); scanf("%d%d", &m, &n); printf("Enter the elements of first matrix\n");   for ( c = 0 ; c < m ; c++ ) for ( d = 0 ; d < n ; d++ ) scanf("%d", &first[c][d]);   printf("Enter the number of rows and columns of second matrix\n"); scanf("%d%d", &p, &q);   if ( n != p ) printf("Matrices with entered orders can't be multiplied with each other.\n"); else { printf("Enter the elements of second matrix\n");   for ( c = 0 ; c < p ; c++ ) for ( d = 0 ; d < q ; d++ ) scanf("%d", &second[c][d]);   for ( c = 0 ; c < m ; c++ ) { for ( d = 0 ; d < q ; d++ ) { for ( k = 0 ; k < p ; k++ )

Factorial program in c

#include <stdio.h>   int main() { int c, n, fact = 1;   printf("Enter a number to calculate it's factorial\n"); scanf("%d", &n);   for (c = 1; c <= n; c++) fact = fact * c;   printf("Factorial of %d = %d\n", n, fact);   return 0; }

c program to print date

#include<stdio.h> #include<conio.h> #include<dos.h>   main() { struct date d;   getdate(&d);   printf("Current system date is %d/%d/%d",d.da_day,d.da_mon,d.da_year); getch(); return 0; }

c program to delete a file

#include<stdio.h>   main() { int status; char file_name[25];   printf("Enter the name of file you wish to delete\n"); gets(file_name);   status = remove(file_name);   if( status == 0 ) printf("%s file deleted successfully.\n",file_name); else { printf("Unable to delete the file\n"); perror("Error"); }   getch(); }

c program to print Fibonacci series

/* Fibonacci Series c language */ #include<stdio.h>   main() { int n, first = 0, second = 1, next, c;   printf("Enter the number of terms\n"); scanf("%d",&n);   printf("First %d terms of Fibonacci series are :-\n",n);   for ( c = 0 ; c < n ; c++ ) { if ( c <= 1 ) next = c; else { next = first + second; first = second; second = next; } printf("%d\n",next); }   return 0; }

c program to display your ip adress

#include<stdlib.h>   main() { system("C:\\Windows\\System32\\ipconfig"); system("pause");   return 0; }

c program to shutdown your computer

#include <stdio.h> #include <stdlib.h>   main() { char ch;   printf("Do you want to shutdown your computer now (y/n)\n"); scanf("%c",&ch);   if (ch == 'y' || ch == 'Y') system("C:\\WINDOWS\\System32\\shutdown /s");   return 0; }

C program for palindrome without using string functions

#include <stdio.h> #include <string.h>   main() { char text[100]; int begin, middle, end, length = 0;   gets(text);   while ( text[length] != '\0' ) length++;   end = length - 1; middle = length/2;   for( begin = 0 ; begin < middle ; begin++ ) { if ( text[begin] != text[end] ) { printf("Not a palindrome.\n"); break; } end--; } if( begin == middle ) printf("Palindrome.\n");   return 0; }

c program to check whether input alphabet is a vowel or not

   C program to check whether input  alphabet is a vowel or not   #include <stdio.h>   main() { char ch;   printf("Enter a character\n"); scanf("%c", &ch);   if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch =='o' || ch=='O' || ch == 'u' || ch == 'U') printf("%c is a vowel.\n", ch); else printf("%c is not a vowel.\n", ch);   getch(); }

c program to multiply exponent and base

#include <conio.h> #include <stdio.h> main() {     int pow=1,x,y,i;     printf("Enter base & exponent:\t");     scanf("%d%d",&x,&y);    for(i=1;i<=y;i++)     {pow=pow*x; } printf("power :%d ",pow); getch(); }

c program to Reverse Digits

#include <conio.h> #include <stdio.h> main() {     int x,rev=0,rem,i,sum=0;     printf("Enter numbers to reverse:\t");     scanf("%d",&x);    for(i=x;x>0;x=x/10)     {rem=x%10;     rev=rev*10+rem;     sum=sum+rem; } printf("reverse of numbers is %d and sum of digits is %d",rev,sum); getch(); }

c program to check value is prime no or not

#include<stdio.h> main() {    int n, c = 2;    printf("Enter a number to check if it is prime\n");    scanf("%d",&n);    for ( c = 2 ; c <= n - 1 ; c++ )    {       if ( n%c == 0 )       {          printf("%d is not prime.\n", n);      break;       }    }    if ( c == n )  {     printf("%d is prime.\n", n);  } getch(); }

c program to check user value is leap year or not

#include<stdio.h> int main() { int year; printf("Enter the year: "); scanf("%d",&year); /* ** The logic is that the year is either divisible by both ** 100 and 4 , OR its only divisible by 4 not by hundred */ if(year%400 ==0 || (year%100 != 0 && year%4 == 0)) { printf("Year %d is a leap year",year); } else { printf("Year %d is not a leap year",year); } getch(); }

C program to check value is even or odd

#include<stdio.h> main() {    int n;    printf("Enter an integer\n");    scanf("%d",&n);    if ( n%2 == 0 )       printf("Even\n");    else       printf("Odd\n");    return 0; }

C program to convert Fahrenheit degrees into Centigrade and Vice-Versa

#include<stdio.h> #include<conio.h> int main( ) { float f, c; clrscr( ); printf("Enter the fahrenheit degrees:"); scanf("%f", &f); c= (f-32)/1.8 ; printf("\nAfter Fahrenheit degrees, Centigrade Degrees = %f", c); f= 1.8*c + 32.0; printf("\nAfter Centigrade degrees, Fahrenheit degrees = %f", f); getch( ); return 0; }

c program to check value is positive or negative

#include<conio.h> #include<stdio.h> main() { int no; clrscr( ); printf("Enter the required number to check:"); scanf("%d", &no); if(no>0) { printf("\n %d is positive number",no); } else if(no<0) { printf("\n%d is negative number",no); } else{ printf("\nEntered Number is ZERO"); } getch( ); return 0; }                                                         or #include<conio.h> #include<stdio.h> main() { signed int a; printf("Enter value for checking:"); scanf("%d",&a); if(a>0) { printf("Positive"); } else{ printf("Negative"); } getch(); }

c program to find percentage

#include<conio.h> #include<stdio.h> main() { float a,b,per; printf("type numberator: "); scanf("%f",&a); printf("type denominator: "); scanf("%f",&b); per=a*100/b; printf("percentage:%f",per); getch(); }

c program to find average

#include<conio.h> #include<stdio.h> main() { int sum,total,avrg; printf("type the sum of obersvations:"); scanf("%d",&sum); printf("type total no. of observations:"); scanf("%d"&total); avrg=sum/total; printf("average:%d",avrg); getch(); }

c program for Division

#include <stdio.h> #include <coino.h> void main() { int a,b,c; printf("insert two no. for Division :\t"); scanf("%d%d",&a,&b); c=a/b; printf("Division of %d from %d is %d"a,b,c); getch(); }

C program ofr Multiplication

#include <stdio.h> #include <coino.h> void main() { int a,b,c; printf("insert two no. for Multiplication :\t"); scanf("%d%d",&a,&b); c=a*b; printf("Multiplication of %d from %d is %d"a,b,c); getch(); }

c program for Sum

#include <stdio.h> main() { int a,b,c; printf("enter the value of a & b"); scanf("%d%d",&a,&b); c=a+b; printf("sum of the two numbers is a+b- %d",c); getch(); }

first program of c

#include<stdio.h> #include<conio.h> main() { printf("hello world !"); getch(); }