Showing posts with label C++. Show all posts
Showing posts with label C++. Show all posts
Wednesday, February 13, 2013

Pointers in C Language - Use of Pointers in C, How to create a pointer in C, C++


Pointers in C Language - Use of Pointers in C, How to create a pointer in C, C++

Pointers are nothing but a special variable which are hold the address of another variable or another pointer variable.
same like as a simple variable, a simple variable hold the value but a pointer hold the address.

Creating Pointer variables in C:- To create a pointer variable in C you should use the * sign before variable name.
Example

int *p1;
float * p2;
char *p3;


Initialize pointer variables in C:-

int *p1;
int x;
p1=&x;

Printing the value of a Pointer in C:-

int *p1,x=10;
p1=x;
printf("%d",*p1);

Program for checking a Number is Perfect Number or Not in C, Java and C#




Program for Checking a Number is Perfect Number or Not :-

Program in C :-

#include<stdio.h>
#include<conio.h>
void main()
{
int num,a,num2=0,num3;
printf("Enter a Number \n");
scanf("%d",&num);
num3=num;
while(num>0)
{
a=num%10;
num2=num2+a;
num=num/10;
}
if(num2==num3)
printf("Number is Perfect");
else
printf("Number is not Perfect");
getch();
}


Program in Java :-


public class TestNumber
{
public sttaic void main(String args[])
{
int num,a,num2=0,nu3;
System.out.println("Enter a Number");
Console con=System.console(System.in);
num=Integer.parseInt(con.readLine());
num3=num;
while(num>0)
{
a=num%10;
num2=num2+a;
num=num/10;
}
if(nun2==num3)
System.out.println("Number is Perfect");
else
System.out.println("Number is not Perfect");
}
}


Program in C# :-


public class Test
{
public static void Main()
{
int num,a,num2=0,num3;
Console.WriteLine("Enter a Number");
num=Integer.Parse(Console.ReadLine());
num3=num;
while(num>0)
{
a=num%10;
num2=num2+a;
num=num/10;
}
if(num2==num3)
Console.WriteLine("Number is Perfect");
else
Console.WriteLine("Number is not Perfect");
}
}

Program for Checking a number is Armstrong or not in C, Java and C#



Program for Checking a Number is Palindrome or Not :-

Program in C :-

#include<stdio.h>
#include<conio.h>
void main()
{
int num,a,num2=0,num3;
printf("Enter a Number \n");
scanf("%d",&num);
num3=num;
while(num>0)
{
a=num%10;
num2=num2+(a*a*a);
num=num/10;
}
if(num2==num3)
printf("Number is Armstrong");
else
printf("Number is not Armstrong");
getch();
}


Program in Java :-


public class TestNumber
{
public sttaic void main(String args[])
{
int num,a,num2=0,nu3;
System.out.println("Enter a Number");
Console con=System.console(System.in);
num=Integer.parseInt(con.readLine());
num3=num;
while(num>0)
{
a=num%10;
num2=num2+(a*a*a);
num=num/10;
}
if(nun2==num3)
System.out.println("Number is Armstrong");
else
System.out.println("Number is not Armstrong");
}
}


Program in C# :-


public class Test
{
public static void Main()
{
int num,a,num2=0,num3;
Console.WriteLine("Enter a Number");
num=Integer.Parse(Console.ReadLine());
num3=num;
while(num>0)
{
a=num%10;
num2=num2+(a*a*a);
num=num/10;
}
if(num2==num3)
Console.WriteLine("Number is Armstrong");
else
Console.WriteLine("Number is not Armstrong");
}
}

How to Check a number is Palindrome or Not in C, Java and C#


Program for Checking a Number is Palindrome or Not :-

Program in C :-

#include<stdio.h>
#include<conio.h>
void main()
{
int num,a,num2=0,num3;
printf("Enter a Number \n");
scanf("%d",&num);
num3=num;
while(num>0)
{
a=num%10;
num2=num2*10+a;
num=num/10;
}
if(num2==num3)
printf("Number is Palindrome");
else
printf("Number is not Palindrome");
getch();
}


