Skip to content

Commit

Permalink
my first basic programs
Browse files Browse the repository at this point in the history
  • Loading branch information
adarsh committed Jan 14, 2020
1 parent 6e7fc0f commit 515e809
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 0 deletions.
18 changes: 18 additions & 0 deletions C program to toggle each character in a string.c
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;
}
27 changes: 27 additions & 0 deletions Checking Power of 2 using C program.c
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;
}
15 changes: 15 additions & 0 deletions Convert Feet to Inches.c
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;
}
25 changes: 25 additions & 0 deletions Count Occurrence of a Digit in a Number using C program.c
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;
}
22 changes: 22 additions & 0 deletions Decimal to Binary Conversion.c
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;
}
37 changes: 37 additions & 0 deletions Decimal to Hexadecimal Conversion using C program.c
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;
}
22 changes: 22 additions & 0 deletions Decimal to Octal Conversion using C program.c
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;
}
25 changes: 25 additions & 0 deletions Octal to Decimal Conversion using C program.c
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;
}
16 changes: 16 additions & 0 deletions Print Alphabets in Upper and Lower case using C program.c
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;
}
34 changes: 34 additions & 0 deletions Print all PRIME numbers from 1 to N using C program.c
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;
}
21 changes: 21 additions & 0 deletions checking wheather the number is perfect or not.c
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;
}

0 comments on commit 515e809

Please sign in to comment.