Programming in C Language
Programming in C Language
Programming in C Language
No6=. Write a program to call the number of vowels and consonants in each
word of a sentence.?
Coding=
#include <stdio.h>
#include <conio.h>
void main()
{
char str[100];
int i, vowel=0,consonant=0,space=0;
printf("Enter the string: ");
gets(str);//for taking string as an input from user...
for(i=0;str[i]!='\0';i++)
{
if (str[i]=='a'|| str[i]=='e'|| str[i]=='i'||str[i]=='o'||str[i]=='u')
{
vowel++; //for number of vowels...
}
else if(str[i]==' '){
space++; //for number of spaces
}
else
{
consonant=consonant+1; //for number of consonant..
}
}
printf("Number of vowels is :%d\n",vowel);
printf("Number of consonants is : %d",consonant);
}
Output=
No7=Write a program for addition and multiplication of two matrices.?
Coding=
#include<stdio.h>
#include<conio.h>
void main()
{
int r,c,a[100][100],b[100][100],sum[100][100],i,j;
printf("Enter number of rows (belween 1 and 100): ");
scanf("%d",&r);
printf("Enter number of columns (between 1 and 100): ");
scanf("%d",&c);
printf("\nEnter elements of 1st matrix:\n");
/* storing elements of first matrix entered by user.. */
for(i=0;i<r;++i)
for (j=0;j<c;++j)
{
printf("Entert elements a%d%d: ",i+1,j+1);
scanf("%d",&a[i][j]);
}
//storing elements of second matrix entered by user. */
printf("Enter elements od 2ad matrix;\n");
for(i=0;i<r;++i)
for(j=0;j<c;++j)
{
printf("Enter elements a%d%d: ",i+1,j+1);
scanf("%d",&b[i][j]);
}
/*Adding two matrices*/
for(i=0;i<r;++i)
for(j=0;j<c;++j)
sum[i][j]=a[i][j]+b[i][j];
/* Displaying the resultant sum matrix. */
printf("\nSum of two matrix is: /n/n");
for(i=0;i<r;++i)
for(j=0;j<c;++j)
{
printf("%d",sum[i][j]);
if(j==c-1)
printf("\n\n");
}
}
Output=
No8= Write a program to factorial of ane using rewastale.?
Coding=
#include<stdio.h>
#include<conio.h>
int fact(int num);
void main()
{
int num;
printf("enter number\n");
scanf("%d",&num);
printf("factorial of the given is %d",fact(num));
getch();
}
int fact(int num)
{
int f;
if (num==1)
return(1);
else
{
f=num*fact(num-1);
}
}
Output=