-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
adarsh
committed
Jan 14, 2020
1 parent
6e7fc0f
commit 515e809
Showing
11 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
char str[100]; | ||
int counter; | ||
printf("Enter a string: "); | ||
gets(str); | ||
for(counter=0;str[counter]!=NULL;counter++) | ||
{ | ||
if(str[counter]>='A' && str[counter]<='Z') | ||
str[counter]=str[counter]+32; | ||
else if(str[counter]>='a' && str[counter]<='z') | ||
str[counter]=str[counter]-32; | ||
} | ||
printf("String after toggle each characters: %s",str); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
int num; | ||
int tempNum,flag; | ||
printf("Enter an integer number: "); | ||
scanf("%d",&num); | ||
tempNum=num; | ||
flag=0; | ||
while(tempNum!=1) | ||
{ | ||
if(tempNum%2!=0) | ||
{ | ||
flag=1; | ||
break; | ||
} | ||
tempNum=tempNum/2; | ||
} | ||
|
||
if(flag==0) | ||
printf("%d is power of 2.",num); | ||
else | ||
printf("%d is not the power of 2.",num); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include<stdio.h> | ||
|
||
int main() | ||
{ | ||
int feet,inches; | ||
|
||
printf("Enter the value of feet: "); | ||
scanf("%d",&feet); | ||
|
||
|
||
inches=feet*12; | ||
|
||
printf("Total inches will be: %d\n",inches); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
|
||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
int num,tNum,digit,cnt; | ||
int rem; | ||
printf("Enter a number: "); | ||
scanf("%d",&num); | ||
printf("Enter digit to search: "); | ||
scanf("%d",&digit); | ||
cnt=0; | ||
tNum=num; | ||
while(tNum>0) | ||
{ | ||
rem=tNum%10; | ||
if(rem==digit) | ||
cnt++; | ||
tNum/=10; | ||
} | ||
printf("Total occurrence of digit is: %d in number: %d.",cnt,num); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
int number,cnt,i; | ||
int bin[32]; | ||
|
||
printf("Enter decimal number: "); | ||
scanf("%d",&number); | ||
cnt=0; | ||
while(number>0) | ||
{ | ||
bin[cnt]=number%2; | ||
number=number/2; | ||
cnt++; | ||
} | ||
printf("Binary value is: "); | ||
for(i=(cnt-1); i>=0;i--) | ||
printf("%d",bin[i]); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
int number,cnt,i; | ||
char hex[32]; | ||
printf("Enter decimal number: "); | ||
scanf("%d",&number); | ||
cnt=0; | ||
while(number>0) | ||
{ | ||
switch(number%16) | ||
{ | ||
case 10: | ||
hex[cnt]='A'; break; | ||
case 11: | ||
hex[cnt]='B'; break; | ||
case 12: | ||
hex[cnt]='C'; break; | ||
case 13: | ||
hex[cnt]='D'; break; | ||
case 14: | ||
hex[cnt]='E'; break; | ||
case 15: | ||
hex[cnt]='F'; break; | ||
default: | ||
hex[cnt]=(number%16)+0x30; | ||
} | ||
number=number/16; | ||
cnt++; | ||
} | ||
printf("Hexadecimal value is: "); | ||
for(i=(cnt-1); i>=0;i--) | ||
printf("%c",hex[i]); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
int number,cnt,i; | ||
int oct[32]; | ||
|
||
printf("Enter decimal number: "); | ||
scanf("%d",&number); | ||
cnt=0; | ||
while(number>0) | ||
{ | ||
oct[cnt]=number%8; | ||
number=number/8; | ||
cnt++; | ||
} | ||
printf("Octal value is: "); | ||
for(i=(cnt-1); i>=0;i--) | ||
printf("%d",oct[i]); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <math.h> | ||
|
||
int main() | ||
{ | ||
char oct[32]={0}; | ||
int dec,i; | ||
int cnt; | ||
|
||
printf("Enter octal value: "); | ||
gets(oct); | ||
|
||
cnt=0; | ||
dec=0; | ||
for(i=(strlen(oct)-1);i>=0;i--) | ||
{ | ||
dec= dec+ (oct[i]-0x30)*pow((double)8,(double)cnt); | ||
cnt++; | ||
} | ||
|
||
printf("DECIMAL value is: %d",dec); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
|
||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
char i; | ||
printf("Capital (upper) case characters:\n"); | ||
for(i='A'; i<='Z'; i++) | ||
printf("%c ",i); | ||
printf("\n\nLower case characters:\n"); | ||
for(i='a'; i<='z'; i++) | ||
printf("%c ",i); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <stdio.h> | ||
|
||
int checkPrime(int num) | ||
{ | ||
int i; | ||
int flg=0; | ||
for(i=2;i<(num-1);i++) | ||
{ | ||
if(num%i==0) | ||
{ | ||
flg=1; | ||
break; | ||
} | ||
} | ||
if(flg) return 0; | ||
else return 1; | ||
} | ||
|
||
int main() | ||
{ | ||
int i,n; | ||
|
||
printf("Enter the value of N: "); | ||
scanf("%d",&n); | ||
|
||
printf("All prime numbers are from 1 to %d:\n",n); | ||
for(i=1;i<=n;i++) | ||
{ | ||
if(checkPrime(i)) | ||
printf("%d,",i); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
int num,loop; | ||
int sum; | ||
printf("Enter an integer number: "); | ||
scanf("%d",&num); | ||
sum=0; | ||
for(loop=1; loop<num;loop++) | ||
{ | ||
if(num%loop==0) | ||
sum=sum+loop; | ||
} | ||
if(sum==num) | ||
printf("%d is a perfect number.",num); | ||
else | ||
printf("%d is not a perfect number.",num); | ||
|
||
return 0; | ||
} |