Thursday, August 6, 2015

List of programme for printout

This is to notify all students that all must take the print-outs of the programs given as an attachment and get it checked by us on 13th August,2015.



LIST OF PROGRAMS FOR PRINTING

  1. Accept two integers from the user and interchange them. Display the interchanged numbers.
  2. Accept a character from the keyboard and display its previous and next character in order. Ex. If the character entered is‘d’, display “The previous character is c”, “The next character is e”.
  3. Accept a character from the user and display its ASCII value.
  4. Write a program, which accepts annual basic salary of an employee and calculates and displays the Income tax as per the following rules. ***
    1. Basic:  < 1,50,000            Tax = 0
    2. 1,50,000 to 3,00,000        Tax = 20%
    3. > 3,00,000            Tax = 30%
  5. Accept a character from the user and check whether the character is a vowel or consonant. (Hint: a,e,i,o,u, A, E, I, O, U  are vowels).
  6. Accept any year as input through the keyboard. Write a program to check whether the year is a leap year or not. (Hint leap year is divisible by 4 and not by 100 or divisible by 400)
  7. Accept a character from the keyboard and display its previous and next character in order. Ex. If the character entered is‘d’, display “The previous character is c”, “The next character is e”.
  8. Write a program to check whether given character is a digit or a character in lowercase or uppercase alphabet. (Hint ASCII value of digit is between 48 to 58 and Lowercase characters have ASCII values in the range of 97 to122, uppercase is between 65 and 90).
  9. Write a C program to convert a given character into uppercase & vice versa.
  10. Write a C program to covert temperature from Celsius to Fahrenheit.
  11. Write a C program to find maximum & minimum of three numbers.
  12. Write a program, which accepts two integers and an operator as a character (+ - * /), performs the corresponding operation and displays the result.
  13. Write a program having a menu with the following options and corresponding actions: Area of a Circle, Area of a Rectangle and Area of a Triangle.
  14. . Write a C Program to accept a four digit number from user and count zero, odd and even digits from the entered number.

  15. Write a C program to calculate the sum of digits of a given number.
  16. Write a C program to calculate Factorial of a given number.
  17. Write a C program to calculate sum of first and last digit of a given number

  18. Write a C program to calculate sum of Fibonacci series up to a given terms.
  19. Write a C program to calculate the x to the power y.
  20. Write a C program to display multiplication table of a given number.

  1. Write a C program to calculate the sum of first n even numbers.

  1. Write a C program to check whether a given number is palindrome or not.

  1. Write a C program to check whether given number is Armstrong or not.

  1. Write a C program to check whether given number is perfect or not.

Monday, August 3, 2015

Switch Statement

Syntax of Switch Case :

switch ( expression )
    {
      case label1 :
            body1
            break;

      case label2 :
            body2
            break;

      case label3 :
            body3
            break;

      default :
           default-body
           break;
 }
 next-statement;

Rule 1 : Case Label must be unique

int id = 3 ;
switch(id)
       {
       case 1:
               printf("C Programming Language");
               break;
       case 2:
               printf("C++ Programming Language");
               break;
       case 2:
               printf("Web Technology");
               break;
       default :
               printf("No student found");
               break;
        }

Rule 2 : Case Labels must ends with Colon

case 1 :
       printf("C Programming Language");
       break;

Rule 3 : Case labels must have constants / constant expression

case 1+1:
case 'A':
case 67:
these are allowed examples of switch case labels , however variables are not allowed in switch case labels.
case var :
case num1 :
case n1+n2 :

Rule 4 : Case label must be of integral Type ( Integer,Character) whereas Case label should not be ‘floating point number ‘

case 10:
case 20+20:
case 'A':
case 'a':
these are allowed examples and following are illegal examples –
case 10.12:
case 7.5:

Rule 5 : Switch case should have at most one default label

switch(roll)
       {
       case 1:
               printf("C Programming Language");
               break;
       case 2:
               printf("C++ Programming Language");
               break;
       case 2:
               printf("Web Technology");
               break;
       default :
               printf("Default Version 1");
               break;
       default :
               printf("Default Version 2");
               break;
        }
It violets first rule.

Rule 6 : Default label is Optional

