C program without main function :
usually it is not possible and not even make sense to write a code without main function because program start executing from main. but for the sake of argument this can be done through MACROS.
i have not experienced...
Home » Archives for 2014
C Program for this Pattern
54321
4321
321
21
1
CODE :
#include <stdio.h>
int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=i;j>=1;j--)
...
C Program for this Pattern
12345
2345
345
45
5
CODE :
#include <stdio.h>
int main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=i;j<=5;j++)
...
C Program for this Patters
12345
1234
123
12
1
CODE :
#include <stdio.h>int main(){ int i, j; for(i=5;i>=1;i--) { for(j=1;j<=i;j++) ...
C Program for this Number Pattern
5
54
543
5432
54321
CODE:
int main()
{
int i,j;
for(i=5;i>=1;i--)
{
for(j=1;j<i;j++)
printf(" ");
for(j=5;j>=i;j--)
...
strcpy - String Copy
Code :
#include <stdio.h>
#include <stdlib.h>
void xstrcpy(char str[100],char str1[100]);
void main()
{
char arr[100],arr1[100];
printf("Enter string ");
gets(arr);
xstrcpy(arr,arr1);
}
void...
String to Lower Case
CODE :
#include<stdio.h>
void main()
{
int i=0,j=0, length;
char str[100];
printf("Enter string : ");
gets(str);
for(i=0; str[i]!='\0';i++)
{}
...
String to Upper Case Letters
code:
#include<stdio.h>
void main()
{
int i=0,j=0, length;
char str[100];
printf("Enter string : ");
gets(str);
for(i=0; str[i]!='\0';i++)
{}
...
Strcmp - String Compare
Program to compare two strings are equal or not.
Code :
#include <stdio.h>
#include <stdlib.h>
void stringcompare(char arr[100], char arr2[100]);
int main()
{
char arr[100], arr2[100];
stringcompare(arr,arr2);
}
void...
strchr - Character Occurrence
Code :
#include <stdio.h>
#include <stdlib.h>
char xstrchr(char arr[100]);
int main()
{
char arr[100];
xstrchr(arr);
}
char xstrchr(char arr[100])
{
char search_key;
printf("Enter...
string concatenation
#include <stdio.h>
#include <stdlib.h>
char stringcat(char arr[100],char arr2[100]);
int main()
{
char arr[100],arr2[100];
stringcat(arr,arr2);
}
char stringcat(char arr[100],char arr2[100])
{
int...
Strings Programs
In this page you will find programs of <string.h> library but without using built in functions...
Guessing game
The below code will generate a guessing game.
Logic :
Store a number in an variable.This will be the hidden number.If the user enters number which is greater or smaller then the hidden number then display an appropriate message.Limit the...
Teaase your Friends with this code
The following program will keep on printing the statement which is written in printf if the user is pressign any key you can send the .exe file of this code to your friends to fool them .
#include<stdio.h>
#include<conio.h>
void main()
{
char...
Write a C Program to print Hello world without using Semicolon
Semicolon is the statement terminator in compiler of C language. Our task is to write a piece of code to print Hello World! or any other line without using semicolons.
this can be done in the part of syntax which is free from bound of semicolons and...
C Program for Linear Search
The below code will perform linear search on an array.Linear search has a time complexity of O(n).
Logic: In linear search each element of the array is checked for target element one by one.
Code:
#include <stdio.h>
#include <conio.h>
void...
C Program for Second Maximum and Second Minimun in an One-Dimensional Array
There are two approaches to calculate maximum,minimum,second-maximum and second-minimum.
The first one is through sorting.You can sort the array in ascending or descending order and can get the required degree of number i.e max,min,etc.
The second approach...
C Program for Maximum and Minimun number in an One-Dimensional Array
The below code will find the maximum and minimum numbers in an array.
Logic: Use linear search to search for the max and min numbers.
Code:
#include <stdio.h>
#include <conio.h>
void main()
{
int i,size,max,min;
...
C Program for Sum of Numbers in an One-Dimensional Array
The below code will generate the sum of all the numbers stored in an 1D-Array.
Logic: Add all the numbers from index zero to the last index
Code:
#include <stdio.h>
#include <conio.h>
void main()
{
int i,sum;
...
C program for swapping of two Variables without using temporary variable
Logic:
To swap two variable we will add the both variables and store in first variable, then we will subtract second from first and store in second so we will get value of first variable in Second Variable. Then from...
C Program to tokenize a string using Strtok
Strtok is the built-in function of <String.h> header file.
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main ()
{
char input[100], *tokenptr;
int lenth,i=0,j,temp,count=0;
printf("Enter string to Tokenize...
C Program to tokenize a string Without using Strtok
Logic :
To tokenize a string without using strtok we will simply use assignment operator '='. The logic is that where the character is found (on basis of which you want to tokenize) place there a '\n' this will...
C program for swapping of two Variables
Logic:
we have two variables of type int say a and b. we want to shift the value of a into b and vice versa.
For this purpose we need another temporary variable say temp. we will shift value of a into temp. Then...
C program to Print Triangle
The below code prints a triangle of height 'h' taken from the user.
*
* *
* * *
* * * *
* * * * *
Code:
#include <stdio.h> #include <conio.h>void main(){ ...
Right Angle Triangle Checker C program
The below code checks whether a triangle is right angled or not by taking input the lengths of all three sides.
Logic: By Pythagoras theorem,
(hypotenuse)^2 = (base)^2+(perpendicular)^2
If the input data satisfies the above equation then...
Even-Odd Checker C program
The below code checks whether a number is even or odd using switch structure.
Logic:
If a number is divided by 2 and the remainder is zero then that number is an even number.
Code:
#include <stdio.h>#include <conio.h>void main(){ ...
C program for Simple Calculator using Switch Case Statement
The below code will create a simple calculator with the Switch structure;
Logic:
Each case is designed to work with a specific switch, in this case switches are the mathematical operators i.e " +, - , * , / , % (for remainder-modulus)...
C program for Sum of digits of a Number
The below code will calculate the sum of digits of an integer number.
Logic: An integer number like 54321 can be separated into digits by dividing it by 10.If 54321 is divided by 10 then we get remainder 1,and number becomes 5432,if we repeat this...
Prime Number - Checker C Program
The below code checks whether the entered number is prime or not.
Logic: Prime numbers are defined as the numbers which are only divisible by one or itself.
This can be checked by dividing the number from 2 to that number.If the number is divisible...
C program for simple Calculator
The below code will create a simple calculator with the use of if-else-if control structure.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,mod;
float x,y,sum,sub,mul,div;
...
C program to Print Right Angle Triangle
The below code prints a right angle triangle of height h taken from the user,
*
**
***
****
*****
Logic:...