Slips Sloution Advanced C
Slips Sloution Advanced C
Slips Sloution Advanced C
Slip 1)
#include<stdio.h>
#include<stdlib.h>
Int main()
int x, y, result;
scanf("%d", &x);
scanf("%d", &y);
result = max(x,y);
return 0;
2) Write a program to accept to compute sum and average of all elements in an array using pointer.
(10 marks).
#include<stdio.h>
int main()
float average;
scanf("%d",&number);
scanf("%d",&number[i]);
i=0;
ptr=&number[0];
for(i=0;i<5;i++)
average=sum/number;
return 0;
3) Write a program to accept details of n students (roll number, name, percentage) using structure.
Display details of the student having maximum percentage. (15 marks)
#include<stdio.h>
struct student
char name[25];
int roll_no;
float percentage;
};
void main()
int number;
printf("Enter number of students data you want to accept : ");
scanf("%d", &number);
int i;
for(i=0;i<number;i++)
scanf("%d", &s[i].roll_no);
scanf("%s", &s[i].name);
scanf("%f", &s[i].percentage);
int max=0;
for(i=1;i<number;i++)
max=i;
Slip 2
1) Write a program to display the command line arguments in reverse order. (5 marks).
#include <stdio.h>
if (argc < 2)
return 1;
printf("%s\n", argv[i]);
return 0;
2) Write a program to display contents of file “a.txt” on the screen. (10 marks)
#include <stdio.h>
#include <ctype.h>
int main()
FILE *file;
char ch;
if (file == NULL)
return 1;
printf("%c", ch);
fclose(file);
return 0;
3) Write a menu driven program to perform the following operations on strings using standard
library functions:
#include <string.h>
int main()
char choice;
scanf("%s",&str1);
scanf("%s",&str2);
printf("\nMenu:\n");
scanf("%c", &choice);
switch(choice)
case '1':
str1[i] = toupper(str1[i]);
break;
case '2':
strcpy(str1, str2);
break;
case '3':
if(strcmp(str1, str2) == 0)
else
break;
case '4':
strcat(str1, str2);
break;
default:
printf("Invalid choice!");
return 0;
Slip 3
1) Write a program to calculate length of string using standard library function.(5 marks)
#include<stdio.h>
#include<string.h>
int main()
{
char string[25];
printf("Enter a string : \t\t");
scanf("%s",&string);
2) Write a program to allocate memory dynamically for n integers. Accept the elements and
calculate their sum and average.(10 marks)
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n, *arr, sum = 0;
float average;
if (arr == NULL)
{
printf("Memory allocation failed.\n");
return 1;
}
average = (float)sum / n;
free(arr);
return 0;
}
struct birthdate
{
int day;
int month;
int year;
};
struct person
{
char name[50];
char address[100];
struct birthdate dob;
};
int main()
{
int n;
return 0;
}
Slip 4
1) Write a program to calculate sum of two numbers. Pass the numbers as command line
arguments.
#include <stdio.h>
#include <stdlib.h>
return 0;
}
2) Write a program to create student structure having fields roll no, name. Accept details of
one student and write a function to display the details.
#include <stdio.h>
struct student
{
int roll_no;
char name[50];
};
void displayStudent(struct student s)
{
printf("Roll No: %d\n", s.roll_no);
printf("Name: %s\n", s.name);
}
int main()
{
struct student s;
return 0;
}
3) Write a program to copy contents of file a.txt to b.txt by changing the case of each
alphabet.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
FILE *sourceFile, *destinationFile;
char ch;
fputc(ch, destinationFile);
}
return 0;
}
Slip 5
#include <stdio.h>
int main()
{
int num1, num2;
return 0;
}
2) Write a program to perform the following operations on two strings using standard library
functions:
a. Copy b. Compare
#include <stdio.h>
#include <string.h>
strcpy(str2, str1);
int main()
scanf("%s", str1);
printf("Enter the second string: ");
scanf("%s", str2);
copy_strings(str1, str2);
if (comparison_result == 0)
else
return 0;
3) Write a program to read the contents of a text file and count the number of characters, lines
and words in the file.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
FILE *file;
char filename[MAX_FILE_NAME];
char word[MAX_WORD_LENGTH];
int charCount = 0, wordCount = 0, lineCount = 0;
char ch;
if (file == NULL)
{
printf("Could not open file %s", filename);
return 1;
}
if (isspace(ch))
{
wordCount++;
}
if (ch == '\n')
{
lineCount++;
}
}
wordCount++;
fclose(file);
return 0;
}
Slip 6
1) Write a C program to compare two strings using standard library function. (5 marks)
#include <stdio.h>
#include <string.h>
int main() {
scanf("%s", str1);
scanf("%s", str2);
if (strcmp(str1, str2) == 0) {
} else {
return 0;
2) Write a C program to copy contents of one file to another file. (10 marks)
#include <stdio.h>
#include <stdlib.h>
int main() {
char ch;
scanf("%s", sourceFileName);
scanf("%s", destinationFileName);
if (sourceFile == NULL) {
return 1;
if (destinationFile == NULL) {
fclose(sourceFile);
return 1;
fputc(ch, destinationFile);
fclose(sourceFile);
fclose(destinationFile);
return 0;
3) Write a C program to create structure employee (id, name, salary). Accept details of n
employees and perform the following operations:
a. Display all employees.
#include <stdio.h>
#include <stdlib.h>
struct Employee
int id;
char name[50];
float salary;
};
int main()
int n, i;
float minSalary;
scanf("%d", &n);
scanf("%d", &employees[i].id);
printf("Name: ");
scanf("%s", employees[i].name);
printf("Salary: ");
scanf("%f", &employees[i].salary);
printf("\nAll employees:\n");
scanf("%f", &minSalary);
free(employees);
return 0;
Slip 7
int main() {
int num1, num2;
return 0;
}
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
if (file == NULL) {
return 1;
}
fclose(file);
return 0;
3) Write a C program to accept n elements using dynamic memory allocation and calculate the
sum and average of the elements. Also find the largest element.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n, i;
float *arr, sum = 0, average, largest;
// Input elements
printf("Enter %d elements:\n", n);
for (i = 0; i < n; i++)
{
scanf("%f", &arr[i]);
}
// Calculate average
average = sum / n;
free(arr);
return 0;
}
Slip 8
#include <stdio.h>
int main()
{
int num1, num2;
swap(&num1, &num2);
printf("After swapping:\n");
printf("First number: %d\n", num1);
printf("Second number: %d\n", num2);
return 0;
}
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char str[100];
int vowels = 0, consonants = 0, i;
return 0;
}
3) Write a C program to accept details of n items (code, name, price) using structure.
Perform the following operations:
a. Display all items having price > ___