Advanced Programming Lab
Advanced Programming Lab
SOURCE CODE:
#include<stdio.h>
void multiply(int mat1[12][12],int mat2[12][12],int ,int ,int );
void main()
{
int mat1[12][12],mat2[12][12];
int i,j,k,m,n,p;
printf("Enter the number of rows and columns for 1st matrix\n");
scanf("%d%d",&m,&n);
printf("Enter the elements of the 1st matrix\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&mat1[i][j]);
}
}
//no of col of 1st mat = no of rows of 2nd mat
printf("Enter the number of columns for 2nd matrix\n");
scanf("%d",&p);
printf("Enter the elements of the 2nd matrix\n");
for(i=0;i<n;i++)
{
for(j=0;j<p;j++)
{
scanf("%d",&mat2[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",mat1[i][j]);
}
printf("\n");
}
printf("The 2nd matrix\n");
for(i=0;i<n;i++)
{
for(j=0;j<p;j++)
{
printf("%d\t",mat2[i][j]);
}
printf("\n");
}
multiply(mat1,mat2,m,n,p);
}
{
for(j=0;j<p;j++)
{
printf("%d\t",mul[i][j]);
}
printf("\n");
}
}
INPUT:
Enter the number of rows and columns for 1st matrix
2
2
Enter the elements of the 1st matrix
1234
Enter the number of columns for nd matrix
2
Enter the elements of the 2nd matrix
5 678
3
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
OUTPUT:
RESULT: Hence,the c program for multiply two Matrices by Passing Matrix to a Function
is executed successfully.
4
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
SOURCE CODE:
#include<stdio.h>
int main()
{
char str[150];
int i, j;
printf(“\nEnter a string : “);
gets(str);
for(i = 0; str[i] != ‘\0’; ++i)
{
while (!( (str[i] >= ‘a’ && str[i] <= ‘z’) || (str[i] >= ‘A’ && str[i] <= ‘Z’) || str[i] == ‘\0’) )
{
for(j = i; str[j] != ‘\0’; ++j)
{
str[j] = str[j+1];
}
str[j] = ‘\0’;
}
}
printf(“\nResultant String : “);
puts(str);
return 0;
}
INPUT:
OUTPUT:
RESULT: Hence the C program to remove all charcaters in a string except alphabet is
executed successfuly.
5
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
AIM: To write a C Program to Add Two Complex Numbers by Passing Structure to a Function.
SOURCECODE:
#include <stdio.h>
typedef struct complex{
float real;
float imag;
} complex;
complex addition(complex num1, complex num2);
int main(){
complex num1, num2, value;
printf("entering real and imag parts of first complex no:\n ");
scanf("%f %f", &num1.real, &num1.imag);
printf("entering real and imag parts of second complex no:\n ");
scanf("%f %f", &num2.real, &num2.imag);
value= addition(num1, num2);
printf("result = %.1f + %.1fi", value.real, value.imag);
return 0;
}
complex addition(complex num1, complex num2){
complex temp;
temp.real = num1.real + num2.real;
temp.imag = num1.imag + num2.imag;
return (temp);
}
INPUT:
entering real and imag parts of first complex no:2.0 3.0
entering real and imag parts of second complex no:4.0 6.0
OUTPUT:
entering real and imag parts of first complex no:2.0 3.0
entering real and imag parts of second complex no:4.0 6.0
result = 6.0 + 9.0i
RESULT: Hence, the C program to add two complex number by passing structure to
function is executed successfully.
6
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
Exp No:4 Storing student records as structures and sort them by Date:08/02/2022
name
AIM: To write a C program to store student records as structures and sort them by name
SOURCE CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student {
int student_id;
char* student_name;
int student_percentage;
};
int comparator(const void* s1, const void* s2){
return strcmp(((struct Student*)s1)->student_name,((struct Student*)s2)->student_name);
}
int main() {
int n = 5;
struct Student arr[n];
//student 1
arr[0].student_id = 1;
arr[0].student_name = "Uday";
arr[0].student_percentage = 98;
//student 2
arr[1].student_id = 2;
arr[1].student_name = "Manasa";
arr[1].student_percentage = 75;
//student 3
arr[2].student_id = 3;
arr[2].student_name = "Thanuja";
arr[2].student_percentage = 62;
//student 4
arr[3].student_id = 4;
arr[3].student_name = "Mounish";
arr[3].student_percentage = 87;
//student 5
arr[4].student_id = 5;
arr[4].student_name = "Manognal";
arr[4].student_percentage = 80;
printf("Unsorted Student Record:\n");
7
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
INPUT:
OUTPUT:
RESULT: Hence, the C program to store student records as structures and sort them by
name is executed successfully.
8
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
AIM: To write a C program to find the number of non repeated elements in an array.
SOURCE CODE:
}
printf("\n The array after removing duplicates is: " );
for (i = 0; i < size; i++)
{
printf(" %d" , array[i]);
}
return 0;
}
INPUT:
Enter size of the array: 6
Enter 6 elements of an array: 12
10
4
10
12
56
OUTPUT:
RESULT: Hence, the C program to find the number of non repeated elements in an array is
executed successfully.
10
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
Exp No:6 Finding two Elements in the Array such that Date:08/02/2022
Difference between them is Largest
AIM: To write a C program to find two elements in the array such that difference between
then is largest.
SOURCE CODE:
#include<stdio.h>
#define N 6
int main()
{
int num[N], i, big, small;
return 0;
}
11
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
INPUT:
Enter 6 integer numbers
8
10
6
7
14
1
OUTPUT:
RESULT: Hence, the C program to find two Elements in the array such that difference
between them is larges.t
12
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
Exp No:7 Finding the two Elements such that their Sum is Date:15/02/2022
Closest to Zero
AIM: TO write a C program to find the two elements such that their sum is closest to zero.
SOURCE CODE:
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
/* Initialization of values */
min_l = 0;
min_r = 1;
min_sum = array[0] + array[1];
for (l = 0; l < array_size - 1; l++)
{
for (r = l + 1; r < array_size; r++)
{
sum = array[l] + array[r];
if (abs(min_sum) > abs(sum))
{
min_sum = sum;
min_l = l;
min_r = r;
}
}
}
printf(" The two elements whose sum is minimum are %d and %d", array[min_l],
array[min_r]);
13
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
int main()
{
int array[] = {42, 15, -25, 30, -10, 35};
minabsvaluepair(array, 6);
getchar();
return 0;
}
Output:
RESULT: Hence, the C program to find the two elements in an array whose sum is closest
to zero is executed successfully.
14
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
SOURCE CODE:
include<stdio.h>
void printUnion(int arr1[], int arr2[], int len1, int len2)
{
int f, i, j, k = 0;
int arr3[100];
if (f == 0) {
arr3[k] = arr2[i];
k++;
}
}
printf("Union of two array is:");
for (i = 0; i < k; i++)
{
printf("%d ", arr3[i]);
}
}
int arr3[100];
int i, j, k = 0;
int main() {
int arr1[100];
int arr2[100];
int arr3[100];
int i, j, len1, len2;
return 0;
}
INPUT:
Output:
RESULT: Hence, the C program to find the Union and Intersection of 2 arrays is executed
successfully.
17
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
Exp No:9 Interchange any two Rows & Columns in the given Date:15/02/2022
Matrix
AIM: To write a C Program to Interchange any two Rows & Columns in the given Matrix
SOURCE CODE:
#include <stdio.h>
void main()
{
static int array1[10][10], array2[10][10];
int i, j, m, n, a, b, c, p, q, r;
{
r = array2[i][p - 1];
array2[i][p - 1] = array2[i][q - 1];
array2[i][q - 1] = r;
}
printf("The matix after interchanging the two rows(in the original matrix) \n");
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
printf(" %d", array1[i][j]);
}
printf("\n");
}
printf("The matix after interchanging the two columns(in the original matrix) \n");
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
printf(" %d", array2[i][j]);
printf("\n");
}
}
INPUT:
OUTPUT:
RESULT: Hence, the C Program to Interchange any two Rows & Columns in the given Matrix is
exectuted successfully.
20
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
AIM: To write a C program to sort rows of the matrix in Ascending & Columns in Descending Order.
SOURCE CODE:
#include <stdio.h>
void main()
{
static int array1[10][10], array2[10][10];
int i, j, k, a, m, n;
a = array1[i][j];
array1[i][j] = array1[i][k];
array1[i][k] = a;
}
}
}
}
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
printf(" %d", array1[i][j]);
}
printf("\n");
}
printf("After arranging the columns in descending order \n");
for (j = 0; j < n; ++j)
{
for (i = 0; i < m; ++i)
{
for (k = i + 1; k < m; ++k)
{
if (array2[i][j] < array2[k][j])
{
a = array2[i][j];
array2[i][j] = array2[k][j];
array2[k][j] = a;
}
}
}
}
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
printf(" %d", array2[i][j]);
}
printf("\n");
}
}
22
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
INPUT:
OUTPUT:
Enter the order of the matrix
33
Enter co-efficients of the matrix
379
248
526
The given matrix is
379
248
526
After arranging rows in ascending order
379
248
256
After arranging the columns in descending order
579
348
226
RESULT: Hence, the C program to sort rows of the matrix in ascending & columns in descending order.
23
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
Exp No:11 Creating a file, open it, type-in some characters and Date:19/02/2022
count the number of characters in a file
AIM: To create a file, open it, type-in some characters and count the number of characters in a file using C
program.
SOURCE CODE:
#include <stdio.h>
#define MAX_FILE_NAME 100
int main()
{
FILE* fp;
char filename[MAX_FILE_NAME];
24
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
return 0;
}
INPUT:
RESULT: Hence, by using C program to create a file, open it, type-in some characters and
count the number of characters in a file is successfully executed.
25
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
SOURCE CODE:
#include <stdio.h>
void main()
{
int i, j, r, c, array[10][10];
printf("Enter the r and c value:");
printf("matrix is");
for (i = 1; i <= r; i++)
{
for (j = 1; j <= c; j++)
{
printf("%d", array[i][j]);
}
printf("\n");
}
else
{
printf("\t");
}
}
printf("\n\n");
for (i = 1; i <= r; i++)
{
printf("\n");
for (j = 1; j <= c; j++)
{
if (j >= i)
{
printf("%d", array[i][j]);
}
else
{
//printf("\t");
}
// printf("\n");
}
}
INPUT:
Enter the r and c value:3 3
array[1][1] = 1 1 1
array[1][2] = array[1][3] = array[2][1] = 1 1 0
array[2][2] = array[2][3] = array[3][1] = 2 0 0
27
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
OUTPUT:
Enter the r and c value:3 3
array[1][1] = 1 1 1
array[1][2] = array[1][3] = array[2][1] = 1 1 0
array[2][2] = array[2][3] = array[3][1] = 2 0 0
array[3][2] = array[3][3] = matrix is
111
110
200
1
11
200
RESULT: Hence, to write a C program to display the upper triangle of a given matrix is
executed successfully
28
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
SOURCE CODE:
#include <stdio.h>
#include <ctype.h>
void main()
char sentence[100];
sentence[i] = '\0';
count = i;
putchar(ch);
29
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
}
printf("\n\n");
}
INPUT:
Enter the sentence: KeeRtHikA
OUTPUT:
Enter the sentence : KeeRtHikA
Case changed sentence is:kEErThIKa
Result: Hence,to write a C program to replace lowercase characters by uppercase & vice-
versa is executed successfully.
30
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
SOURCE CODE:
#include <stdio.h>
#include <string.h>
void main()
{
int i, j = 0, k = 0, x, len;
char str[100], str1[10][20], temp;
str1[i][x] = temp;
}
INPUT:
OUTPUT:
RESULT: Hence, the C program to reverse every word of the string is executed successfully.
32
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
SOURCE CODE:
#include <stdio.h>
#include <string.h>
int main()
{
char s[1000],temp=1,c='*';
int i,j,k=0,n;
}
}
for(i=0;s[i];i++)
{
s[i]=s[i+k];
if(s[i]==c)
{
k++;
i--;
}
}
33
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
printf("%s",s);
return 0;
}
INPUT:
OUTPUT:
Enter the string: do good be good
String after removing all duplicates: do be
Result: Hence to write a C program to delete all repeated words from a string is successfully
executed.
34
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
SOURCE CODE:
#include <stdio.h>
#include <string.h>
int main()
{
char s[1000];
int a[1000],i,j,k=0,count=0,n;
for(j=0;s[j];j++);
n=j;
for(i=0;i<n;i++)
{
a[i]=0;
count=1;
if(s[i])
{
for(j=i+1;j<n;j++)
{
if(s[i]==s[j])
{
count++;
s[j]='\0';
}
}
}
a[i]=count;
if(count>=k)
k=count;
35
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
}
printf("maximum occuring characters ");
for(j=0;j<n;j++)
{
if(a[j]==k)
{
printf(" '%c',",s[j]);
}
}
INPUT:
OUTPUT:
Enter the string: do good be good
maximum occurring characters 'o'=5 times
RESULT:
Hence the C program to find highest frequency character in a string is successfully executed.
36
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
AIM: To write a C program to display every possible combination of two characters from
the input word without repeated combinations.
SOURCE CODE:
#include <stdio.h>
#include <string.h>
void main()
{
int i, j = 0, k, k1 = 0, k2 = 0, row = 0;
char temp[50];
char str[100], str2[100], str1[5][20], str3[6][20], str4[60][40];
row = 0;
for (i = 0;i <= k1;i++)
{
for (j = 0;j <= k2;j++)
{
strcpy(temp, str1[i]);
strcat(temp, str3[j]);
strcpy(str4[row], temp);
row++;
}
}
for (i = 0;i <= k2;i++)
{
for (j = 0;j <= k1;j++)
{
strcpy(temp, str3[i]);
strcat(temp, str1[j]);
strcpy(str4[row], temp);
row++;
}
}
{
strcpy(str4[k], str4[k + 1]);
}
row--;
}
}
}
INPUT:
Enter the string: do good
Enter the string: be good
OUTPUT:
Enter the string: do good
Enter the string: be good
do be
do good
good be
good
Exp No:18 Forming new number that is greater than the Date:12/04/2022
given number but should have the same digits
AIM: To write a C program that takes input as 2323 and gives output as 2332. ie. the new
number should be greater than the previous number but should have the same digits.
SOURCE CODE:
#include <stdio.h>
#include <math.h>
int main()
{
int num, result;
return 0;
}
n = num;
while (n != 0)
{
40
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
digit[i] = n % 10;
n = n / 10;
i++;
}
len = i;
for (i = 0; i < len - 1; i++)
{
if (digit[i] > digit[i + 1])
{
temp = digit[i];
digit[i] = digit[i + 1];
digit[i + 1] = temp;
return 0;
}
return num;
}
INPUT:
Enter a number: 56732
OUTPUT:
Enter a number: 56732
The number greater than 56732 and made of same digits is 57632.
RESULT: Hence, to write a C program that takes input as 2323 and gives output as 2332. ie.
the new number should be greater than the previous number but should have the same digits
is successfully executed.
41
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
AIM: To write a C program for determining if one string is a circular permutation of another
string.
SOURCE CODE:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#define CHAR_SIZE 26
int main()
{
char str1[50], str2[50];
int a1[CHAR_SIZE] = {0};
char str2_rem[50];
return 0;
}
INPUT:
Enter string 1: abcd
Enter string 2: dabc
OUTPUT:
Enter string 1: abcd
Enter string 2: dabc
abcd & dabc are circular permutation of each other.
AIM: To write a c program to find the consecutive occurrence of any vowel in a string
SOURCE CODE :
#include <stdio.h>
#include <string.h>
#include <ctype.h>
struct detail
{
char word[20];
};
int main()
{
struct detail s[10];
char string[100], unit[20], c;
int i = 0, j = 0, count = 0;
} while (c != '\n');
string[i - 1] = '\0';
printf("The string entered is: %s\n", string);
for (i = 0; i < strlen(string); i++)
{
while (i < strlen(string) && string[i] != ' ' && isalnum(string[i]))
{
unit[j++] = string[i++];
}
44
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
if (j != 0)
{
unit[j] = '\0';
count = update(s, unit, count);
j = 0;
}
}
return 0;
}
return count;
45
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
int vowelcheck(char c)
{
char vowel[5] = {'a', 'e', 'i', 'o', 'u'};
int i;
c = tolower(c);
for (i = 0; i < 5; i++)
{
if (c == vowel[i])
{
return 1;
}
}
return 0;
}
INPUT:
OUTPUT:
RESULT: Hence to write a C program to find the consecutive occurrence of any vowel in a
string.
46
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
AIM: To write a C program to accept two strings and check whether all characters in first
string is present in second string and print.
SOURCE CODE:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#define CHAR_SIZE 26
int main()
{
char str1[50], str2[50];
int a1[CHAR_SIZE] = {0}, a2[CHAR_SIZE] = {0}, i;
char str1_alpha[CHAR_SIZE], str2_alpha[CHAR_SIZE];
}
else
{
printf("All characters do not match in %s and %s.\n", str1, str2);
}
return 0;
}
INPUT:
Enter string1: aspired
Enter string2: despair
48
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
OUTPUT:
Enter string1: aspired
Enter string2: despair
All characters match in aspired and despair.
The characters that match are: a, d, e, i, p, r, s,
RESULT: Hence, the C program to accept 2 string & check whether all characters in first
string is present in second string & print.
49
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
AIM: To write a C program for given below 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 C program to count
the number of students belonging to each of the following groups of marks:
0-9,10-19,20-29,-----100.
SOURCE CODE:
#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};
/* . . . . . . . .READING AND COUNTING . . . . . .*/
For( I = 0 ; I < MAXVAL ; i++ )
{
/*. . . . . . . .READING OF VALUES . . . . . . . . */
Scanf(“%f”, &value[i]) ;
/*. . . . . .COUNTING FREQUENCY OF GROUPS. . . . . */
++ group[ (int) ( value[i] + 0.5 ) / 10] ;
}
/* . . . .PRINTING OF FREQUENCY TABLE . . . . . . .*/
Printf(“\n”);
Printf(“ GROUP RANGE FREQUENCY\n\n”) ;
For( I = 0 ; I < COUNTER ; i++ )
{
Low = I * 10 ;
If(I == 10)
High = 100 ;
Else
High = low + 9 ;
Printf(“ %2d %3d to %3d %d\n”,
I+1, low, high, group[i] ) ;
}
50
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
Getch();
}
INPUT:
43 65 51 27 79 11 56 61 52 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 35 63 12 21
73 49 51 19 39 49 68 93 85 59
Output:
43 65 51 27 79 11 56 61 52 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 35 63 12 21
73 49 51 19 39 49 68 93 85 59
1 0 to 9 2
2 10 to 19 4
3. 20 to 29 4
4. 30 to 39 5
5 40 to 49 8
6 50 to 59 9
7 60 to 69 7
8 70 to 79 6
9 80 to 89 3
10 90 to 99 2
11 100 to 100 0
RESULT:Hence, the C program for given list of marks obtained by a class of 50 students
in an annual examination is executed successfully.
51
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
AIM: The total distance travelled by vehicle in 't' seconds is given by distance = ut+1/2at2
where 'u' and 'a' are the initial velocity (m/sec.) and acceleration (m/sec2). Write C
program to find the distance travelled at regular intervals of time given the values of
'u' and 'a'. The program should provide the flexibility to the user to select his own
time intervals and repeat the calculations for different values of 'u' and 'a'.
SOURCE CODE:
#include<stdio.h>
main()
{
int a,u,t,t1,t2,i;
float s;
clrscr();
printf("ENTER THE VALUES OF a,u,t,t1,t2:");
scanf("%d%d%d%d%d",&a,&u,&t,&t1,&t2);
for(i=t1;i<=t2;i=i+t) // performing the looping operation for time intervals
{
s=(u*i)+(0.5*a*i*i); // calculate the total distance
printf("\n\nthe distance travelled in %d seconds is %f ",i,s);
}
getch();
}
INPUT:
52
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
OUTPUT:
2
3
4
5
6
RESULT: Hence, to write C program to find the distance travelled at regular intervals of
time given the values of 'u' and 'a' is successfully executed.
53
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
SOURCE CODE:
#include <stdio.h>
int main(void)
{
// to print the source code
char c;
// _FILE_ gets the location
// of the current C program file
FILE *file = fopen(_FILE_, "r");
Do
{
//printing the contents
//of the file
c = fgetc(file);
putchar(c);
}
while (c != EOF);
fclose(file);
return 0;
}
OUTPUT:
#include <stdio.h>
int main(void)
{
// to print the source code
char c;
// _FILE_ gets the location
// of the current C program file
FILE *file = fopen(_FILE_, "r");
Do
{
//printing the contents
//of the file
c = fgetc(file);
54
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
putchar(c);
}
while (c != EOF);
fclose(file);
return 0;
}
RESULT:Hence, the C program to print source code as program output has been executed
Successfully.
55
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
AIM: To write a program using switch and if statements to compute net amount of a cloth
show which has announced seasonal discounts on purchase of items.
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int ch,pa;
float net;
clrscr();
printf("enter 1.if it is millcloth\n 2. if it is handloom");
scanf("%d",&ch);
printf("\n enter purchased amount");
scanf("%d",&pa);
switch(ch)
{
case 1:
if(pa>=1&&pa<=100)
net=pa;
if(pa>=101&&pa<=200)
net=pa-(5.00/100.00)*pa;
if(pa>=201&&pa<=300)
net=pa-(7.5/100.00)*pa;
if(pa>300)
net=pa-(10.00/100.00)*pa;
break;
case 2:
if(pa>=1&pa<=100)
net=pa-(5.00/100.00)*pa;
if(pa>=101&&pa<=200)
net=pa-(7.5/100.00)*pa;
if(pa>=201&&pa<=300)
net=pa-(10.00/100.00)*pa;
if(pa>300)
net=pa-(15.00/100.00)*pa;
56
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
break;
}
printf("\n the net amount to be paid is%f",net);
getch();
}
INPUT:
enter 1. if it is millcloth
2. if it is handloome
enter the purchased amount1000
OUTPUT:
enter 1. if it is millcloth
2.if it is handloome
enter the purchased amount1000
The net amount to be paid is 900.000000
RESULT: Hence, the C program using switch and if statements to compute net amount of a
cloth show which has announced seasonal discounts on purchase of items is executed
successfully.
57
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
AIM: To write a C program to check whether a given number is EVEN or ODD, without
using any arithmetic or relational operators.
SOURCE CODE:
#include <stdio.h>
int main()
{
int number;
printf("\n");
return 0;
}
INPUT:
OUTPUT:
RESULT: Hence, the C program to check whether a given number is EVEN or ODD,
without using any arithmetic or relational operators.
58
Name: V.Keerthika Roll No: 1975020
SRI PADMAVATI VISVAVIDYALAYAM, TIRUPATI
(Women’s University)
SCHOOL OF ENGINEERING AND TECHNOLOGY
Exp No:27 Printing your name 10 times without using any Date:30/04/2022
loop or goto statement.
AIM: To write a C program to Print your name 10 times without using any loop or goto
statement.
SOURCE CODE:
#include <stdio.h>
void rec(int i)
{
if(i<=10)
{
printf("%02d Keerthika/n",i);
rec(i+1);
}
}
int main()
{
int i=1;
rec(i);
}
OUTPUT:
01 keerthika
02 keerthika
03 Keerthika
04 Keerthika
05 Keerthika
06 Keerthika
07 Keerthika
08 Keerthika
09 Keerthika
10 Keerthika
RESULT: Hence, to write a C program to print your name 10 times without using loop or
goto statement is successfully executed.
59