Saturday, 13 December 2014

C program to print patterns of stars

#include <stdio.h>
 
int main()
{
   int row, c, n, temp;
 
   printf("Enter the number of rows in pyramid of stars you wish to see ");
   scanf("%d",&n);
 
   temp = n;
 
   for ( row = 1 ; row <= n ; row++ )
   {
      for ( c = 1 ; c < temp ; c++ )
         printf(" ");
 
      temp--;
 
      for ( c = 1 ; c <= 2*row - 1 ; c++ )
         printf("*");
 
      printf("\n");
   }
 
   return 0;
}

output = 
    *
   ***
  *****
 *******
*********

Saturday, 11 October 2014

C Aptitude Questions and Answers


Predict the output or error(s) for the following:

1.     void main()

{


}

Answer:

Compiler error: Cannot modify a constant value. Explanation:

p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".



2. What is the output of this C code?
  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int k = 0;
  5.         for (k < 3; k++)
  6.         printf("Hello");
  7.     }
a) Compile time error
b) Hello is printed thrice
c) Nothing
d) Varies
Answer:a
3. What is the output of this C code?
  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         double k = 0;
  5.         for (k = 0.0; k < 3.0; k++)
  6.             printf("Hello");
  7.     }
a) Run time error
b) Hello is printed thrice
c) Hello is printed twice
d) Hello is printed infinitely
Answer:b


Monday, 29 September 2014

Dennis Ritchie

Dennis Ritchie (September 9, 1941 – c. October 12, 2011) was an American computer scientist and winner, with Kenneth Thompson, of the 1983 Turing Award. He created the C programming language and, with Thompson, the Unix operating system, which have had pervasive and lasting influence on subsequent programming languages and operating systems.

library file in c


Every C program uses libraries, which give the ability to execute necessary functions.
 For example, the most basic function called printf, which prints to the screen, is defined in the stdio.h header file.
To add the ability to run the printf command to our program, we must add following include derivative to our first line of the code:
 #include<stdio.h>

Sunday, 28 September 2014

My first c program


 #include<stdio.h>
 int main()

 {

  printf(“Hello World\n”);

  return 0;

 }
output= Hello World
 

history of c language

In computing, C (/ˈsiː/, as in the letter C) is a general-purpose programming language initially developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs.[5][6] 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.[7]
C is one of the most widely used programming languages of all time,[8][9] and C compilers are available for the majority of available computer architectures and operating systems.
Many later languages have borrowed directly or indirectly from C, including D, Go, Rust, Java, JavaScript, Limbo, LPC, C#, Objective-C, Perl, PHP, Python, Verilog (hardware description language),[4] and Unix's C shell. These languages have drawn many of their control structures and other basic features from C. Most of them (with Python being the most dramatic exception) are also very syntactically similar to C in general, and they tend to combine the recognizable expression and statement syntax of C with underlying type systems, data models, and semantics that can be radically different. C++ and Objective-C started as compilers that generated C code; C++ is currently nearly a superset of C,[10] while Objective-C is a strict superset of C.[11][12][13]
Before there was an official standard for C, many users and implementors relied on an informal specification contained in a book by Dennis Ritchie and Brian Kernighan; that version is generally referred to as "K&R" C. In 1989 the American National Standards Institute published a standard for C (generally called "ANSI C" or "C89"). The next year, the same specification was approved by the International Organization for Standardization as an international standard (generally called "C90"). ISO later released an extension to the internationalization support of the standard in 1995, and a revised standard (known as "C99") in 1999. The current version of the standard (now known as "C11") was approved in December 2011.[14]