Program in Java :-


public class TestNumber
{
public sttaic void main(String args[])
{
int num,a,num2=0,nu3;
System.out.println("Enter a Number");
Console con=System.console(System.in);
num=Integer.parseInt(con.readLine());
num3=num;
while(num>0)
{
a=num%10;
num2=num2*10+a;
num=num/10;
}
if(nun2==num3)
System.out.println("Number is Palindrome");
else
System.out.println("Number is not Palindrome");
}
}


Program in C# :-


public class Test
{
public static void Main()
{
int num,a,num2=0,num3;
Console.WriteLine("Enter a Number");
num=Integer.Parse(Console.ReadLine());
num3=num;
while(num>0)
{
a=num%10;
num2=num2*10+a;
num=num/10;
}
if(num2==num3)
Console.WriteLine("Number is Palindrome");
else
Console.WriteLine("Number is not Palindrome");
}
}

How to check a number is Even or Odd in C, Java and C#


Program for Check a Number is Even or Odd :-

Program for C :-

#include<stdio.h>
#include<conio.h>
void main()
{
int num;
printf("Enter a Number \n");
scanf("%d",&num);
if(num%2==0)
printf("Number is Even");
else
printf("Number is Odd");
getch();
}

Program in Java :-

public class TestNumber
{
public sttaic void main(String args[])
{
int num;
System.out.println("Enter a Number");
Console con=System.console(System.in);
num=Integer.parseInt(con.readLine());
if(num%2==0)
System.out.println("Number is Even");
else
System.out.println("Number is Odd");
}
}


Program in C# :-

public class Test
{
public static void Main()
{
int num;
Console.WriteLine("Enter a Number");
num=Integer.Parse(Console.ReadLine());
if(num%2==0)
Console.WriteLine("Number is Even");
else
Console.WriteLine("Number is Odd");
}
}


Data Types in C - List of Data Types in C Language



Data Types in C Language :-

C has a concept of "Data Types" which are used to define a variable before its use. A variable is hold the value for its define data type and in a variable the value which it holds can be change during the program life cycle.

C has the following built-in Data Types--
  • int 
  • float 
  • double
  • char
Data Types in C - List of Data Types in C Language

int :- The int Data Type is used to store the integer values positive and negative both. The range of numbers in int in C is -32768 to +32767.

float :- The float Data Type used to store the floating point values positive and negative both.

char :- The char Data Type is used to store a single character in a variable. 

double :- The double Data Type is used to store the floating point numbers into a variable but it range is just double from float.



First Program of C Language - Introduction Of C Language



First Program of C Language - Introduction Of C Language
C is a general purpose High Level Programming Language developed by Dennic Ritchie for the Unix Operating System in AT & T Bell Lab in 1972.C was given free with UNIX O/S.
All the Applications which are running on Unix Operating System are developed in C and the UNIX operating System also developed in C Language.

Features of C Language :-


  • Easy to Learn.
  • High Level Language with great support of Low Level Programming.
  • Structured Language.
  • Can be Compiled on various machines with different Compilers. 

Program of C Language - How to write a C Program.

#include<stdio.h>
#include<conio.h>
int main()
{
int x=10;
printf("Your value is =%d",x);

}

What is C - Introduction of C Language - First Program in C


What is C - Introduction of C Language - First Program in C

C is a general purpose High Level Programming Language that was originally developed by Dennic Ritchie for the Unix Operating System in AT & T Bell Lab in 1972. C was provide free with the UNIX OS.

All the Applications which are running on Unix Operating System are developed in C and the UNIX operating System also developed in C Language.

Features of C Language :-


  • Easy to Learn.
  • High Level Language with great support of Low Level Programming.
  • Structured Language.
  • Can be Compiled on various machines with different Compilers.