codescracker


c

C Programming Examples



« C Tutorial Next Program »


Here, you can learn more than 100 C programming examples with output. It is important to go through these C programs to understand C programming practically.

You can learn here, from simplest C programs to shutdown your computer using C program.

C Program 1

Following is the simplest C program which will print "Hello Compiler, I am C" on the screen :

/* C Programming Examples - C Programs - C Examples */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();  // clear the screen
	printf("Hello Compiler, I am C");
	getch();  // output screen holds, until user press a key
}

When the above c program is compile and executed, it will produce the following result:

c programming examples with output

C Program 2

/* C Programming Examples */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	char name[20];
	printf("Enter Your Name : ");
	scanf("%s", name);
	printf("Hello, %s. You are at codescracker.com", name);
	getch();
}

The sample run of the above C program is shown here:

c programming examples with output

C Program 3

/* C Programming Examples */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	int no_star, no_row, i, j;
	printf("How many stars you want to print ? ");
	scanf("%d", &no_star);
	printf("Upto how many rows ? ");
	scanf("%d", &no_row);
	int p = no_star/no_row;
	for(i=0; i<no_row; i++)
	{
		for(j=0; j<p; j++)
		{
			printf("* ");
		}
		printf("\n");
	}
	getch();
}

The sample run of the above C program is shown here :

c programming examples

C Program 4

/* C Programming Examples */
		
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
	clrscr();
	char str[10];
	// answer in yes/no
	printf("Are you a programmer ? ");
	scanf("%s", str);
	if(!strcmp("yes", str))
	{
		printf("What a true mind you have..!!");
	}
	else
	{
		printf("Sorry..!!..You are telling a lie");
	}
	getch();
}

The sample run of the above C program in both cases is shown here. This is the first output:

c programs

This is second output:

c examples

C Program 5

/* C Programming Examples */
		
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
	clrscr();
	char pass[20];
	printf("Create a Password : ");
	scanf("%s", pass);
	int num1, num2, sum;
	printf("Enter the two number to Add : ");
	scanf("%d%d", &num1, &num2);
	char e_pass[20];
	printf("Enter password to watch the result : ");
	scanf("%s", e_pass);
	if(!strcmp(pass, e_pass))
	{
		sum = num1 + num2;
		printf("%d + %d = %d", num1, num2, sum);
	}
	else
	{
		printf("Sorry..!!..You entered wrong password");
	}
	getch();
}

The sample run of the above C program in both cases is shown here. This is first output:

c programs list

This is second one:

c all programs

C Program 6

/* C Programming Examples */
		
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
	clrscr();
	char arr[6][20] = {"programmer", "developer", "engineer",
			"student", "teacher", "professor",};
	char name[25];
	int found=0;
	printf("Who you are ? ");
	scanf("%s", name);
	for(int i=0; i<6; i++)
	{
		if(!strcmp(name, arr[i]))
		{
			printf("Congratulation..!!\n");
			printf("You are invited from codescracker.com.");
			found=1;
			break;
		}
		else
		{
			found++;
		}
	}
	if(found != 1)
	{
		printf("Sorry..!!..You are not invited");
	}
	getch();
}

The sample run of the above C program in both cases is shown here. This is first output:

c programs with output

This is second one:

c examples with output

This is third one:

c programming examples with explanation

Here is fourth one:

c programming code

Other Language Programming Examples

You may also like to go through these programming examples list in other languages:


« C Tutorial Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test