Академический Документы
Профессиональный Документы
Культура Документы
Dr. V. Saravanan
(Associate Professor)
1
CERTIFICATE
This is to certify that the project entitled “ Building Various patterns Using Numbers and
Special Characters Using C-Language” is the bonafide work carried out by
Siva Surya Kumar Guntupalli (170040811) , T.Deep (170040841) , Telluri Vani Sai
Bhavani (170040860) , Tiragati Vishwanath (170040875) students of IⅠⅠ year
B.Tech, E.C.E dept, College of Engineering, K.L deemed to be University, in the Coding
Skilling for the academic year 2019-2020.
2
ACKNOWLEDGMENT
Our sincere thanks to Dr. V. Saravanan in the Lab for his outstanding support throughout
the project for the successful completion of the work.
Our sincere thanks to B. JOHN PHILIP, Course coordinator of Technical Proficiency &
Training-1 for supporting in successful completion of this project.
We express our gratitude to Mr. Ramesh Siddavatam, ELITE Head and Dr. SUMAN
MALOJI, Head of the Department for Electronics &Communication Engineering for
providing us with adequate facilities, ways and means by which we are able to complete this
term paper work.
We would like to place on record the deep sense of gratitude to the honourable Vice
Chancellor, K L deemed to be University for providing the necessary facilities to carry the
concluded term paper work.
Last but not the least, we thank all Teaching and Non-Teaching Staff of our department and
especially my classmates and my friends for their support in the completion of our project
work.
2 T. Deep (170040841)
3
CONTENTS
Content Page No
Abstract 5
Chapter 1: Introduction 6
Chapter 6: Conclusions 37
References 37
4
ABSTRACT
Normally the statements inside the loop body executes sequentially. But by
using loop control statements we can change the flow of execution of statements
inside the loop body. If we are exiting the loop body then all automatic and
local variables/objects which got created in loop's scope will be destroyed. If
programmer wants to perform "specific operation" multiple times then he uses a
loop. The "specific operation" should be kept inside the loop and are called
"controlled statements" or "body of a loop".
5
INTRODUCTION
6
C PROGRAMMING BASICS
• Header Files
• Main Function
• Comments in C
• Data Types in C
• Variables
• Input and Output
• For Loop
• While Loop
• Do-While Loop
• Conditional Statements
• Operators
• String Functions
• Numeric Functions
• Functions and Parameters
• Actual and Formal Parameters
• Arrays
• Structures
• Type def
• Pointers
• Call by Value
• Call by Reference
7
Explanation of Basics
➔ Header Files:
• The files that are specified in the include section is called as header file
• These are precompiled files that has some functions defined in them
➔ Main Program :
• From main function the flow goes as per the programmers choice.
➔ Comments in C:
➔ Data Types in C
8
–Arrays come under this category
➔ Variables
• Declaration
int a;
• Definition
<<varname>>=<<value>>;
a=10;
• Usage
<<varname>>
• Input
–scanf(“%d”,&a);
9
–Gets an integer value from the user and stores it under the name “a”
• Output
–printf(“%d”,a);
➔ For Loop
➔ While Loop
10
}
While(i!=0)
Output:
10 9 8 7 6 5 4 3 2 1
➔ Conditional Statements
if (condition)
{
stmt 1; //Executes if Condition is true
}
else
{
stmt 2; //Executes if condition is false
}
➔ switch(var)
{
case 1: //if var=1 this case executes
stmt;
break;
case 2: //if var=2 this case executes
stmt;
break;
default: //if var is something else this will execute
stmt;
}
➔ Operators
• Arithmetic (+,-,*,/,%)
•Relational (<,>,<=,>=,==,!=)
• Logical (&&,||,!)
11
• Bitwise (&,|)
• Assignment (=)
• Compound assignment(+=,*=,-=,/=, %=,&=,|=)
• Shift (right shift >>, left shift <<)
➔ String Functions
➔ Numeric Functions
• Syntax of function
Declaration section <<Returntype>> funname(parameter list);
Definition section <<Returntype>> funname(parameter list) {
body of the function
12
}
➔ Function Call
Funname(parameter);
Example:
#include<stdio.h>
void fun(int a); //declaration
int main() {
fun(10); //Call
}
void fun(int x) //definition {
printf(“%d”,x);
}
• Actual parameters are those that are used during a function call
• Formal parameters are those that are used in function definition and
function declaration
➔ Arrays:
13
• float a[5][5] is a two dimensional array. It can store 5x5 = 25 floating point numbers
• The bounds are a[0][0] to a[4][4]
➔ Structures
➔ Type def
14
➔ Pointers
15
➔ Call by Reference
16
PROBLEM IDENTIFICATION
There are various patterns in C language like star pattern, number patterns, and
character patterns. In the following C programs, the user can provide the number of
rows to print the pattern . These programs print various patterns of numbers. These
codes illustrate how to create various patterns using C programming. The C programs
involve usage of nested for loops (a for loop inside a for loop). A pattern of numbers,
star or characters is a way of arranging these in some logical manner or they may form
a sequence. Time complexity of a function (or set of statements) is considered as O(1)
if it doesn’t contain loop, recursion and call to any other non-constant time function.
Time Complexity of a loop is considered as O(n) if the loop variables is incremented /
decremented by a constant amount. For example following functions have O(n) time
complexity. Time complexity of nested loops is equal to the number of times the
innermost statement is executed. For example the following sample loops have O(n 2)
time complexity. Time complexity is the main drawback in implementing patterns in
c. To some extinct this can be reduced by implementing patterns in matrices
17
SOLUTION TO THE PROBLEM
PATTERN 1
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
PROGRAM:
#include<stdio.h>
int main()
{
int i,j,n,a=1;
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf("%d ",a);
a++;
}printf("\n");
}
}
PATTERN 2
1
21
321
4321
54321
PROGRAM:
#include<stdio.h>
int main()
{
int i,j,n,a=1;
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
18
printf("%d ",a-j);
}
a++;
printf("\n");
}
}
PATTERN 3
1
23
456
7 8 9 10
PROGRAM:
#include<stdio.h>
int main()
{
int i,j,n,a=1;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=n;j>0;j--)
{
if(j<=i)
{
printf("%d ",a);
a++;
}
else
printf(" ");
}printf("\n");
}
}
PATTERN 4
A
ba
CBA
dcba
EDCBA
19
PROGRAM
#include<stdio.h>
int main()
{
int i,j,n,a=64,b=96;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2!=0)
a=a+i;
else
b=b+i;
for(j=1;j<=i;j++)
{
if(i%2!=0)
{
printf("%c ",a);
a--;
}
else
{
printf("%c ",b);
b--;
}
}printf("\n");
}
}
PATTERN 5
z
ab
wxy
cdef
rstuv
ghijkl
mnopq
PROGRAM
#include<stdio.h>
int main()
{
int i,j,n,a=122,b=97,c=0,p;
scanf("%d",&n);
for(i=0;i<n;i++)
{
if(i%2==0&&i>0)
{
if(c==0)
{
21
a=a-i-2;
p=a;c=1;
}
else
{
a=p-i-1;
}
}
for(j=0;j<=i;j++)
{
if(i%2!=0)
{
printf("%c ",b);
b++;
}
else
{
printf("%c ",a);
a++;
}
}printf("\n");
}
}
PATTERN 6
*****
****
***
**
*
PROGRAM:
#include<stdio.h>
int main()
{
int i,j,n,a=0;
scanf("%d",&n);
for(i=n;i>=1;i--)
{
for(j=1;j<=n;j++)
{
if(j>a)
printf("* ");
else
printf(" ");
}a++;
printf("\n");
}
}
22
PATTERN 7
1
1*2
1*2*3
1*2*3*4
1*2*3*4*5
1*2*3*4
1*2*3
1*2
1
PROGRAM
#include<stdio.h>
int main()
{
int i,j,n,a,c=1;
scanf("%d",&n);
int k=(n*2)-1;
for(i=0;i<k;i++)
{a=1;
if(i!=0)
{
if(i<n)
c=c+2;
else
c=c-2;
}
for(j=0;j<c;j++)
{
if(j%2==0)
{
printf("%d",a);
a++;
}
else
printf("*");
}printf("\n");
}
}
PATTERN 8
1
32
654
10 9 8 7
15 14 13 12 11
23
PROGRAM
#include<stdio.h>
int main(){
int i,j,n,a=0,k;
scanf("%d",&n);
for(i=1;i<=n;i++)
{ k=a+i;
for(j=1;j<=i;j++)
{
printf("%d ",k);
k--;
}printf("\n");
a=a+i;
}
PATTERN 9
11 12 13 14 15
7 8 9 10
456
23
1
PROGRAM
#include<stdio.h>
int main()
{
int i,j,n,a,p;
scanf("%d",&n);
int k=(n*(n+1))/2;
for(i=n;i>=1;i--)
{ if(i==n)
{
a=k-i+1;
p=a;
}
else
{
a=a-i;
p=a;
}
for(j=i;j>=1;j--)
{
printf("%d ",p);
p++;
}printf("\n");
}
}
24
PATTERN 10
1
01
101
0101
10101
010101
1010101
01010101
PROGRAM:
#include<stdio.h>
int main()
{
int i,j,n;
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
if(i%2!=0&&j%2==0)
{
printf("0 ");
}
if(i%2!=0&&j%2!=0)
{
printf("1 ");
}
if(i%2==0&&j%2!=0)
{
printf("0 ");
}
if(i%2==0&&j%2==0)
{
printf("1 ");
}
}printf("\n");
}
}
PATTERN 11
10101
1010
101
10
1
PROGRAM:
#include<stdio.h>
int main()
{
int i,j,n;
scanf("%d",&n);
25
for(i=1;i<=n;i++)
{
for(j=n;j>=i;j--)
{
if(j%2!=0)
printf("1 ");
else
printf("0 ");
}printf("\n");
}
}
PATTERN 12
54321
1234
432
12
3
PROGRAM:
#include<stdio.h>
int main()
{
int i,j,n,a,b,k=-1;
scanf("%d",&n);
for(i=0;i<n;i++)
{
if(i%2==0)
k++;
a=n-k;
b=1;
for(j=n;j>i;j--)
{
if(i%2==0)
{
printf("%d ",a);
a--;
}
else
{
printf("%d ",b);
b++;
}
}printf("\n");
}
}
26
PATTERN 13
EDCBA
EDCB
EDC
ED
E
PROGRAM:
#include<stdio.h>
int main()
{
int i,j,n,k=65;
int a=k;
scanf("%d",&n);
a=a+n-1;
for(i=1;i<=n;i++)
{
for(j=n;j>=i;j--)
{
printf("%c ",a);
a--;
}printf("\n")
a=k+n-1;
}
}
PATTERN 14
*********
* *
* *
* *
*
PROGRAM
#include<stdio.h>
int main()
{
int i,j,n,a=1;
scanf("%d",&n);
int b=(2*n)-1;
for(i=1;i<=n;i++)
{
for(j=1;j<=(2*n)-1;j++)
{
if(i==1)
printf("*");
else
{
27
if(j==a||j==b)
printf("*");
else
printf(" ");
}
}a++;b--;
printf("\n");
}
}
PATTERN 15
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
PROGRAM
#include<stdio.h>
int main()
{
int i,j,n,a,q;
scanf("%d",&n);
int b=((2*n))/2;
a=b;q=a;
for(i=1;i<=n;i++)
{ int k=1;
for(j=1;j<=(2*n)-1;j++)
{
if(i==1)
{
if(j==a)
printf("%d",k);
else
printf(" ");
}
else
{
if((j==a||j==q+2)&&j<=b){
printf("%d",k);
k++;q=j;
28
}
else
printf(" ");
}
}a--;b++;
q=a;
printf("\n");
}
}
29
OUTPUTS:
PATTERN 1:
PATTERN 2:
30
PATTERN 3:
PATTERN 4:
31
PATTERN 5:
PATTERN 6:
32
PATTERN 7:
PATTERN 8:
33
PATTERN 9:
PATTERN 10:
34
PATTERN 11:
PATTERN 12:
35
PATTERN 13:
PATTERN 14:
36
PATTERN 15:
37
CONCLUSIONS:
REFERENCES:
▪ https :/ / www.tuto ri als poi n t.co m/cpro g rammi ng/ c_fo r_l oo
p.htm
35