Some Solutions

Prob-1.#include<stdio.h>

void main()
{
    int m1[10][10], m2[10][10],mult[10][10];
    int i,j,k,r1,c1,r2,c2;
    printf("Enter number of rows and columns of first matrix\n");
    scanf("%d %d", &r1, &c1);
    printf("Enter number of rows and columns of second matrix\n");
    scanf("%d %d",&r2, &c2);
    if(r2==c1)
    {
        printf("Enter first matrix\n");
        for(i=0;i<r1;i++)
            for(j=0;j<c1;j++)
                scanf("%d", &m1[i][j]);

        printf("Enter second matrix\n");
        for(i=0;i<r2;i++)
            for(j=0;j<c2;j++)
                scanf("%d", &m2[i][j]);

        printf("Multiplication of the Matrices:\n");
        for(i=0;i<r1;i++)
        {
            for(j=0;j<c2;j++)
            {
                mult[i][j]=0;
                for(k=0;k<r2;k++)
                    mult[i][j]+=m1[i][k]*m2[k][j];
                printf("%d\t",mult[i][j]);
            }
            printf("\n");
        }
    }
    else
    {
        printf("Matrix multiplication cannot be done");
    }
}




Prob-2.#include<stdio.h>

void main()
{
    int arr[] = {10,20,30,40,50};
    int i=0;
    int *p;
    p = arr;

    while(i<5)
    {
        printf("%d\n", *p);
        p++;
        i++;
    }
}



Prob-3.#include<stdio.h>

void main()
{
    char str[100];
    int i, space_count=0;
    gets(str);

    for(i=0; str[i] != '\0'; i++)
    {
        if( str[i] == ' ' )
        {
            space_count++;
        }
    }
    space_count++;
    printf("Total vowels: %d\n", space_count);
}




Prob-4.#include<stdio.h>

void main()
{
    char str[100];
    int i, vowel_count=0;
    gets(str);

    for(i=0; str[i] != '\0'; i++)
    {
        if( str[i] == 'a' ||
            str[i] == 'e' ||
            str[i] == 'i' ||
            str[i] == 'o' ||
            str[i] == 'u')
        {
            vowel_count++;
        }
    }
    printf("Total vowels: %d\n", vowel_count);
}



Prob-5.#include<stdio.h>
#include<string.h>

void main()
{
    char str[100], tmp[100];
   
    puts("enter string to check palindrom");
    gets(str);
    strcpy(tmp, str);
    strrev(tmp);
    if(strcmp(str, tmp) == 0)
        puts("palindrom");
    else
        puts("not palindrom");
}






No comments: