Lab_DOC_Corrected
Lab_DOC_Corrected
printf(“\n”);
}
return 0;
}
20. Program to show sum of 10 elements of array & show the average.
#include<stdio.h> Output:
int main() enter elements of an array:
{ 4
int a[10],i,sum=0; 5
float av; 6
printf(“enter elements of an aaray: ”); 1
for(i=0;i<10;i++) 2
scanf(“%d”,&a[i]); 3
for(i=0;i<10;i++) 5
sum=sum+a[i]; 5
printf(“sum=%d”,sum); 4
av=sum/10; 7
printf(“average=%.2f”,av); sum=42
return 0; average=4.22
}
rewind(fp);
fp=fopen(“test.c”,”r”);
fp1=fopen(“tes.c”,”w”);
c=fgetc(fp);
while(c!=eof)
{
fputc(c,fp);
c=fgetc(fp);
}
fclose(fp);
fclose(fp1);
fp1=fopen(“tes.c”,”r”);
c=fgetc(fp1);
printf(“\nthe contents in file 2\n”);
while(c!=eof)
{
putchar(c);
c=fgetc(fp1);
}
fclose(fp1);
return 0;
}
34. Number Of Occurrences Of Vowels, Consonants, Words, Spaces And Special Characters In
The Given Statement.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
int main()
{
char s[100];
int vow=0,cons=0,spc=0,punc=0,l,i;
l=strlen(s);
for(i=0;i<l;i++)
{
if( isalpha(s[i]))
{
if(s[i]==’a’||s[i]==’e’||s[i]==’i’||s[i]==’o’||s[i]==’u’)
{ vow++;
}
else
{
cons++;
}
}
if(isspace(s[i])
{
spc++;
}
if(ispunct(s[i]))
{
punc++;
}
}
printf(“\nno.of words=%d”,spc+1);
printf(“\nno.of vowels=%d”,vow);
printf(“\nno.of consonants=%d”,cons);
printf(“\nno.of space=%d”,spc);
printf(“\nno.on special characters=%d”,punc);
return 0;
}
Output:
Enter the statement
*Nothing is impossible in the world.
No.of words=6
No.of vowels=10
No.of consonants=19
No.of space=5
No.of special characters=1
35. Write a program to create enumerated data type for 12 months. Display their values in
integer constants.
#include<stdio.h>
int main()
{
Enum month(Jan, Feb, Mar, Apr, May, June, July, Aug,Sep, Oct, Nov, Dec)
printf(“Jan=%d”, Jan);
printf(“Feb=%d”, Feb);
printf(“June=%d”, June);
printf(“Dec=%d”, Dec);
}
Output:
Jan =0
Feb=1
June=5
Dec=11
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100
11 22 33 44 55 66 77 88 99 110
12 24 36 48 60 72 84 96 108 120
printf(“\n”);
for(i=1; i<=n; ++i)
{
printf(“Enter roll number:”);
scanf(“%d”, &roll_number);
total=0;
printf(“Enter marks of %d subjects for ROLL NO”, m, roll number);
for(j=1; j<=m; j++)
{
scanf(“%d”, &marks);
total=total+marks;
}
printf(“TOTAL MARKS =%d”, total);
if(total>=FIRST)
printf(“(First division)”);
else if (total>=SECOND)
printf(“(Second division)”);
else
printf(“(***FAIL***)”);
}
}
Output:
Enter number of students and subjects 3 6
Enter roll_number: 8701
Enter marks of 6 subjects for ROLL NO 8701 81 75 83 45 61 59
TOTAL MARKS =404 (First division)
Enter roll_number:8702
Enter marks of 6 subjects for ROLL NO 8702 51 49 55 47 65 41
TOTAL MARKS =308(Second division)
Enter roll_number: 8704
Enter marks of 6 subjects for ROLL NO 8704 40 19 31 47 39 25
TOTAL MARKS=201(*** FAIL ***)
average=sum/(float)(m-1);
printf(“\n”);
printf(“Number of values =%d”,m-1);
printf(“sum=%f”, sum);
printf(“Average=%f”, average);
}
Output:
This program computes the average of a set of numbers
Enter values one after another
Enter a NEGATIVE number at the end
21 23 24 22 26 22 -1
Number of values =6
Sum= 138.000000
Average=23.000000
while(count<=100)
{
printf(“enter a number:”);
scanf(“%lf”, &number);
if(number==9999)
break;
if(number<0)
{
printf(“Number is negative ”);
negative++;
continue;
}
sqroot=sqrt(number);
printf(“Number=%lf square root=%lf ”, number, sqroot); count++;
}
printf(“Number of items done =%d”, count);
printf(“Negative items=%d”, negative);
printf(“END OF DATA”);
}
Output:
Enter 9999 to STOP
Enter a number:-9
Number is negative
Enter a number: 16
Number= 16.000000
Square root=4.000000
Enter a number: 80
Number=80.000000
Square root=8.944272
6. Given below is the list of marks obtained by a class of 50 students in an annual examination.
43 65 51 27 79 11 56 61 82 09 25 36 07 49 55 63 74 81 49 37 40 49 16 75 87 91 33 24 58 78
65 56 76 67 45 54 36 63 12 21 73 49 51 19 39 49 68 93 85 59
Write a program to count the number of students belonging to each of the following groups
of marks: 0-9,10-19,20 -29, ,100.
#include<stdio.h>
#define MAXVAL 50
#define COUNTER 11
void main()
{
float value [MAXVAL];
int i, low, high;
int group[COUNTER]={0,0,0,0,0,0,0,0,0,0,0};
for(i=0; i<MAXVAL; i++)
{
scanf(“%f”, &value[i]);
++group[(int)(value[i]/10)];
}
printf(“\n”);
printf(“GROUP RANGE FREQUENCEY”);
for(i=0; i<COUNTER; i++)
{
low=i*10;
if(i= =10)
high=100;
else
high=low+9;
printf(“%2d%3d to %3d%d”, i+1, low, high, group[i]);
}
}