Labels

Showing posts with label C. Show all posts
Showing posts with label C. Show all posts

Thursday, December 24, 2015

To print the next character accepted from the user;

To print the next character accepted from the user;
#include
int main()
{
char a,b;
printf("Enter any character: ");
a= getchar();
int c=a;
int d=c+1;
printf("The alterante of character user entered is ");
b= putchar(d);
printf("\n");
return 0;
}

Print next character

To compile this program in Linux:
  1. Save this file with extension .c
  2. g++ compiler come pre installed in linux. Type this in terminal g++ alternate.c -o alternate. Here, I have assumed that the file name is alternate.c. -o array will provide me with an output file with extension exe file and name alternate.
  3. Now, run this file typing ./alternate and press enter.
To compile this program using cmd:
  1. Save this file with extension.c
  2. Type this in the cmd g++ alternate.c -o alternate.
  3. To run type alternate and press enter.
Note: To use g++ compiler in windows user has to install these compiler by itself as g++ compiler does not come per installed in windows operating system.



Wednesday, December 23, 2015

Largest of three numbers using Macro;

A C program to find the largest of three numbers using macro;

#include
#define CONDITION if (b>=97 && b<=122)\
printf("The character u entered is a small alphabet.\n");\
else\
{\
if(b>=65 && b<=112)\
printf("The character you entered is a large alphabet.\n");\
else\
printf("You have not entered a alphabet.\n");\
}
int main()
{
char a;
printf("Enter any character: ");
a= getchar();
int b= a;
CONDITION;
return 0;

}

Largest of three using Macro
















To compile this program in Linux:
  1. Save this file with extension .c
  2. g++ compiler come pre installed in linux. Type this in terminal g++ display.c -o display. Here, I have assumed that the file name is display.c. -o array will provide me with an output file with extension exe file and name display.
  3. Now, run this file typing ./display and press enter.
To compile this program using cmd:
  1. Save this file with extension.c
  2. Type this in the cmd g++ display.c -o display.
  3. To run type display and press enter.
Note: To use g++ compiler in windows user has to install these compiler by itself as g++ compiler does not come per installed in windows operating system.




Thursday, December 17, 2015

The largest of three numbers;

A C program to find the largest of three numbers;

#include <stdio.h>
int main()
{
int a,b,c;
printf("Enter first number ");
scanf("%d",&a);
printf("Enter second number ");
scanf("%d",&b);
printf("Enter third number ");
scanf("%d",&c);
if(a>b)
{
if(a>c)
printf("First is largest\n");
}
else
{
if(b>c)
printf("Second is largest\n");
else
printf("Third is largest\n");
}
return 0;
}
Largest of three number
Largest of three number

To compile this program in Linux:
  1. Save this file with extension .c
  2. g++ compiler come pre installed in linux. Type this in terminal g++ max.c -o max. Here, I have assumed that the file name is max.c. -o array will provide me with an output file with extension exe file and name max.
  3. Now, run this file typing ./max and press enter.
To compile this program using cmd:
  1. Save this file with extension.c
  2. Type this in the cmd g++ max.c -o max.
  3. To run type max and press enter.
Note: To use g++ compiler in windows user has to install these compiler by itself as g++ compiler does not come per installed in windows operating system.




Array of Prime number;

A C program to print array of prime numbers;

#include <stdio.h>
int main()
{
int n;
int arr[100];
printf("Enter the value of n: ");
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
if(i%2==0)
{
for(int j=0;j=i;j++)
{
arr[j]=i;
printf("Array: %d \n",arr[j]);
break;
}
}
}
return 0;
}

Array of prime numbers
Array of Prime numbers

To compile this program in Linux:
  1. Save this file with extension .c
  2. g++ compiler come pre installed in linux. Type this in terminal g++ array.c -o array. Here, I have assumed that the file name is array.c. -o array will provide me with an output file with extension exe file and name array.
  3. Now, run this file typing ./array and press enter.
To compile this program using cmd:
  1. Save this file with extension.c
  2. Type this in the cmd g++ array.c -o array.
  3. To run type array and press enter.
Note: To use g++ compiler in windows user has to install these compiler by itself as g++ compiler does not come per installed in windows operating system.


Monday, December 7, 2015

Notes C language


Powerpoint presentation of C language Notes:-
http://www.mediafire.com/view/pcv596358luurf3/C_by_Rahul_Kumar_Parihar.ppt
File Name: C by Rahul Kumar Parihar
File Size: 598kb

"Click on pic to download the best book for C programming.... If u really want otherwise ppt is good enough for basic learning."


C Book
C Book


Sum of prime numbers;

Sum of n prime numbers;

#include <stdio.h>
int main()
{
int n,sum=0;
printf("Enter the value of n(highest number): ");
scanf("%d",&n);
for (int i=0;i<=n;i++)
{
if(i%2==0)
{
sum=i+sum;
}
else
{
sum=sum;
}
}
printf("The sum of prime number: %d \n",sum);
return 0;

}

Sum of prime numbers
Sum of prime numbers




















To compile this program in Linux:

  1. Save this file with extension .c
  2. g++ compiler come pre installed in linux. Type this in terminal g++ primesum.c -o primesum. Here, I have assumed that the file name is primesum.c. -o fact will provide me with an output file with extension exe file and name fact.
  3. Now, run this file typing ./primesum and press enter.
To compile this program using cmd:

  1. Save this file with extension.c
  2. Type this in the cmd g++ primesum.c -o primesum.
  3. To run type primesum and press enter.
Note: To use g++ compiler in windows user has to install these compiler by itself as g++ compiler does not come per installed in windows operating system.

Sum of n numbers;

To find the sum of n numbers;

#include <stdio.h>
int main()
{
int n,sum=0;
printf("Enter value of n (the highest number): ");
scanf("%d",&n);
for (int i=0; i<=n; i++)
{
sum=i+sum;
}
printf("Sum of %d \n",sum);
return 0;
}
Sum of n numbers


To compile this program in Linux:

  1. Save this file with extension .c
  2. g++ compiler come pre installed in linux. Type this in terminal g++ sum.c -o sum. Here, I have assumed that the file name is sum.c. -o fact will provide me with an output file with extension exe file and name fact.
  3. Now, run this file typing ./sum and press enter.
To compile this program using cmd:

  1. Save this file with extension.c
  2. Type this in the cmd g++ sum.c -o sum.
  3. To run type sum and press enter.
Note: To use g++ compiler in windows user has to install these compiler by itself as g++ compiler does not come per installed in windows operating system.

Saturday, December 5, 2015

To find the factorial of a number using Recursion in C;

To find the factorial of a number using Recursion in C;

#include <stdio.h>
int fact(int a);
int main()
{
int n;
printf("Enter the value of n: ");
scanf("%d",&n);
int a=fact(n);
return 0;
}
int fact(int a)
{
int result;
if(a==1)
result =1;
result= fact(a-1)*a;
return result;
}

Recursion in C























To compile this program in Linux:

  1. Save this file with extension .c
  2. g++ compiler come pre installed in linux. Type this in terminal g++ fact.c -o fact. Here, I have assumed that the file name is fact.c. -o fact will provide me with an output file with extension exe file and name fact.
  3. Now, run this file typing ./fact and press enter.
To compile this program using cmd:

  1. Save this file with extension.c
  2. Type this in the cmd g++ fact.c -o fact.
  3. To run type fact and press enter.
Note: To use g++ compiler in windows user has to install these compiler by itself as g++ compiler does not come per installed in windows operating system.