85. C program to find Second largest element in an integer array.
#include<stdio.h>
int main()
{
int a[5]={12,43,5,75,1};
int lVal,x,pos=0,Val, pos2;
lVal=a[0];
for(x=0; x<5; x++){
printf(" %d ",a[x]);
}
for(x=0; x<5; x++){
if(lVal<a[x]){
lVal=a[x];
pos=x;
}
}
for(x=pos; x<5; x++){
a[x]=a[x+1];
}
Val=a[0];
x=0;
printf("\n");
for(x=0; x<5-1; x++){
if(Val<a[x]){
Val=a[x];
}
}
printf("\nThe second largest element is: %d\n",Val);
return 0;
}
Programmed by: @miss_rupali
#include<stdio.h>
int main()
{
int a[5]={12,43,5,75,1};
int lVal,x,pos=0,Val, pos2;
lVal=a[0];
for(x=0; x<5; x++){
printf(" %d ",a[x]);
}
for(x=0; x<5; x++){
if(lVal<a[x]){
lVal=a[x];
pos=x;
}
}
for(x=pos; x<5; x++){
a[x]=a[x+1];
}
Val=a[0];
x=0;
printf("\n");
for(x=0; x<5-1; x++){
if(Val<a[x]){
Val=a[x];
}
}
printf("\nThe second largest element is: %d\n",Val);
return 0;
}
Programmed by: @miss_rupali
86. C program to convert decimal digits into Excess 3 code
#include <stdio.h>
int main() {
printf("***EXCESS 3 CODE***\n");
int num ,i=0,n;
int bin[10],ex[10];
scanf("%d",&n);
num = n+3;
printf("number: %d\n",n);
while(n>0){
bin[i] = n % 2;
n = n / 2;
i++;
}
printf("binary: ");
for(int j= i-1;j>=0; j--){
printf ("%d ",bin[j]);
}
printf("\n");
i=0;
while(num>0){
ex[i] = num % 2;
num = num / 2;
i++;
}
printf("excess 3 code: ");
for(int j= i-1;j>=0; j--){
printf ("%d ",ex[j]);
}
return 0;
}
Programmed by: @miss_rupali
#include <stdio.h>
int main() {
printf("***EXCESS 3 CODE***\n");
int num ,i=0,n;
int bin[10],ex[10];
scanf("%d",&n);
num = n+3;
printf("number: %d\n",n);
while(n>0){
bin[i] = n % 2;
n = n / 2;
i++;
}
printf("binary: ");
for(int j= i-1;j>=0; j--){
printf ("%d ",bin[j]);
}
printf("\n");
i=0;
while(num>0){
ex[i] = num % 2;
num = num / 2;
i++;
}
printf("excess 3 code: ");
for(int j= i-1;j>=0; j--){
printf ("%d ",ex[j]);
}
return 0;
}
Programmed by: @miss_rupali
#DSA_Series
87. C program to Traverse a BST using recursion.
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
struct node *left;
struct node *right;
int data;
}node;
void show(node *root){
//checking if root is empty then print NULL
if(root->left==NULL || root->right==NULL)
printf("NULL\n");
//else print data of its rigth node and left node
else{
printf("%d\n%d %d\n",root->data, root->left->data, root->right->data);
}
}
//creating main function to creat the nodes of a tree
node * creat(int data){
//allocating memory in heap
node *p = (node*)malloc(sizeof(node));
p->data = data;
p->left=NULL;
p->right=NULL;
return p;
}
void preOrder(node *root){
//preorder follows ROOT->LEFT-RIGTH
if(root!=NULL){
printf("%d ", root->data);
preOrder(root->left);
preOrder(root->right);
}
}
void inOrder(node *root){
//inorder follows LEFT->ROOT->RIGHT
if(root!=NULL){
inOrder(root->left);
printf("%d ", root->data);
inOrder(root->right);
}
}
void postOrder(node *root){
//postorder folllows LEFT->RIGTH->ROOT
if(root!=NULL){
postOrder(root->left);
postOrder(root->right);
printf("%d ", root->data);
}
}
int main(){
//taking data in node *type pointer
node *n=creat(34);
node *n1=creat(97);
node *n2=creat(7);
node *n3=creat(37);
node *n4=creat(17);
node *n5=creat(67);
node *n6=creat(127);
n->left=n1;
n->right=n2;
n1->left=n3;
n1->right=n4;
n2->left=n5;
n2->right=n6;
printf("Preorder: ");
preOrder(n);
printf("\nInorder: ");
inOrder(n);
printf("\nPsotorder: ");
postOrder(n);
return 0;
}
87. C program to Traverse a BST using recursion.
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
struct node *left;
struct node *right;
int data;
}node;
void show(node *root){
//checking if root is empty then print NULL
if(root->left==NULL || root->right==NULL)
printf("NULL\n");
//else print data of its rigth node and left node
else{
printf("%d\n%d %d\n",root->data, root->left->data, root->right->data);
}
}
//creating main function to creat the nodes of a tree
node * creat(int data){
//allocating memory in heap
node *p = (node*)malloc(sizeof(node));
p->data = data;
p->left=NULL;
p->right=NULL;
return p;
}
void preOrder(node *root){
//preorder follows ROOT->LEFT-RIGTH
if(root!=NULL){
printf("%d ", root->data);
preOrder(root->left);
preOrder(root->right);
}
}
void inOrder(node *root){
//inorder follows LEFT->ROOT->RIGHT
if(root!=NULL){
inOrder(root->left);
printf("%d ", root->data);
inOrder(root->right);
}
}
void postOrder(node *root){
//postorder folllows LEFT->RIGTH->ROOT
if(root!=NULL){
postOrder(root->left);
postOrder(root->right);
printf("%d ", root->data);
}
}
int main(){
//taking data in node *type pointer
node *n=creat(34);
node *n1=creat(97);
node *n2=creat(7);
node *n3=creat(37);
node *n4=creat(17);
node *n5=creat(67);
node *n6=creat(127);
n->left=n1;
n->right=n2;
n1->left=n3;
n1->right=n4;
n2->left=n5;
n2->right=n6;
printf("Preorder: ");
preOrder(n);
printf("\nInorder: ");
inOrder(n);
printf("\nPsotorder: ");
postOrder(n);
return 0;
}
88. C program to count how many number of Hours, minutes and seconds in given year.
#include<stdio.h>
int main()
{
int h_24, year,ts,yr;
printf("enter for how many year\n");
scanf("%d",&yr);
int h,m;
int h_1 = 3600;//in 1hr = 3,600 seconds
//in 1day 24 hours
h_24 = 24*3600;// in 1hr 3,600 sec
// so in 24hrs 86,400 seconds
year = h_24*365;//in 1yr 365 days
//after this line in 1yr 31536000 sec
ts = yr*year;
//this line will find sec ac to input yr.
h = ts/3600;//this line findes hours
m = ts/60; //this line findes minutes
printf("total hour = %d\n",h);
printf("total minutes = %d\n",m);
printf("total sec = %d\n",ts);
return 0;
}
Programmed by:@Sks_programmer
#include<stdio.h>
int main()
{
int h_24, year,ts,yr;
printf("enter for how many year\n");
scanf("%d",&yr);
int h,m;
int h_1 = 3600;//in 1hr = 3,600 seconds
//in 1day 24 hours
h_24 = 24*3600;// in 1hr 3,600 sec
// so in 24hrs 86,400 seconds
year = h_24*365;//in 1yr 365 days
//after this line in 1yr 31536000 sec
ts = yr*year;
//this line will find sec ac to input yr.
h = ts/3600;//this line findes hours
m = ts/60; //this line findes minutes
printf("total hour = %d\n",h);
printf("total minutes = %d\n",m);
printf("total sec = %d\n",ts);
return 0;
}
Programmed by:@Sks_programmer
89. C program to convert string into substring.
#include <stdio.h>
int main(){
char str[100];
char temp[80];
int start, end,x=0;
printf("Enter the string: ");
scanf("%[^\n]%*c", str);
printf("Enter the number of index for start and end of sub-string: ");
scanf("%d %d", &start, &end);
for(int i=start; i <= end; i++){
temp[x] = str[i];
x++;
}
for(int i=0; i<x; i++)
printf("%c", temp[i]);
return 0;
}
#include <stdio.h>
int main(){
char str[100];
char temp[80];
int start, end,x=0;
printf("Enter the string: ");
scanf("%[^\n]%*c", str);
printf("Enter the number of index for start and end of sub-string: ");
scanf("%d %d", &start, &end);
for(int i=start; i <= end; i++){
temp[x] = str[i];
x++;
}
for(int i=0; i<x; i++)
printf("%c", temp[i]);
return 0;
}
90. C program to find the difference between smallest and largest element of a given array.
#include <stdio.h>
int findDiff(int n, int arr[]){
int smallest = arr[0];
int largest = arr[0];
int diff=0;
for(int i=0; i<n; i++){
if(smallest > arr[i+1]){
smallest = arr[i+1];
}
}
for(int i=1; i<n; i++){
if(largest < arr[i]){
largest = arr[i];
}
}
diff = largest - smallest;
return diff;
}
int main()
{
int n;
printf("enter the number of elements: ");
scanf("%d", &n);
int arr[n];
printf("enter values: \n");
for(int i=0; i<n; i++){
scanf("%d", &arr[i]);
}
int diff = findDiff(n, arr);
printf("Difference: %d", diff);
return 0;
}
#include <stdio.h>
int findDiff(int n, int arr[]){
int smallest = arr[0];
int largest = arr[0];
int diff=0;
for(int i=0; i<n; i++){
if(smallest > arr[i+1]){
smallest = arr[i+1];
}
}
for(int i=1; i<n; i++){
if(largest < arr[i]){
largest = arr[i];
}
}
diff = largest - smallest;
return diff;
}
int main()
{
int n;
printf("enter the number of elements: ");
scanf("%d", &n);
int arr[n];
printf("enter values: \n");
for(int i=0; i<n; i++){
scanf("%d", &arr[i]);
}
int diff = findDiff(n, arr);
printf("Difference: %d", diff);
return 0;
}
91. C program to find Median of a given integer array.
#include<stdio.h>
int main()
{
int n;
int fst, lst, med, isSorted, temp;
printf("enter the number of elements: ");
scanf("%d",&n);
int arr[n];
printf("enter the values: ");
for(int a=0; a<n; a++){
scanf("%d",&arr[a]);
}
for(int i=0; i<n-1; i++){
isSorted = 1;
for(int j=0; j<= n-i-1; j++){
if(arr[j] > arr[j+1]){
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
isSorted = 0;
}
}
}
if(isSorted){
printf("After sorting the array: ");
for(int i=0; i<n; i++){
printf("%d ", arr[i]);
}
}
printf("\n");
fst=0;
lst= n-1;
med=(fst+lst)/2;
if(n%2)
printf("median of the array is : %d",arr[med]);
else
printf("median of the array is : %lf ",(arr[med]+arr[med+1])/2.0);
return 0;
}
#include<stdio.h>
int main()
{
int n;
int fst, lst, med, isSorted, temp;
printf("enter the number of elements: ");
scanf("%d",&n);
int arr[n];
printf("enter the values: ");
for(int a=0; a<n; a++){
scanf("%d",&arr[a]);
}
for(int i=0; i<n-1; i++){
isSorted = 1;
for(int j=0; j<= n-i-1; j++){
if(arr[j] > arr[j+1]){
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
isSorted = 0;
}
}
}
if(isSorted){
printf("After sorting the array: ");
for(int i=0; i<n; i++){
printf("%d ", arr[i]);
}
}
printf("\n");
fst=0;
lst= n-1;
med=(fst+lst)/2;
if(n%2)
printf("median of the array is : %d",arr[med]);
else
printf("median of the array is : %lf ",(arr[med]+arr[med+1])/2.0);
return 0;
}
#c_&_os
92. C program to implement FCFS algorithm in OS
#include <stdio.h>
int main()
{
int n,i;
printf("enter number of process..?\n");
scanf("%d", &n);
int process[n],arrival_time[n],burst_time[n],completion_time[n],tat[n],wt[n],rt[n];
printf("enter process...\n");
for(i=0; i<n; i++){
scanf("%d", &process[i]);
}
printf("enter arrival time..\n");
for(i=0; i<n; i++){
printf("enter arrival time for prcess: p%d\n",i+1);
scanf("%d",&arrival_time[i]);
}
printf("enter burst time..\n");
for(i=0; i<n; i++){
printf("enter burst time for prcess: p%d\n",i+1);
scanf("%d",&burst_time[i]);
}
//process starts here...
printf("\ncompletion time...\n");
for(i=0; i<n; i++){
completion_time[0] = burst_time[0];
completion_time[i+1] = completion_time[i] + burst_time[i+1];
printf("completion time of process p%d is %d\n",i+1,completion_time[i]);
}
//turn around time(tat)...
printf("\nTAT...\n");
for(i=0; i<n; i++){
tat[i] = completion_time[i] - arrival_time[i];
printf("turn around time time of process p%d is %d\n",i+1,tat[i]);
}
//waiting time(wt)...
printf("\nwaiting time...\n");
for(i=0; i<n; i++){
wt[i] = tat[i] - burst_time[i];
printf("wating time of process p%d is %d\n",i+1,wt[i]);
}
return 0;
}
92. C program to implement FCFS algorithm in OS
#include <stdio.h>
int main()
{
int n,i;
printf("enter number of process..?\n");
scanf("%d", &n);
int process[n],arrival_time[n],burst_time[n],completion_time[n],tat[n],wt[n],rt[n];
printf("enter process...\n");
for(i=0; i<n; i++){
scanf("%d", &process[i]);
}
printf("enter arrival time..\n");
for(i=0; i<n; i++){
printf("enter arrival time for prcess: p%d\n",i+1);
scanf("%d",&arrival_time[i]);
}
printf("enter burst time..\n");
for(i=0; i<n; i++){
printf("enter burst time for prcess: p%d\n",i+1);
scanf("%d",&burst_time[i]);
}
//process starts here...
printf("\ncompletion time...\n");
for(i=0; i<n; i++){
completion_time[0] = burst_time[0];
completion_time[i+1] = completion_time[i] + burst_time[i+1];
printf("completion time of process p%d is %d\n",i+1,completion_time[i]);
}
//turn around time(tat)...
printf("\nTAT...\n");
for(i=0; i<n; i++){
tat[i] = completion_time[i] - arrival_time[i];
printf("turn around time time of process p%d is %d\n",i+1,tat[i]);
}
//waiting time(wt)...
printf("\nwaiting time...\n");
for(i=0; i<n; i++){
wt[i] = tat[i] - burst_time[i];
printf("wating time of process p%d is %d\n",i+1,wt[i]);
}
return 0;
}
93. C program to print first n non-prime numbers with the help of function
#include<stdio.h>
int isprime(int a){
int d=0;
for(int c=2; c<=a/2; c++){
if(a % c ==0){
d=1;
break;
}
}
if(d==1){
return 1;
}
else{
return 0;
}
}
int main(){
int n;
printf("enter the value of n: ");
scanf("%d",&n);
for(int a=4; a<=n; a++){
if(isprime(a)){
printf("%d \n",a);
}
}
return 0;
}
#include<stdio.h>
int isprime(int a){
int d=0;
for(int c=2; c<=a/2; c++){
if(a % c ==0){
d=1;
break;
}
}
if(d==1){
return 1;
}
else{
return 0;
}
}
int main(){
int n;
printf("enter the value of n: ");
scanf("%d",&n);
for(int a=4; a<=n; a++){
if(isprime(a)){
printf("%d \n",a);
}
}
return 0;
}
94. Implementing Tower of Hanoi using Recursion
#include <stdio.h>
void twrs(int num, char frompeg, char topeg, char auxpeg) {
if (num == 1) {
printf("\n Move disk 1 from peg %c to peg %c", frompeg, topeg);
return;
}
twrs(num - 1, frompeg, auxpeg, topeg);
printf("\n Move disk %d from peg %c to peg %c", num, frompeg, topeg);
twrs(num - 1, auxpeg, topeg, frompeg);
}
int main() {
int num;
printf("Enter the number of disks : ");
scanf("%d", &num);
printf("The sequence of moves involved in the Tower of Hanoi are :\n");
twrs(num, 'A', 'C', 'B');
return 0;
}
/**Programmed by: @miss_rupali**/
#include <stdio.h>
void twrs(int num, char frompeg, char topeg, char auxpeg) {
if (num == 1) {
printf("\n Move disk 1 from peg %c to peg %c", frompeg, topeg);
return;
}
twrs(num - 1, frompeg, auxpeg, topeg);
printf("\n Move disk %d from peg %c to peg %c", num, frompeg, topeg);
twrs(num - 1, auxpeg, topeg, frompeg);
}
int main() {
int num;
printf("Enter the number of disks : ");
scanf("%d", &num);
printf("The sequence of moves involved in the Tower of Hanoi are :\n");
twrs(num, 'A', 'C', 'B');
return 0;
}
/**Programmed by: @miss_rupali**/
95. C program to print relationships between n elements.
#include<stdio.h>
void swap(int *a,int *b){
int temp=*a;
*a=*b;
*b=temp;
}
void comb(int *a,int l,int r){
int i;
if(l==r)
{
for(i=0;i<=r;i++)
printf("%d",a[i]);
printf("\n");
}
else{
for(i=l;i<=r;i++){
swap((a+l),(a+i));
comb(a,l+1,r);
swap((a+l),(a+i));
}
}
}
int main(void){
int n,i;
printf("enter the value of n: ");
scanf("%d",&n);
int arr[n];
for(i=0;i<n;i++)
{
arr[i]=i+1;
}
comb(arr,0,n-1);
return 0;
}
Output:
enter the value of n: 3
123
132
213
231
321
312
/**
Programmed by : @Satvik017
**/
#include<stdio.h>
void swap(int *a,int *b){
int temp=*a;
*a=*b;
*b=temp;
}
void comb(int *a,int l,int r){
int i;
if(l==r)
{
for(i=0;i<=r;i++)
printf("%d",a[i]);
printf("\n");
}
else{
for(i=l;i<=r;i++){
swap((a+l),(a+i));
comb(a,l+1,r);
swap((a+l),(a+i));
}
}
}
int main(void){
int n,i;
printf("enter the value of n: ");
scanf("%d",&n);
int arr[n];
for(i=0;i<n;i++)
{
arr[i]=i+1;
}
comb(arr,0,n-1);
return 0;
}
Output:
enter the value of n: 3
123
132
213
231
321
312
/**
Programmed by : @Satvik017
**/
96. C program to convert the time from a 12 hour clock to a 24 hour clock.
#include <stdio.h>
#include <string.h>
int main() {
int hh, mm,m;
char a[2];
printf("enter hour and minutes: ");
scanf("%d %d",&hh,&m);
mm=m;
printf("am/pm: ");
scanf ("%s",&a);
if(hh<=12 && mm<=59){
if((strcmp (a,"pm") ==0) && hh!=0 && hh!=12){
hh+=12;
}else if((strcmp(a,"am")==0) && hh==12){
hh=0;
}
}
if(mm != 00 && hh != 00)
printf ("%d:%d",hh,mm);
else
printf ("%02d:%02d",hh,mm);
return 0;
}
Output:
enter hour and minutes: 3 56
am/pm: pm
time in 24 hour clock:
15:56
#include <stdio.h>
#include <string.h>
int main() {
int hh, mm,m;
char a[2];
printf("enter hour and minutes: ");
scanf("%d %d",&hh,&m);
mm=m;
printf("am/pm: ");
scanf ("%s",&a);
if(hh<=12 && mm<=59){
if((strcmp (a,"pm") ==0) && hh!=0 && hh!=12){
hh+=12;
}else if((strcmp(a,"am")==0) && hh==12){
hh=0;
}
}
if(mm != 00 && hh != 00)
printf ("%d:%d",hh,mm);
else
printf ("%02d:%02d",hh,mm);
return 0;
}
Output:
enter hour and minutes: 3 56
am/pm: pm
time in 24 hour clock:
15:56
97. C program to Decrypt Encrypted text.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
int i=0, j=0,x,y=0,l;
char str[100];
char str1[100];
char str2[100];
printf("enter an encrypted string: ");
fgets(str,100,stdin);
l = strlen(str);
y = l-1;
for(x = 0; x < l; x++){
str1[x] = str[y];
y--;
}
while(str1[i] != '\0'){
if((str1[i] >= 65 && str1[i] <= 90) (str1[i] >= 97 && str1[i] <= 122) (str1[i] == 32 && str1[i] != 44)){
str2[j] = str1[i];
j++;
}
i++;
}
str2[j] = '\0';
printf("decrypted string: %s",str2);
return 0;
}
Output:
enter an encrypted string: 63$@y#ts12at75*^ @#s86i ,$~4el66p0p@!a
decrypted string: apple is tasty
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
int i=0, j=0,x,y=0,l;
char str[100];
char str1[100];
char str2[100];
printf("enter an encrypted string: ");
fgets(str,100,stdin);
l = strlen(str);
y = l-1;
for(x = 0; x < l; x++){
str1[x] = str[y];
y--;
}
while(str1[i] != '\0'){
if((str1[i] >= 65 && str1[i] <= 90)
str2[j] = str1[i];
j++;
}
i++;
}
str2[j] = '\0';
printf("decrypted string: %s",str2);
return 0;
}
Output:
enter an encrypted string: 63$@y#ts12at75*^ @#s86i ,$~4el66p0p@!a
decrypted string: apple is tasty
๐1๐1
98. C program to count Zeros within a given range.
#include <stdio.h>
int countZero(int num){
int mod;
int count = 0;
while(num>0) {
mod = num%10;
if(mod==0){
count++;
}
num=num/10;
}
return count;
}
int countZeroInRang(int num1,int num2){
int count = 0;
for(int i = num1; i <= num2; i++){
count += countZero(i);
}
return count;
}
int main() {
int num1,num2,zeros=0;
printf("Enter two numbers : ");
scanf("%d %d",&num1,&num2);
zeros = countZeroInRang(num1,num2);
printf ("Zeros between %d and %d are %d",num1,num2,zeros);
return 0;
}
Output:
Enter two numbers: 20 500
Zeros between 20 and 500 are 90
#include <stdio.h>
int countZero(int num){
int mod;
int count = 0;
while(num>0) {
mod = num%10;
if(mod==0){
count++;
}
num=num/10;
}
return count;
}
int countZeroInRang(int num1,int num2){
int count = 0;
for(int i = num1; i <= num2; i++){
count += countZero(i);
}
return count;
}
int main() {
int num1,num2,zeros=0;
printf("Enter two numbers : ");
scanf("%d %d",&num1,&num2);
zeros = countZeroInRang(num1,num2);
printf ("Zeros between %d and %d are %d",num1,num2,zeros);
return 0;
}
Output:
Enter two numbers: 20 500
Zeros between 20 and 500 are 90
99. Menu driven program to find number of vowels, constants, digits and special symbols in a given string.
#include <stdio.h>
int isVowel(int n,char line[]){
int vowels =0 ;
for(int i=0; i<n; i++){
if(line[i] == 97 line[i] == 101 line[i] == 105 line[i] == 111 line[i] == 117){
vowels++;
}
}
return vowels;
}
int isConstant(int n,char line[]){
int constant = 0;
for(int i=0; i<n; i++){
if(line[i] >= 65 && line[i] <= 91 || line[i] >= 97 && line[i] <= 122){
constant++;
}
}
return constant;
}
int isDigit(int n,char line[]){
int digit = 0;
for(int i=0; i<n; i++){
if(line[i] >= 48 && line[i] <= 57){
digit++;
}
}
return digit;
}
int isSpecial_symbol(int n,char line[]){
int special_symbol = 0;
for(int i=0; i<n; i++){
if(line[i] >= 33 && line[i] <= 46 line[i] >= 58 && line[i] <= 64 line[i] >= 92 && line[i] <= 96) {
special_symbol++;
}
}
return special_symbol;
}
int main(){
char line[500];
int choice,n;
int vowels;
int constant;
int special_symbol;
int digit;
char repeat;
printf("Enter an string: ");
scanf("%[^\n]%*c",&line);
n=strlen(line);
printf("1.vowels \n");
printf("2.consonant\n");
printf("3.special_symbol\n");
printf("4.digit\n");
do{
printf("Enter your choice: \n");
scanf("%d",&choice);
switch(choice){
case 1:
vowels = isVowel(n,line);
if(vowels)
printf("vowels: %d\n", vowels);
else
printf("vowel is not found!");
break;
case 2:
constant = isConstant(n,line);
if(constant)
printf("constants: %d\n", constant);
else
printf("constant is not found!");
break;
case 3:
special_symbol = isSpecial_symbol(n,line);
if(special_symbol)
printf("special symbols: %d\n", special_symbol);
else
printf("special symbol is not found!");
break;
case 4:
digit = isDigit(n,line);
if(digit)
printf("digit: %d\n",digit);
else
printf("digit is not found!");
break;
default:
printf("\ninvalid choice....!");
}
printf("\n\nDo you want to choose again?(Y/N)\n");
scanf(" %c", &repeat);
}while(repeat=='Y');
return 0;
}
#include <stdio.h>
int isVowel(int n,char line[]){
int vowels =0 ;
for(int i=0; i<n; i++){
if(line[i] == 97
vowels++;
}
}
return vowels;
}
int isConstant(int n,char line[]){
int constant = 0;
for(int i=0; i<n; i++){
if(line[i] >= 65 && line[i] <= 91 || line[i] >= 97 && line[i] <= 122){
constant++;
}
}
return constant;
}
int isDigit(int n,char line[]){
int digit = 0;
for(int i=0; i<n; i++){
if(line[i] >= 48 && line[i] <= 57){
digit++;
}
}
return digit;
}
int isSpecial_symbol(int n,char line[]){
int special_symbol = 0;
for(int i=0; i<n; i++){
if(line[i] >= 33 && line[i] <= 46
special_symbol++;
}
}
return special_symbol;
}
int main(){
char line[500];
int choice,n;
int vowels;
int constant;
int special_symbol;
int digit;
char repeat;
printf("Enter an string: ");
scanf("%[^\n]%*c",&line);
n=strlen(line);
printf("1.vowels \n");
printf("2.consonant\n");
printf("3.special_symbol\n");
printf("4.digit\n");
do{
printf("Enter your choice: \n");
scanf("%d",&choice);
switch(choice){
case 1:
vowels = isVowel(n,line);
if(vowels)
printf("vowels: %d\n", vowels);
else
printf("vowel is not found!");
break;
case 2:
constant = isConstant(n,line);
if(constant)
printf("constants: %d\n", constant);
else
printf("constant is not found!");
break;
case 3:
special_symbol = isSpecial_symbol(n,line);
if(special_symbol)
printf("special symbols: %d\n", special_symbol);
else
printf("special symbol is not found!");
break;
case 4:
digit = isDigit(n,line);
if(digit)
printf("digit: %d\n",digit);
else
printf("digit is not found!");
break;
default:
printf("\ninvalid choice....!");
}
printf("\n\nDo you want to choose again?(Y/N)\n");
scanf(" %c", &repeat);
}while(repeat=='Y');
return 0;
}
๐3
C Coding
5_6222125641475556333.pdf
C practice questions, only for Beginners...Happy Coding :D