Showing posts with label array concept. Show all posts
Showing posts with label array concept. Show all posts

Friday 5 July 2013

Q.Write a program to find palindrome string using string functions.

Program:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    char a[30];
    int b,c=0,i=0,j;
    clrscr();
    printf("Enter the String:");
    scanf("%s",a);
    b=strlen(a);
    j=b-1;
    while(a[i]==a[j])
    {
        ++c;
        ++i;
        --j;
    }
    if(c==b)
        printf("\nString is Palindrome");
    else
        printf("\nString is not a palindrome");
    getch();
}


Sample Output:

    

Note: 
 " Hi I am a Learner of C/C++. I have done this program with my own Knowledge. There may be an easy way to solve this program. So I am sorry if this program in your point of view is too long. "

Thursday 27 June 2013

Q. Write a C program to generate pascal triangle or Write a C program to print following number triangle :







1






1
1




1
2
1


1
3
3
1
1
4
6
4
1

Solution:

#include<stdio.h>
#include<conio.h>

void main()
{
    int a,b,i,j,d[30],t[30];
    clrscr();
    printf("Enter the max limit:");
        scanf("%d",&a);
    b=a;
    for(i=0;i< a;i++)
    {

//Initialisation..
        t[0]=1; t[i]=1;
d[0]=1;

//Spacing..
        for(j=0;j< b-1;j++)
            printf(" ");
        b--;

//Calculation..
        for(j=1;j<=i;j++)
        {
        d[j]=t[j-1]+t[j];
        }
        d[i]=1;

//Printing..
        for(j=0;j<=i;j++)
        {
            printf("%d ",d[j]);
            t[j]=d[j]; //Restoring temporary Array..
        }

        printf("\n");
    }
getch();
}


Sample Output:





Note: 
 " Hi I am a Learner of C/C++. I have done this program with my own Knowledge. There may be an easy way to solve this program. So I am sorry if this program in your point of view is too long. "


Thursday 20 June 2013

Q.Write a Program to perform array multiplication( C programming).

Array Multiplication:
Solution:
#include<conio.h>
#include<stdio.h>

void main()
{
    int a[25][25],b[25][25],c[25][25],i,j,m,n,o,k;
    clrscr();
    printf("\nEnter row & column in A:\n");
        scanf("%d\n%d",&m,&n);
    printf("\nEnter the column value in B:\n");
        scanf("%d",&o);
    printf("\nEnter %d*%d value of A\n",m,n);
    for(i=0; i< m; i++)
        for(j=0; j< n; j++)
            scanf("%d",&a[i][j]);
    printf("\nEnter %d*%d value of B\n",n,o);
    for(i=0; i< n; i++)
        for(j=0; j< o; j++)
            scanf("%d",&b[i][j]);
    printf("\nA values:\n");
    for(i=0; i< m; i++)
    {
        for(j=0; j< n; j++)
            printf("%d\t",a[i][j]);
        printf("\n");
    }
    printf("\nB values:\n");
    for(i=0; i< n; i++)
    {
        for(j=0; j< o; j++)
            printf("%d\t",b[i][j]);
        printf("\n");
    }

    for(i=0; i< m; i++)
        for(k=0; k< o; k++)
        {
            c[i][k]=0;
            for(j=0; j< n; j++)
            {
            c[i][k]=c[i][k]+a[i][j]*b[j][k];
            }
        }
    printf("\nC values:\n");
    for(i=0; i< m; i++)
    {
        for(j=0; j< o; j++)
            printf("%d\t",c[i][j]);
        printf("\n");
    }
getch();
}

Sample Output:




Note: 
 " Hi I am a Learner of C/C++. I have done this program with my own Knowledge. There may be easy way to solve this programs. So I am sorry if this program in your point of view is too long. "

Q. Write a program to get two different array values , merge them and finally produce the ascending order sorting of the result. (array Concept)-C programming

Array Concept: 
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
    int a[25],b[25],n,g=0,m,i,j,c,temp;
    clrscr();
    printf("Enter the number of a: ");
        scanf("%d",&n);
    printf("\nEnter the no of b: ");
        scanf("%d",&m);
    printf("\nEnter a values\n");
    for(i=1; i<=n ; i++)
        scanf("%d",&a[i]);
    printf("\nEnter b values\n");
    for(j=1; j<=m ; j++)
    {
        scanf("%d",&b[j]);
        a[i]=b[j];
        i++;
    }
    printf("\nMerged values:\n");
    c=n+m;
    for(i=1; i<=c; i++)
        printf("%d\t",a[i]);
    while(g < c)
    {
        for(i=1; i<=c; i++)
            if(a[i]>a[i+1])
            {
                temp=a[i];
                  a[i]=a[i+1];
                  a[i+1]=temp;
            }
            else
                a[i]=a[i];
    ++g;
    }
    printf("\nSorted Values:\n");
    for(i=1; i<=c; i++)
        printf("%d\t",a[i]);
getch();
}

Sample Output:



Note: 
 " Hi I am a Learner of C/C++. I have done this program with my own Knowledge. There may be easy way to solve this programs. So I am sorry if this program in your point of view is too long. "

Popular Posts