C lab exercises
C lab exercises
#include<stdio.h>
#include<conio.h>
int main()
{
int c = 1,b = 22, a =48;
// Finding largest by comparing using relational operators
if (a >= b) {
if (a >= c)
printf("%d is the largest number.", a);
else
printf("%d is the largest number.", c);
}
else {
if (b >= c)
printf("%d is the largest number.", b);
else
printf("%d is the largest number.", c);
}
return 0;
}
Output
48 is the largest number
//getchar();
return 0;
}
Output
Reverse is 4321
Output
GCD of 98 and 56 is 14
int i, n;
return 0;
}
Output
Enter the number of terms: 10
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,
return 0;
}
Output
Enter an integer: 8
8 is a even number
#include <stdio.h>
int main()
{
int i, s = 0;
int n = 10;
i = 1;
return 0;
}
Output
Largest element of array is 9
for(i=0;i<number;i++){
printf("%d ",a[i]);
}
for(i=0;i<number;i++){
for(j = i+1; j < number; j++){
if(a[i] == a[j]){
for(k = j; k <number; k++){
a[k] = a[k+1];
}
j--;
number--;
}
}
}
printf("After deleting the duplicate element the Array is:");
for(i=0;i<number;i++){
printf("%d ",a[i]);
}
return 0;
}
Output
Enter the size of array:3
Enter the elements of the array:
2
2
3
Entered elements are 2,2,3
After deleting the duplicate element array is:
2
3
scanf("%d", &len);
printf("\n Enter the array elements");
18. Write a C program to read N (minimum 3) students marks and find number of
students passed and fail depending on the marks.
#include <stdio.h>
#include<conio.h>
main()
{
int s1,s2,s3,s4,s5;
printf("Enter marks of sub1,sub2,sub3,sub4,sub5");
scanf("%d%d%d",&s1,&s2,&s3);
if(s1>40 && s2>40 && s3>40)
{
printf("Pass");
}
else
{
printf("Fail");
}
return 0;
}
Output
Enter marks of sub1,sub2 ,sub3
55
80
75
Pass
19. Write a C program to count the number of vowels, consonants and special
characters in a given sentence.
#include <stdio.h>
#include <string.h>
if (!s[i]) {
printf("\nVowels: %d\n", vowels);
printf("Consonants: %d\n", consonants);
return;
}
else {
if ((s[i] >= 65 && s[i] <= 90)
|| (s[i] >= 97 && s[i] <= 122)) {
if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i'
|| s[i] == 'o' || s[i] == 'u' || s[i] == 'A'
|| s[i] == 'E' || s[i] == 'I' || s[i] == 'O'
|| s[i] == 'U')
vowels++;
else
consonants++;
}
i++;
stringcount(s);
}
}
// Driver code
int main()
{
char s[1000] = "C Programming";
printf("String: %s", s);
stringcount(s);
return 0;
}
OUTPUT
Strings: C Programing
Vowels:5
Consonants:8
#include <stdio.h>
int main() {
int r, c, a[100][100], b[100][100], sum[100][100], i, j;
printf("Enter the number of rows (between 1 and 100): ");
scanf("%d", &r);
printf("Enter the number of columns (between 1 and 100): ");
scanf("%d", &c);
printf("\nEnter elements of 1st matrix:\n");
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j) {
printf("Enter element a%d%d: ", i + 1, j + 1);
scanf("%d", &a[i][j]);
}
return 0;
}
OUTPUT
Enter the number of columns (between 1 and 100): 3
10 8 6