CPROG_IA-3_Scheme_Solutions
CPROG_IA-3_Scheme_Solutions
1ST
Date 0 1 2 5 Semester USN
String Functions:
• strlen ()
• strcmp ()
• strcpy ()
• strncmp () L1 10
• strncpy ()
• strrev ()
• strcat ()
• strstr ()
• strncat ()
OR
2 Write a program to check whether a string is palindrome or not without library
function.
Executable program – 10 M
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
return 0;
}
3 Develop a program using pointers to compute the Sum, Mean and Standard
deviation of all elements stored in an array of N real numbers.
Executable program – 10 M
#include <stdio.h>
#include <math.h>
// Function prototypes
void computeStatistics(float *arr, int n, float *sum, float *mean, float
*std_dev);
L2 10
int main() {
int n;
printf("Enter the number of elements: ");
scanf("%d", &n);
float arr[n];
printf("Enter %d real numbers: ", n);
for (int i = 0; i < n; i++) {
scanf("%f", arr + i); // Using pointer notation
}
return 0;
}
*mean = *sum / n;
float variance = 0;
for (int i = 0; i < n; i++) {
variance += pow(*(arr + i) - *mean, 2);
}
Executable program – 10 M
#include <stdio.h>
// Function prototypes
void add(float *a, float *b, float *result);
void subtract(float *a, float *b, float *result);
void multiply(float *a, float *b, float *result);
void divide(float *a, float *b, float *result);
int main() {
float num1, num2, result; L2 10
char operation;
switch(operation) {
case '+':
add(&num1, &num2, &result);
break;
case '-':
subtract(&num1, &num2, &result);
break;
case '*':
multiply(&num1, &num2, &result);
break;
case '/':
if (num2 != 0)
divide(&num1, &num2, &result);
else {
printf("Error! Division by zero.\n");
return 1;
}
break;
default:
printf("Invalid operator!\n");
return 1;
}
Executable program – 10 M
L3
#include <stdio.h>
// Define structure for Employee
typedef struct {
int EMPID;
char EMPNAME[50];
float SALARY;
} Employee;
int main() {
Employee emp;
return 0;
}
OR
6 10
Write a note on following:
a) Structure with its declaration.
b) Unions with its declaration.
Structure Union
No data overlap as members are Full data overlap as members shares the same
independent. memory.
Individual member can be accessed
Only one member can be accessed at a time.
at a time.
Executable program – 10 M
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main() {
FILE *file;
char filename[100], ch;
int char_count = 0, word_count = 0, in_word = 0;
if (isspace(ch)) {
in_word = 0;
} else if (!in_word) {
in_word = 1;
word_count++;
}
}
return 0;
}
OR
Write a program in C to create and store information in a text file and 10
print the same on console.
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *file;
char filename[100], ch;
return 0;
}