Pattern Codes, ABCDE Code, Arduino Code

Saturday, 14 January 2017

Repeated Number in Array

Repeated number in array:

Output:

 Enter the number in array 8
5
6
4
5
1
2
 8 5 6 4 5 1 2

 Repeated number is :: 5

Code:

#include<stdio.h>

int main()
{
int arr[20];
int arr2[20];
int n,count=0,i,j;
printf("\n Enter the number in array ");
for(i=0;i<=6;i++)
{ //input array elements
scanf("%d",&arr[i]);
}
for(i=0;i<=6;i++)
{ //print array elements
printf(" %d",arr[i]);
}
printf("\n Repeated number is :: ");
for(i=0;i<=6;i++)
{ //loop for checking the repeated elements
for(j=i+1;j<=6;j++)
{
if(arr[i] == arr[j])
{
printf("%d ",arr[i]);
}
}
}
}

Bubble Sorting

Bubble Sort
output:
 enter the elements in array
8
9
25
8
51
3
66
23
95
75

 Before Sorting  8 9 25 8 51 3 66 23 95 75


After Sorting  3 8 8 9 23 25 51 66 75 95
-----------------------------------------------------------------------------------------------------
#include<stdio.h>

int main()
{
int arr[20];
int i,j,n,temp = 0;
printf("\n enter the elements in array \n");
for(i=0;i<10;i++)
{
scanf("%d",&arr[i]);

printf("\n Before Sorting  ");
for(i=0;i<10;i++)
{
printf("%d ",arr[i]);
}
for(i=0;i<10;i++)
{
for(j=0;j<10-i-1;j++)
{
if(arr[j]>arr[j+1])
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1]=temp;
}
}
}
printf("\n\n");
printf("After Sorting  ");
for(i=0;i<10;i++)
{
printf("%d ",arr[i]);
}
 }

Reverse Right Angle Triangle Star Pattern

Reverse Right Angle Triangle Star Pattern

Output:

Enter the number of your choice5

*****
 ****
  ***
   **
    *

Code:

#include<stdio.h>

int main()
 {
int i,j,k, n;
printf("\n Enter the number of your choice");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(k=0;k<i;k++)
{
printf(" ");
}
for(j=n;j>i;j--)
{
printf("*");
}
printf("\n");
}
}

Star Triangle Pattern in C


Star Traingle Pattern in c

Output:

 Enter the number of your choice5
     *
    * *
   * * *
  * * * *
 * * * * *

Code:

#include<stdio.h>

int main()
  {
int i,j,k, n;
printf("\n Enter the number of your choice");
scanf("%d",&n);
for(i=0;i<n;i++)                        //outer loop for each row
{
for(k=n;k>i;k--)
{
printf(" ");                   //1st inner loop for space
}
for(j=0;j<i;j++)                   //2nd inner loop for printing star
{
printf("* ");
}
printf("\n");
}
}

To select prime number from array

To select prime number from array

Code:

// display prime number from array
#include<stdio.h>

int main()
{
int arr[20];
int n,i,j;
printf("\n Enter the values in array ");
for(i=0;i<=10;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<=10;i++)
{
printf("%d",arr[i]);
}
printf("\n PRIME NUMBERS IN ARRAY ARE :---");
for(i=0;i<=10;i++)
{
int flag = 0;
for(j=2;j<arr[i];j++)
{
if(arr[i]%j == 0)
{
flag = 1;
//printf("\n %d / %d",arr[i],j);
break;
}
}
if(flag == 0)
{
printf(" %d",arr[i]);
}
}
  }

Friday, 13 January 2017

Right Angle Star pattern in c

Right angle Star Pattern in C

Output:

 enter the number of your choice 5
*
**
***
****
*****
******

Code:
#include<stdio.h>

int main()
 {
int i,j,n;
printf("\n enter the number of your choice");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
for(j=0;j<=i;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}

ABCDE pattern in c

Print ABCDE pattern in c

Output:

ABCDEFGHGFEDCBA
ABCDEFGGFEDCBA
ABCDEFFEDCBA
ABCDEEDCBA
ABCDDCBA
ABCCBA
ABBA
AA

Code:

#include<stdio.h>

int main()
{ int i,j,k;
char ch = 'A';
char n;
printf("\n Enter the charachter of  your choice");
scanf("%c",&n);
k = n;
for(i = ch ;i<= n; i++)
{ ch = 'A';
for(j=n; j>=i; j--)
{ printf("%c",ch);
ch++;
}
if(k==n)
{ ch--;
for(k = n-2;k>=j;k--)
{ch--;
printf("%c",ch);
}
}
else
{for(k = n-1;k>=j;k--)
{ch--;
printf("%c",ch);
}
}
printf("\n");
}
}

Rolls Royce

Rolls Royce
Amazing Cars

About Me