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
5_6242193455259321326.pdf
491.8 KB
I am sharing '5_6242193455259321326' with you
100. C program to generate the above pattern.
#include <stdio.h>
int main() {
int i,j,f,k;
char str[80];
printf("Enter a string: ");
scanf("%s",str);
for(i=0;str[i]!='\0';i++){
for(j=0;j<=i;j++){
printf("%c",str[j]);
}
printf("\n");
}
for(k=i-1;k > 0; k--){
for(j=0;j<k;j++){
printf("%c",str[j]);
}
printf("\n");
}
return 0;
}
#include <stdio.h>
int main() {
int i,j,f,k;
char str[80];
printf("Enter a string: ");
scanf("%s",str);
for(i=0;str[i]!='\0';i++){
for(j=0;j<=i;j++){
printf("%c",str[j]);
}
printf("\n");
}
for(k=i-1;k > 0; k--){
for(j=0;j<k;j++){
printf("%c",str[j]);
}
printf("\n");
}
return 0;
}
Hello everyone, I hope we all are doing good. I apologize for not being active these days. I'll start uploading new programs as soon as possible. Thanks for your patience.
Happy Coding!
Happy Coding!
๐6