switch(roll)
       {
       case 1 :
               printf("C Programming Language");
               break;
       case 2 :
               printf("C++ Programming Language");
               break;
       case 2 :
               printf("Web Technology");
               break;
        }
default statement is optional. It can be neglected.

Rule 7 : Default can be placed anywhere in the switch

switch(roll)
       {
       case 1 :
               printf("C Programming Language");
               break;
       default:
               printf("No Student Found");
               break;
       case 2 :
               printf("C++ Programming Language");
               break;
       case 2 :
               printf("Web Technology");
               break;
        }

Rule 8 : Break Statement takes control out of the switch

Rule 9 : Two or more cases may share one break statement

switch(alpha)
       {
       case 'a':
       case 'A':
               printf("Alphabet A");
               break;
       case 'b':
       case 'B':
               printf("Alphabet B");
               break;
        }

Rule 10 : Nesting ( switch within switch ) is allowed

switch(alpha)
       {
       case 'a':
       case 'A':
               printf("Alphabet A");
               break;
       case 'b':
       case 'B':
               switch(alpha)
               {
               }
               break;
        }
nesting of switch case is allowed in C.

Rule 11 : Relational Operators are not allowed in Switch Statement.

switch(num)
       {
       case >15:
               printf("Number > 15");
               break;
       case =15:
               printf("Number = 15");
               break;
       case <15:
               printf("Number < 15");
               break;
        }
relational operators are not allowed as switch label.

Rule 12 : Macro Identifier are allowed as Switch Case Label.

#define MAX 2

switch(num)
       {
       case MAX:
               printf("Number = 2");
               break;
        }
as preprocessor will replace occurrence of MAX by constant value i.e 2 therefor it is allowed.

Rule 13 : Const Variable is allowed in switch Case Statement.

int const var = 2;

switch(num)
       {
       case var:
               printf("Number = 2");
               break;
        }

Thursday, July 23, 2015

Type Casting in C

Type casting is a way to convert a variable from one data type to another data type. For example, if you want to store a long value into a simple integer then you can type cast long to int. You can convert values from one type to another explicitly using the cast operator as follows:

(type_name) expression

Consider the following example where the cast operator causes the division of one integer variable by another to be performed as a floating-point operation:


#include
void main()

{   
           int sum = 17, count = 5;   
           double mean;   
           mean = (double) sum / count;   
           printf("Value of mean : %f\n", mean );
}

When the above code is compiled and executed, it produces the following result:

Value of mean : 3.400000

It should be noted here that the cast operator has precedence over division, so the value of sum is first converted to type double and finally it gets divided by count yielding a double value.
Type conversions can be implicit which is performed by the compiler automatically, or it can be specified explicitly through the use of the cast operator. It is considered good programming practice to use the cast operator whenever type conversions are necessary.

Tuesday, July 21, 2015

C Question Answer

Q1. Difference Between C and ansi C?

Ans.  After the development of C, it got really popular and practically became the default programming language. However, it was not working the same on various different platforms. C had been designed for the UNIX environment; hence, when run in many other platforms, some codes were returning errors. There was a need for a set of standards, which would allow the C programming language to work similarly on all platforms. Hence, the ANSI C was born.

ANSI C is a set of successive standards which were published by the American National Standards Institute (ANSI) for the C programming language. The ANSI specifies the syntax and semantics of programs written in C. It also specifies the C program's interactions with the platform via input and output data. Additionally, it also specifies restrictions and limits imposed upon conforming implementations of C language translators.


Q2. Difference between binary code and machine code?

Ans. Binary IS machine code. When you write a program in C, it's human readable, but not executable. A compiler will compile (translate) it to machine code, which is indeed executable. This machine code is sometimes called a "binary" as it is not human readable, but a stream of instructions for the processor in binary form.

Q3. What ansi stand for & who owes C?

Ans. American National Standards Institute (ANSI)


Q4. Difference between object file and executable file?

Ans. C is a compiled language so you need to translate the source code in a file that the computer can execute. This file is generated by the compiler and is called the object code ( .obj ), but a program like the "hello world" program is composed by a part that we wrote and a part of the C library. The linker links these two parts of a program and produces an executable file ( .exe ).