Translate

Friday, 29 June 2012


The Father Of "C"Dennis Ritchie

Sir Dennis Ritchie Was the Invented 'C Programming' Language .



  Google
Cprogramming.......
C...

C Programming

               What is a programming language?--Human beings need language to communicate between them. Similarly to communicate with computers we need a programming language. All the events in life can be communicated to computers with the help of programming language. C is the basic of all programming language. Before the introduction of C we had only Machine level languages. C is just like any other communication Language.
                 If you learn C programming thoroughly you can easily learn other programming languages. To learn C we just need to know the syntax of C program only. i.e order in which we have to write the contents.This website is intended to introduce C programming to beginning programmers. Over several years of studying, I have noted a large number of students appear to have difficulty in grasping the fundamentals of C Language. So I am trying to explain them with the help of simple examples.
                This website will help you get a quick start with C programming. This website is a guide for the beginners and also for those who have little knowledge on C Programming fundamentals.
                 There are different types of programming languages such as Structure oriented, Object oriented etc. C is the most commonly used Structure oriented programming language. Compiler for some languages are developed using C only. With the help of this tutorial I am trying to explain all the basics of C.In order to successfully complete this tutorial, you won't need any prior knowledge of the C programming language. First of all I will start with the most basic concepts and take you up to the highest level of C programming including the usually intimidating concepts of structures, union,file, pointers and dynamic memory allocation,etc.
                 Once you have mastered C, you will find Object Oriented Language such as c++,java, etc are easy to learn.
So let's start our Journey.........


CONTROL STATEMENTS......

Csmartprogramming

example......



Definition of perfect number or What is perfect number? 

Perfect number is a positive number which sum of all positive divisors excluding that number is equal to that number. For example 6 is perfect number since divisor of 6 are 1, 2 and 3.  Sum of its divisor is
1 + 2+ 3 =6

Note: 6 is the smallest perfect number.

Next perfect number is 28 since 1+ 2 + 4 + 7 + 14 = 28
Some more perfect numbers: 496, 8128



Code 1:
1. C program to check perfect number
#include<stdio.h>
int main(){
  int n,i=1,sum=0;
  printf("Enter a number: ");
  scanf("%d",&n);
  while(i<n){
      if(n%i==0)
           sum=sum+i;
          i++;
  }
  if(sum==n)
      printf("%d is a perfect number",i);
  else
      printf("%d is not a perfect number",i);
  return 0;
}
Sample output:
Enter a number: 6
6 is a perfect number
Code 2:
1. C program to find perfect numbers
2. C perfect number code
3. Perfect number program in c language
#include<stdio.h>
int main(){
  int n,i,sum;
  int min,max;
  printf("Enter the minimum range: ");
  scanf("%d",&min);
  printf("Enter the maximum range: ");
  scanf("%d",&max);
  printf("Perfect numbers in given range is: ");
  for(n=min;n<=max;n++){
    i=1;
    sum = 0;
    while(i<n){
      if(n%i==0)
           sum=sum+i;
          i++;
    }
    if(sum==n)
      printf("%d ",n);
  }
  return 0;
}
Sample output:
Enter the minimum range: 1
Enter the maximum range: 20
Perfect numbers in given range is: 6
Code 3:
3. C program to print perfect numbers from 1 to 100
#include<stdio.h>
int main(){
  int n,i,sum;
 
  printf("Perfect numbers are: ");
  for(n=1;n<=100;n++){
    i=1;
    sum = 0;
    while(i<n){
      if(n%i==0)
           sum=sum+i;
          i++;
    }
    if(sum==n)
      printf("%d ",n);
  }
  return 0;
}
Output:
Perfect numbers are: 6 28

3. Wap to reverse a number in c
#include<stdio.h>
int main(){
    int num,r,reverse=0;
    printf("Enter any number: ");
    scanf("%d",&num);
    for(;num!=0;num=num/10){
         r=num%10;
         reverse=reverse*10+r;
    }
    printf("Reversed of number: %d",reverse);
    return 0;
}
Sample output:
Enter any number: 123
Reversed of number: 321

How to write power in c

#include<stdio.h>
int main(){
  int pow,num,i=1;
  long int sum=1;
  printf("\nEnter a number: ");
  scanf("%d",&num);
  printf("\nEnter power: ");
  scanf("%d",&pow);
  while(i<=pow){
            sum=sum*num;
            i++;
  }
  printf("\n%d to the power %d is: %ld",num,pow,sum);
  return 0;
}

Csmartprogramming