Computer Concept & Programming In C - Unit III - 17

Q.36. Write a program that counts the total number of vowels in a given sentence.                                                                 (AKTU. 2010 - 11)
Ans.

#include<stdio.h>
#include<conio.h>
#include<string.h>
#define size 50
void main()
{
 char sent[size];
 int i, len, vow = 0;
 clrscr();
 printf("\nEnter the sentence.\n");
 gets(sent);
 len  = strlen(sent);
 for(i = 0; i < len; i++)
     if( (sent[i] == 'a')||(sent[i] == 'A')
||(sent[i] == 'e')||(sent[i] == 'E')
||(sent[i] == 'i')||(sent[i] == 'I')
||(sent[i] == 'o')||(sent[i] == 'O')
||(sent[i] == 'u')||(sent[i] == 'U') )
vow++;
 printf("\n The number of vowels in the sentence = %d", vow);
 getch();
 }

Q.37. Write a program in C to create a text file. Also copy the vowels in that file to another file.                                                                   (AKTU. 2012 - 13)
Ans.
#  include <stdio.h>
#  include <conio.h>
#  include <malloc.h>
void main ( )
{
int * p;
int i, n, pos, neg;
clrscr ( );
printf (“\ n Enter number of elements in array”);
scanf (“%d”, & n);
p = (int*) malloc (n*size of (int));
if (p == NULL)
printf (“\ n Required memory unavailable”);
else
{
printf (“\ n Enter the elements”);
for (i = 0; i < n; i++)
scanf (“%d”, (p+i));
pos = neg = 0;
for (i = 0; i < n; i++)
if (*(p+i) < 0)
neg ++;
if (*(p+i) > 0)
pos ++;
printf (“\n Total Number of  positive integers = % d”, pos);
printf (“\n Total Number of negative intergers = %d”, neg);
}
getch ( );
}
}

Q.38 Write a program in C that accept the length and width of a rectangle and print the area. The area of a rectangle and print the area. The area of a rectangle is calculated by a function and returns it value to main program where it is printed. The values of length and width of rectangle are accepted from the keyboard. Also give the flowchart and algorithm.                                                                                                                         (AKTU. 2010-11)
Ans.
#include<stdio.h>
#include<conio.h>
float area(float, float);
void main()
{
  float length, width, ar;
  clrscr();
  printf("\nEnter length\n");
  scanf("%f",&length);
  printf("\nEnter width\n");
  scanf("%f",&width);
  ar = area(length, width);
  printf("\n AREA = %f", ar);
  getch();
}
float area(float p, float q)
{
  return (p * q);
}