Practicals
Practicals
#include <stdio.h>
int main()
{
int first, second, add, subtract, multiply;
float divide;
printf("Enter two integers\n");
scanf("%d%d", &first, &second);
add = first + second;
subtract = first - second;
multiply = first * second;
divide = first / (float)second; //typecasting
printf("Sum = %d\n",add);
printf("Difference = %d\n",subtract);
printf("Multiplication = %d\n",multiply);
printf("Division = %.2f\n",divide);
return 0;
}
I.Write a C program to find the largest of three numbers using ternary operators.
#include<stdio.h>
void main()
{
int a, b, c, larg;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);
printf("Enter third number: ");
scanf("%d", &c);
larg = (a>b)?((a>c)?a:c):((b>c)?b:c);
printf("Largest number is: %d", larg);
}
I.Write a C program to take input of name, rollno and marks obtained by a student in 4 subjects of 100 marks each
and display the name, rollno with percentage score secured.
#include <stdio.h>
struct student {
char name[50];
int roll;
int mark1,mark2,mark3,mark4;
int total;
float percent;
} s;
int main() {
printf("Enter information:\n");
printf("Enter name: ");
scanf("%s",&s.name);
printf("Enter roll number: ");
scanf("%d", &s.roll);
printf("Enter mark1: ");
scanf("%f", &s.mark1);
printf("Enter mark2: ");
scanf("%f", &s.mark2);
printf("Enter mark3: ");
scanf("%f", &s.mark3);
printf("Enter mark4: ");
scanf("%f", &s.mark4);
s.total=s.mark1+s.mark2+s.mark3+s.mark4;
s.percent=s.total*100/400;
printf("Displaying Information:\n");
printf("Name:%s \n",s.name);
printf("Roll number: %d\n", s.roll);
printf("Percentage: %.1f %%\n", s.percent);
return 0;
}
II.Write a C program using function to find the average of ‘n’ numbers using variable length arguments.
#include <stdio.h>
int main() {
int n, i;
float num[100], sum = 0.0, avg;
printf("Enter the numbers of elements: ");
scanf("%d", &n);
while (n > 100 || n < 1) {
printf("Error! number should in range of (1 to 100).\n");
printf("Enter the number again: ");
scanf("%d", &n);
}
for (i = 0; i < n; ++i) {
printf("%d. Enter number: ", i + 1);
scanf("%f", &num[i]);
sum += num[i];
}
avg = sum / n;
printf("Average = %.2f", avg);
return 0;
}
I.Write a C program to swap values of two variables with and without using third variable.
#include<stdio.h>
int main() {
double first, second, temp;
printf("Enter first number: ");
scanf("%lf", &first);
printf("Enter second number: ");
scanf("%lf", &second);
temp = first;
first = second;
second = temp;
printf("\nAfter swapping, first number = %.2lf\n", first);
printf("After swapping, second number = %.2lf", second);
return 0;
}
I.Write a C program to display the size of every data type using “sizeof” operator.
#include<stdio.h>
int main() {
int intType;
float floatType;
double doubleType;
char charType;
return 0;
}
II.Write a C program to generate pay roll of employees using structures and pointers. Ref pg no 58
I.Write a C program to input two numbers and display the maximum number.Ref pg 2
discriminant = b * b - 4 * a * c;
return 0; }
II.Write a C Program to find the largest, smallest , second largest, second smallest, middle element in an Array.
#include <stdio.h>
#include <limits.h>
int main() {
int n;
int arr[n];
return 0;
}
I.Write a C program to input name, marks of 5 subjects of a student and display the name of the student, the total
marks scored, percentage scored and the class of result.(similar to above program)
int main() {
int n;
printf("Enter the number of elements in the array: ");
scanf("%d", &n);
int arr[n];
printf("Enter %d elements: \n", n);
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
reverseArray(arr, n);
printf("Reversed array: \n");
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");
return 0;
}
I.Write a C Program to Check Whether a Number is Prime or not. Ref pg no18
I.Write a C program to check whether the entered year is leap year or not (a year is leap if it is divisible by 4 and
divisible by 100 or 400.) ref pg no 14
I.Write a C program to print even number and odd numbers from 1 to 20. Ref pg no 8
II.Write a C program to convert the Celsius into Fahrenheit and Fahrenheit to Celsius.(Ref pg no 8)
II.Write a C program to generate the prime numbers between given two limits. Ref 18
I.Write a C program to check whether a number is positive, negative or zero using switch case. Ref pg 9
I.Write a C program to compute grade of students using if else adder. The grades are assigned as followed:
ref pg 12
II.Write a C program to swap values of two numbers using pass by value and pass by reference. Ref pg no 37
I.Write a C program to print the sum of digits of a number using for loop. above
II.Write a C program to find the division of two numbers using command line arguments.
II.Write a C program to find the multiplication of two numbers using command line arguments.
II.Write a C program to find the subtraction of two numbers using command line arguments
II.Write a C Program to find the sum of the diagonal element of a 3-D Array.
i.Binary search