Monday, 10 November 2014

C Questions With Answers

C Questions
Q1. What is C language? Define in brief.
Q2. Write a program to input a string and determine it is Palindrome or not.
Q3. What is ASCII? Write a program to show the ASCII of ‘a’ to ‘z’.
Q4. What is Loop? Where it is applied? Write a program to print the following

*
***
*****
***
*
1
121
12321
121
1
54321
4321
21
1




Q5. What is Recursion? Write a Program to Calculate the factorial of a given number using recursion.




Ans 1.

C is one of the most widely used programming languages of all time, and C compilers are available for the majority of available computer architectures and operating systems. C is developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs. Like most imperative languages in the ALGOL tradition, C has facilities for structured programming and allows lexical variable scope and recursion, while a static type system prevents many unintended operations. Its design provides constructs that map efficiently to typical machine instructions, and therefore it has found lasting use in applications that had formerly been coded in assembly language, most notably system software like the Unix computer operating system.

Ans 2. 

#include<stdio.h>
void main()
{
        int i,j,tmp=0;
        char str[10];
        printf("Enter your string - ");
        gets(str);
        for(i=0;i=strlen(str)/2;i++)
        {
                   for(j=strlen(str)-1;j>0;j--)
                   {
                              if(str[j]==str[i])
                              {
                                        i=i+1;
                                        tmp=tmp+1;
                               }
                    }
         }
         if(tmp==strlen(str)/2)
         {
                          printf("palindrome string"); 
          }
          else
          {
                          printf("Not palindrome");
           }
}


Ans.3  We all know that computer can understand 0 and 1 but we humans use many character like numbers , alphabets  and special symbols. so the Question is that how computer understand it? Actually a program called compiler or interpreter change our language into some computer code. So here a new question in which code, answer a code called ASCII. A standard code which is acceptable all over the world. for ex. computer can't understand 'A' so there is a code for this 65 which is in binary 1000001. so now lets focus what is ASCII.

ASCIIAmerican Standard Code for Information Interchange, is a character-encoding scheme. Originally based on the English alphabet, it encodes 128 specified characters into 7-bit binary integers as shown by the ASCII chart on the right. The characters encoded are numbers 0 to 9, lowercase letters a to z, uppercase letters A to Z, basic punctuation symbols, control codes that originated with Teletype machines, and space. For example, lowercase j would become binary 1101010 and decimal 106.
ASCII codes represent text in computers, communications equipment, and other devices that use text. Most modern character-encoding schemes are based on ASCII, though they support many additional characters.
ASCII developed from telegraphic codes. Its first commercial use was as a 7-bit teleprinter code promoted by Bell data services. Work on the ASCII standard began on October 6, 1960, with the first meeting of the American Standards Association's (ASA) X3.2 subcommittee. The first edition of the standard was published during 1963, a major revision during 1967, and the most recent update during 1986. Compared to earlier telegraph codes, the proposed Bell code and ASCII were both ordered for more convenient sorting (i.e., alphabetization) of lists, and added features for devices other than teleprinters.
ASCII includes definitions for 128 characters: 33 are non-printing control characters (many now obsolete) that affect how text and space are processed and 95 printable characters, including the space (which is considered an invisible graphic).
The IANA prefers the name US-ASCII. ASCII was the most common character encoding on the World Wide Web until December 2007, when it was surpassed by UTF-8, which includes ASCII as a subset.
#include<stdio.h>
void main()
{
          int i;
          for(i=97;i<=122;i++)
          {
                      printf("%d=%c  ",i,i);
          }
          getch();
}

Ans 4.There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on.
Programming languages provide various control structures that allow for more complicated execution paths.
A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages.


No comments:

Post a Comment