STUDENTS 3K

  • Home
  • Students+
    • Engineering Students
    • Education Loan
    • Study Abroad Guide
    • Projects Download
  • Freshers
    • Aptitude Q & A
    • Placement Papers
    • Verbal Ability
    • Interview Questions
    • IT Company Details
    • Job Updates
  • Study Resources
    • Career Guidance
    • LAB Programs
      • C Programs
      • CPP Programs [C++]
      • Java Programs
    • Question Papers
    • Learn English
    • Notice Board
  • More –>>
    • Love calculator
You are here: Home / Important Programs / Pattern program in C [Star, Triangle, Number patterns code]

Pattern program in C [Star, Triangle, Number patterns code]

Pattern program in C source code: This program provides you a multiple patterns output for a single input. This can be a simple code to understand the patterns concept easily. It generates the star, numbers, triangle & diamond patterns in a while.

  • Binary search in c using arrays with example program
  • String operations in C with example

CREATE PATTERNS IN C

This C program is used to create a pattern for an entered number or stars like tree structure, diamond shape or triangle format by using many interior loops and nested loop statements and space to create a pattern format in a C program.

[Read: Software Company List] & [Placement papers download]

Patterns Program:

Q: How to write a C program to create a triangle, star, number & diamond patterns?

//Header files
#include<stdio.h>
#include<conio.h>

void main()
{
   //Program variables
   int cr2=0,cr=0,cr1=0,num,temp=0;

   clrscr(); //Function to clear previous output
   printf("Enter the Number:"); //Display function
   scanf("%d",&number); //Getting input function
   printf("Show the Pattern");
   for(cr=1;cr<=number;cr++) //Looping statement
   {
	for(cr1=1;cr1<=cr;cr1++) //Nested loop
	{
	       printf("%d",cr1);
	}
	printf("\n");
   }
   printf("\n Show the Pattern2\n");
   for(cr=1;cr<=number;cr++) //Outer for loop
   {
	for(cr1=1;cr1<=cr;cr1++) //Inner for loop
	{
	       printf("%d",cr);
	}
	printf("\n");
   }
   printf("\n Show the Pattern3\n");

   for(cr=1;cr<=number;cr++)
   {
	for(cr2=cr;cr2<=number;cr2++)
	{
		printf("");
	}
	for(cr1=1;cr1<=cr;cr1++)
	{
		  printf("%d",cr);
	}
	printf("\n");
   }
// © http://students3k.com
   printf("\n Show the Pattern4\n");

   for(cr=1;cr<=number;cr++)
   {
	for(cr2=cr;cr2<=number;cr2++)
	{
		printf("");
	}
	temp=0;
	for(cr1=1;cr1<=cr;cr1++)
	{
		if(cr1<((cr+1)/2)+1)
			temp++;
		else if(cr1==((cr+1)/2)+1)
			temp++;
		else
		       temp--;
		printf("%d",temp);
	}
	printf("\n");
   }
 getch();
}

Filed Under: Important Programs Tagged With: C, LAB, Programs





Random Materials :

  • Data Mining and Data Warehousing
  • Difference Between Class and Primitive Types
  • Database Roles in SQL
  • CASE Expression in SQL
  • Concurrent Update Problem

Follow Us on Facebook

Advertisement

Company Profile

  • About Students3k
  • Contact Us
  • Earn Money Online
  • Website Archive Page
  • Privacy Policy
  • Disclaimer

Categories

  • Important Programs
  • Study Abroad
  • IT Companies
  • Career Guidance for Students
  • Teachers
  • Verbal Analogies

We Are Social

  • Facebook Fans
  • Twitter Follow
  • Google Plus
  • Pinterest Page

© Copyright 2012 - 2016 Students3k.com · All Rights Reserved · Designed By Benefits

Show