Q 1) A
i. Write a ‘C’ program to accept a character and check if it is uppercase or lowercase
#include<stdio.h>
int main()
{
char ch;
printf("\nEnter The Character : ");
scanf("%c", &ch);
if (ch >= 'A' && ch <= 'Z')
printf("Character is Upper Case Letters");
else
printf("Character is Not Upper Case Letters");
return (0);
}
OR
#include<stdio.h>
int main()
{
char ch;
printf("\nEnter The Character : ");
scanf("%c", &ch);
if (ch >= 65 && ch <= 90)
printf("Character is Upper Case Letters");
else
printf("Character is Not Upper Case Letters");
return (0);
}
Program Output:
Enter The Character : R
Character is Upper Case Letters
ii Write a ‘C’ program to display n terms of the Fibonacci series.
#include <stdio.h>
int main()
{
int a, b, c, i, terms;
printf("Enter number of terms: ");
scanf("%d", &terms);
/* Fibonacci magic initialization */
a = 0;
b = 1;
c = 0;
printf("Fibonacci terms: \n");
/* Iterate through n terms */
for(i=1; i<=terms; i++)
{
printf("%d, ", c);
a = b; // Copy n-1 to n-2
b = c; // Copy current to n-1
c = a + b; // New term
}
return 0;
}
Program Output:
Enter number of terms: 8Fibonacci terms:
0, 1, 1, 2, 3, 5, 8, 13,
OR
Q 1) Write ‘C’ program to find the maximum number from an array of n integers.
#include <stdio.h>
int main()
{
int size, i, max;
printf("\n Enter the size of the array: ");
scanf("%d", &size);
int array[size];
printf("\n Enter %d elements of the array: \n", size);
for (i = 0; i < size; i++)
{
scanf("%d", &array[i]);
}
max = array[0];
for (i = 1; i < size; i++)
{
if (max < array[i])
max = array[i];
}
printf("\n Maximum element present in the given array is : %d", max);
return 0;
}
Program Output:
Enter the size of the array: 6
Enter 6 elements of the array:
22
3
56
34
89
7
Maximum element present in the given array is : 89
0 Comments:
Post a Comment