Professional Documents
Culture Documents
L25+L26
Lab Assessment 2
Name: Ajayjith.N.S
Reg.no:18BCE2332
Questions:
1. Write a c program to read multiple lines of a text as individual strings who's max length is unspecified
maintain a pointer to each string within a one dimensional array of pointers then determine the no. of vowels
consonants, digits ,white spaces and other characters of each line finally determine the avg no. Vowels per line
and consonants per line.
2. Write a c program to calculate no. of the days between two given dates.
Solutions:
1.
CODE:
#include <stdio.h>
int main() {
char line[150];
int vowels, consonant, digit, space;
vowels = consonant = digit = space = 0;
printf("Enter a line of string: ");
fgets(line, sizeof(line), stdin);
line[i] = tolower(line[i]);
if (line[i] == 'a' || line[i] == 'e' || line[i] == 'i' ||
line[i] == 'o' || line[i] == 'u') {
++vowels;
}
else if ((line[i] >= 'a' && line[i] <= 'z')) {
++consonant;
}
else if (line[i] >= '0' && line[i] <= '9') {
++digit;
}
else if (line[i] == ' ') {
++space;
}
}
return 0;
}
OUTPUT:
2.
CODE:
#include<stdio.h>
#include<stdlib.h>
int valid_date(int date, int mon, int year);
int main(void)
{
int day1, mon1, year1,
day2, mon2, year2;
if (mon2 == 3)
{
else
{
day2 += 28;
}
}
else
{
day2 += 31;
}
mon2 = mon2 - 1;
}
printf("Difference: %d years %02d months and %02d days.", year_diff, mon_diff, day_diff);
return 0;
}
if (mon == 2)
{
if (is_leap && day == 29)
{
is_valid = 1;
}
else if(day > 28)
{
is_valid = 0;
}
}
else
{
is_valid = 0;
}
}
else
{
is_valid = 0;
}
return is_valid;
}
OUTPUT: