diff --git a/HarpreetSinghNagi/Milestone 3/alphabet to ascii value.cpp b/HarpreetSinghNagi/Milestone 3/alphabet to ascii value.cpp new file mode 100644 index 00000000..dc68815d --- /dev/null +++ b/HarpreetSinghNagi/Milestone 3/alphabet to ascii value.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; +int main() +{ + int st=0, en=0, ascii; + cout<<"input the starting ASCII value : "<>st; + cout<<"input the ending ASCII value : "<>en; + if(st<=0 || st>=255) + st=0; + if(en<=0 || en>=255) + en=255; + for(ascii=st; ascii<=en; ascii++) + { + cout<<"ASCII value of "< +using namespace std; +int main() +{ + long int num=0,i=0 ,fd=0 , ld=0; + cout<<"enter a number : "; + cin>> num; + ld=num%10; //define ld before entering the loop. + while (num>10) + { + num=num/10; + i++; + fd=num; + } + cout<<"first digit of the number is : "< +using namespace std; +int main() +{ + long long int num, ld, ct=0, n=0, a; + cout<<"enter a number : "<>num; + a=num; + for(n=0; n<10; n++) + { ct=0; + a=num; + while(a>0) + { + ld=a%10; + if (ld==n) + { + ct++; + } + a=a/10; + } + cout<<"frequency of "< +using namespace std; +int main() +{ + long long int num, n, ct, ld, m; + cout<<"enter a number : "<>num; + n=0; + while(n<10) + { + ct=0; + cout<<"the frequency of "<0; m=m/10) + { + ld=m%10; + if(ld==n) + { + ct++; + } + } + cout< +#include +using namespace std; +int main() +{ + long long int num=0, ld=0,count=0, digit=0; + cout<<"enter a number : "<< num<> num; + cout<<"enter a digit : "<< digit<> digit; + while (num>0) + { + ld=num%10; + num=num/10; + if (ld==digit) + { + count++; + } + } + cout<<"frequency of "< +#include +using namespace std; +int main() +{ + long long int num=0, ld=0, rev=0, ct=0, i, tz=0, extra=0; + cout<<"enter a number : "<> num; + while (num>0) + { + ld=num%10; + rev=rev*10+ld; + num=num/10; + if(ld==0) + { + ct++; + } + } + while(rev>0) + { + switch (rev%10) + { + case 0: + cout<<"zero "; + extra++; //for counting extra zeros. + break; + case 1: + cout<<"one "; + break; + case 2: + cout<<"two "; + break; + case 3: + cout<<"three "; + break; + case 4: + cout<<"four "; + break; + case 5: + cout<<"five "; + break; + case 6: + cout<<"six "; + break; + case 7: + cout<<"seven "; + break; + case 8: + cout<<"eight "; + break; + default: + cout<<"nine "; + } + rev=rev/10; + } + tz=ct-extra; //tz=trailing zeros + for(i=1; i<=tz; i++) + { + cout<<"zero "; //prints no. of trailing zeros. + } + return 0; +} diff --git a/HarpreetSinghNagi/Milestone 3/palindrome.cpp b/HarpreetSinghNagi/Milestone 3/palindrome.cpp new file mode 100644 index 00000000..34f99e0c --- /dev/null +++ b/HarpreetSinghNagi/Milestone 3/palindrome.cpp @@ -0,0 +1,23 @@ +#include +#include +using namespace std; +int main () +{ + long long int oldnum=0 ,num=0 ,ld=0, rev=0; + cout<<"enter a number : "<< oldnum<> oldnum; + num=oldnum; + while (num>0) + { + ld=num%10; + rev=rev*10+ld; + num=num/10; + } + cout<<"reverse : "< +#include +using namespace std; +int main() +{ + long long int num=0, ld, product; + cout<<"enter a number : "<< num<> num; + product=num%10; + while (num>10) + { + num=num/10; + ld=num%10; + product=product*ld; + } + cout<<"product of digits : "< +#include +using namespace std; +int main() +{ + long long int num=0, ld=0, rev=0; + cout<<"enter a number : "<< num<> num; + while (num>0) + { + ld=num%10; + rev=rev*10+ld; + num=num/10; + } + cout<<"reverse : "< +#include +using namespace std; +int main() +{ + long long int num=0, ld=0, sum=0; + cout<<"enter a number : "<> num; + sum=num%10; + while (num>0) + { + num=num/10; + ld=num%10; + sum=sum+ld; + } + cout<<"sum of digits : "< +using namespace std; +int main() +{ + long long int num=0,i=0 ,fd=0 , ld=0, sum=0; + cout<<"enter a number : "<< num; + cin>> num; + ld=num%10; //define ld before entering the loop. + while (num>10) + { + num=num/10; + i++; + fd=num; + } + cout<<"first digit of the number is : "< +#include +using namespace std; +int main() +{ + long long int num=1,i=0 ,fd=0 , ld=0, newnum=0, oldnum=0; + cout<<"enter a number : "<< oldnum; + cin>> oldnum; + num=oldnum; + ld=num%10; //define ld before entering the loop. + while (num>10) + { + num=num/10; + i++; //i=count + fd=num; + } + cout<<"first digit of the number is : "< +#include +using namespace std; +int main() +{ + int num1=0, num2=0, i, min, hcf; + cout<<"enter a 1st number : "<>num1; + cout<<"enter a 2nd number : "<>num2; + min=(num1>num2) ? num2 : num1; + cout<<" HCF of "<< num1<<" and "<< num2<<" is : "; + for(i=1; i<=min; i++) + { + if(num1%i==0 && num2%i==0) + { + hcf=i; + } + } + cout< +#include +using namespace std; +int main() +{ + int num1=0, num2=0, a, b, mx, lcm=1, p, q; + cout<<"enter a 1st number : "<>num1; + cout<<"enter a 2nd number : "<>num2; + mx=(num1>num2) ? num1 : num2; + cout<<" LCM of "<< num1<<" and "<< num2<<" is : "; + for(a=1; a<=mx; a++) + { + + p=num1*a; + for (b=1; b<=mx; b++) + { + + q=num2*b; + if(p==q) + { + lcm=p; + break; + } + } + if (p==q) + {break;} + } + cout< +#include +using namespace std; +int main() +{ + int num=0, i=1, factorial=1; + cout<<"enter a number : "<>num; + cout<<" --> "< +#include +using namespace std; +int main() +{ + int num=0, i; + cout<<"enter a number : "<>num; + cout<<" factors of "< +#include +using namespace std; +int main () +{ + int num=0, power=0, i=0, product=1; + cout<<"enter a base : "<>num; + cout<<"enter the exponent : "<>power; + for (i=1; i<=power; i++) + { + product=product*num; + } + cout<> en; + for (n=1; n<=en; n++) + { + num=n; + while(num>0) + { + num=num/10; + ct++; + } + + m=n; + sum=0; + while (m>0) + { + ld=m%10; + m=m/10; + sum=sum+(pow(ld,ct)+0.5) ; + } + if(sum==n) + cout<<"--> "< +#include +using namespace std; +int main() +{ + long long int num=0, ld=0, count, sum=0; + cout<<"enter a number to check armstrong number : "<> num; + while (num>0) + { + num=num/10; + count++; + } + while (num>0) + { + num=num/10; + ld=num%10; + sum=sum+pow(ld,count); + } + if(sum==num) + cout<<"it is an armstrong number."< +#include +using namespace std; +int main() +{ + int num, i, prime; + cout<<"enter a number : \n"; + cin>>num; + for(i=2; i +#include +using namespace std; +int main() +{ + int num=0, i, j, prime; + cout<<"enter a number : "<>num; + cout<<"prime factors of "< +using namespace std; +int main() +{ + int start, end, num, i, prime; + cout<<"enter lower limit : \n"; + cin>>start; + cout<<"enter upper limit : \n"; + cin>>end; + for (num=start; num<=end; num++) + { + for(i=2; i "< +using namespace std; +int main() +{ + int start, end, num, i, prime, sum=0; + cout<<"enter lower limit : \n"; + cin>>start; + cout<<"enter upper limit : \n"; + cin>>end; + for (num=start; num<=end; num++) + { + for(i=2; i "< +#include +using namespace std; +int main() +{ + int num=0, i, sum=0; + cout<<"enter a number : "<>num; + //cout<<" factors of "< +#include +using namespace std; +int main() +{ + long long int num=0, n, i, ld, factorial=1, sum=0; + cout<<"enter a number to check strong number : "<> num; + n=num; + while (n>0) + { + ld=n%10; + if(ld!=0) + { + factorial=1; + for(i=1; i<=ld; i++) + { + factorial*=i; + } + } + else + { + ld=1; + } + sum+=factorial; + n=n/10; + } + if(sum==num) + cout<<"--> "< "< +using namespace std; +int main() +{ + int en, n, first=0, second=1, next=2 ; + cout<<"enter the number of terms : "<>en; + cout<<"printing fibonacci series upto "< "< +#include +using namespace std; +int main() +{ + int num=0, i, sum=0, en, n; + cout<<"enter a upper limit : "<>en; + for(n=1; n<=en; n++) + { + num=n; + for(i=1; i"< +#include +using namespace std; +int main() +{ + long long int en, num=0, n, i, ld, factorial=1, sum=0; + cout<<"enter upper limit : "<> en; + for(num=1; num<=en; num++) + { + sum=0; + n=num; + while (n>0) + { + ld=n%10; + if(ld!=0) + { + factorial=1; + for(i=1; i<=ld; i++) + { + factorial*=i; + } + } + else + { + ld=1; + } + sum+=factorial; + n=n/10; + } + if(sum==num) + cout<<"--> "< +#include + using namespace std; + int main() + { + long int num, i, ld=0, sum=0, j=0; + cout<<"enter a binary number : "; + cin>>num; + cout<<"\ndecimal number : "; + for(i=num; i>0; i=i/10) + { + ld=i%10; + sum+=ld*pow(2,j); + j++; + } + cout< + using namespace std; + int main() + { + int num, i, ld=0, rev=0, revld=0, j; + cout<<"enter a binary number : "; + cin>>num; + cout<<"\nhexadecimal number : "; + for(i=num; i>0; i=i/10000) + { + ld=i%10000; + rev=rev*10000+ld; + + } + //cout<0; j=j/10000) + { + revld=j%10000; + if( revld==0000 || revld==000 || revld==00 || revld==0 ) + cout<<"0"; + else if (revld==0001 || revld==001 || revld==01 || revld==1) + cout<<"1"; + else if (revld==0010 || revld==010 || revld==10) + cout<<"2"; + else if (revld==0011 || revld==11) + cout<<"3"; + else if (revld==0100 || revld==100) + cout<<"4"; + else if (revld==0101 || revld==101) + cout<<"5"; + else if (revld==0110 || revld==110) + cout<<"6"; + else if (revld==0111 || revld==111) + cout<<"7"; + else if (revld==1000) + cout<<"8"; + else if (revld==1001) + cout<<"9"; + else if (revld==1010) + cout<<"A"; + else if (revld==1011) + cout<<"B"; + else if (revld==1100) + cout<<"C"; + else if (revld==1101) + cout<<"D"; + else if (revld==1110) + cout<<"E"; + else if (revld==1111) + cout<<"F"; + else + {cout<<"wrong input..."; + break;} + + } + + } diff --git a/HarpreetSinghNagi/Milestone 7/binary to octal number system.cpp b/HarpreetSinghNagi/Milestone 7/binary to octal number system.cpp new file mode 100644 index 00000000..2a0f19a8 --- /dev/null +++ b/HarpreetSinghNagi/Milestone 7/binary to octal number system.cpp @@ -0,0 +1,58 @@ +/* + *Binary Number System: + *Binary number system is a base 2 number system. + *Binary number system uses only 2 symbols to represent all its numbers i.e. 0 and 1. + *Octal Number System: + *Octal number system is a base 8 number system. + *Octal number system uses 8 symbols to represent all its numbers i.e. 0 1 2 3 4 5 6 7. + Binary Octal + 000 0 + 001 1 + 010 2 + 011 3 + 100 4 + 101 5 + 110 6 + 111 7 + */ + #include + using namespace std; + int main() + { + int num, i, ld=0, rev=0, revld=0, j; + cout<<"enter a binary number : "; + cin>>num; + cout<<"octal number : "; + for(i=num; i>0; i=i/1000) + { + ld=i%1000; + rev=rev*1000+ld; + + } + //cout<0; j=j/1000) + { + revld=j%1000; + if( revld==000 || revld==00 || revld==0 ) + cout<<"0"; + else if (revld==001 || revld==01 || revld==1) + cout<<"1"; + else if (revld==010 || revld==10) + cout<<"2"; + else if (revld==011 || revld==11) + cout<<"3"; + else if (revld==100) + cout<<"4"; + else if (revld==101) + cout<<"5"; + else if (revld==110) + cout<<"6"; + else if (revld==111) + cout<<"7"; + else + {cout<<"wrong input..."; + break;} + + } + + } diff --git a/HarpreetSinghNagi/Milestone 7/decimal to binary.cpp b/HarpreetSinghNagi/Milestone 7/decimal to binary.cpp new file mode 100644 index 00000000..260b7e66 --- /dev/null +++ b/HarpreetSinghNagi/Milestone 7/decimal to binary.cpp @@ -0,0 +1,25 @@ +/* +Decimal number system +Decimal number system is a base 10 number system. +Decimal number system uses only 10 symbols to represent all number i.e. 0123456789 + +Binary number system +Binary number system is a base 2 number system. +Binary number system uses only 2 symbols to represent all numbers i.e. 0 and 1 +*/ +#include +using namespace std; +int main() +{ + int decimal, rem, binary=0, place=1, n; + cout<<"Enter a decimal number : "<>decimal; + cout<<"binary number : "; + for (n=decimal; n>0 ;n=n/2) + { + rem=n%2; + binary = rem*place + binary; + place*=10; + } + cout< +#include +using namespace std; +int main() +{ + int decimal, rem, place=1, n, i=0; + char hexadecimal[17]; + char HEXVALUES[]={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + cout<<"Enter a decimal number : "; + cin>>decimal; + for (n=decimal; n>0 ;n=n/16) + { + rem=n%16; + hexadecimal[i] = HEXVALUES[rem]; + i++; + } + hexadecimal[i]='\0'; + cout<<"hexadecimal number : "; + strrev(hexadecimal); + cout< +using namespace std; +int main() +{ + int decimal, rem, octal=0, place=1, n; + cout<<"Enter a decimal number : "<>decimal; + cout<<"octal number : "; + for (n=decimal; n>0 ;n=n/8) + { + rem=n%8; + octal = rem*place + octal; + place*=10; + } + cout< + using namespace std; + int main() + { + char hex[17]; // hex[16]=\0. it has 17 elements from 0 to 16. + int i; // declare i under integer data type . + cout<<"enter a hexadecimal number : "; + cin>>hex; + cout<<"binary number : "; + for(i=0; hex[i]!='\0'; i++) + { + if( hex[i]=='0' ) + cout<<"0000"; + else if ( hex[i]=='1' ) + cout<<"0001"; + else if (hex[i]=='2' ) + cout<<"0010"; + else if (hex[i]=='3' ) + cout<<"0011"; + else if (hex[i]=='4') + cout<<"0100"; + else if (hex[i]=='5' ) + cout<<"0101"; + else if (hex[i]=='6') + cout<<"0110"; + else if (hex[i]=='7') + cout<<"0111"; + else if (hex[i]=='8') + cout<<"1000"; + else if (hex[i]=='9') + cout<<"1001"; + else if (hex[i]=='A' || hex[i]=='a') + cout<<"1010"; + else if (hex[i]=='B' || hex[i]=='b') + cout<<"1011"; + else if (hex[i]=='C' || hex[i]=='c') + cout<<"1100"; + else if (hex[i]=='D' || hex[i]=='c') + cout<<"1101"; + else if (hex[i]=='E' || hex[i]=='d') + cout<<"1110"; + else if (hex[i]=='F' || hex[i]=='f') + cout<<"1111"; + else + {cout<<"wrong input..."; + break;} + + } + + } diff --git a/HarpreetSinghNagi/Milestone 7/hexadecimal to decimal.cpp b/HarpreetSinghNagi/Milestone 7/hexadecimal to decimal.cpp new file mode 100644 index 00000000..ea0979bf --- /dev/null +++ b/HarpreetSinghNagi/Milestone 7/hexadecimal to decimal.cpp @@ -0,0 +1,31 @@ +#include +#include //if we are using pow() function. +#include //if we are using strings. + using namespace std; + int main() + { + char hex[17]; + long int num, i, sum=0, j=0; + cout<<"enter a hexadecimal number : "; + cin>>hex; + j=strlen(hex) - 1; //strlen() is used for finding the length of a string. + cout<<"decimal number : "; + for(i=0; hex[i]!='\0'; i++) + { + if(hex[i]>='0' && hex[i]<='9') + { + num = hex[i] - 48; //num is stored in int data type which converts hex[i] into its ascii value. + } + else if(hex[i]>='a' && hex[i]<='f') + { + num = hex[i] - 97 + 10; + } + else if(hex[i]>='A' && hex[i]<='F') + { + num = hex[i] - 65 + 10; + } + sum+=num*pow(16,j); //as we are starting from left side. j is decremented. + j--; + } + cout< + using namespace std; + int main() + { + char hex[17]; // hex[16]=\0. it has 17 elements from 0 to 16. + long long int i, binary=0, bin=0, rev=0; // declare i under integer data type . + int n, ld=0, revld=0, j; + cout<<"enter a hexadecimal number : "; + cin>>hex; + cout<<"binary number : "; + for(i=0; hex[i]!='\0'; i++) + { + if( hex[i]=='0' ) + binary=0; + else if ( hex[i]=='1' ) + binary=1; + else if (hex[i]=='2' ) + binary=10; + else if (hex[i]=='3' ) + binary=11; + else if (hex[i]=='4') + binary=100; + else if (hex[i]=='5' ) + binary=101; + else if (hex[i]=='6') + binary=110; + else if (hex[i]=='7') + binary=111; + else if (hex[i]=='8') + binary=1000; + else if (hex[i]=='9') + binary=1001; + else if (hex[i]=='A' || hex[i]=='a') + binary=1010; + else if (hex[i]=='B' || hex[i]=='b') + binary=1011; + else if (hex[i]=='C' || hex[i]=='c') + binary=1100; + else if (hex[i]=='D' || hex[i]=='c') + binary=1101; + else if (hex[i]=='E' || hex[i]=='d') + binary=1110; + else if (hex[i]=='F' || hex[i]=='f') + binary=1111; + else + {cout<<"invalid input..."; + break;} + bin=bin*10000 + binary; + } + cout<0; n=n/1000) + { + ld=n%1000; + rev=rev*1000+ld; + + } + for(j=rev; j>0; j=j/1000) + { + revld=j%1000; + if( revld==000 || revld==00 || revld==0 ) + cout<<"0"; + else if (revld==001 || revld==01 || revld==1) + cout<<"1"; + else if (revld==010 || revld==10) + cout<<"2"; + else if (revld==011 || revld==11) + cout<<"3"; + else if (revld==100) + cout<<"4"; + else if (revld==101) + cout<<"5"; + else if (revld==110) + cout<<"6"; + else if (revld==111) + cout<<"7"; + else + {cout<<"wrong input..."; + break;} + + } + + } diff --git a/HarpreetSinghNagi/Milestone 7/octal to binary.cpp b/HarpreetSinghNagi/Milestone 7/octal to binary.cpp new file mode 100644 index 00000000..465c7038 --- /dev/null +++ b/HarpreetSinghNagi/Milestone 7/octal to binary.cpp @@ -0,0 +1,40 @@ + + #include + using namespace std; + int main() + { + int num, i, ld=0, rev=0, revld=0, j; + cout<<"enter a octal number : "; + cin>>num; + cout<<"\nbinary number : "; + for(i=num; i>0; i=i/10) + { + ld=i%10; + rev=rev*10+ld; + + } + //cout<0; j=j/10) + { + revld=j%10; + if( revld==0 ) + cout<<"000"; + else if (revld==1) + cout<<"001"; + else if (revld==2) + cout<<"010"; + else if (revld==3) + cout<<"011"; + else if (revld==4) + cout<<"100"; + else if (revld==5) + cout<<"101"; + else if (revld==6) + cout<<"110"; + else if (revld==7) + cout<<"111"; + else + {cout<<"wrong input..."; + break;} + } + } diff --git a/HarpreetSinghNagi/Milestone 7/octal to decimal.cpp b/HarpreetSinghNagi/Milestone 7/octal to decimal.cpp new file mode 100644 index 00000000..076caa16 --- /dev/null +++ b/HarpreetSinghNagi/Milestone 7/octal to decimal.cpp @@ -0,0 +1,17 @@ +#include +#include + using namespace std; + int main() + { + long int num, i, ld=0, sum=0, j=0; + cout<<"enter a octal number : "; + cin>>num; + cout<<"\ndecimal number : "; + for(i=num; i>0; i=i/10) + { + ld=i%10; + sum+=ld*pow(8,j); + j++; + } + cout< + using namespace std; + int main() + { + int OCTALVALUES[] = {0, 1, 10, 11, 100, 101, 110, 111}; +//binary to octal values {0, 1, 2 , 3 , 4 , 5 , 6 , 7 } + + long long octal, i, binary, place; + int ld=0, digit, n, j, rev=0, revld=0; + + place = 1; + binary = 0; + + cout<<"Enter any octal number: "; + cin>>octal; + i = octal; + while(i > 0) + { + digit = i % 10; + binary = (OCTALVALUES[digit] * place) + binary; + i /= 10; + place *= 1000; + } + cout<<"binary number :"<0; n=n/10000) + { + ld=n%10000; + rev=rev*10000+ld; + + } + for(j=rev; j>0; j=j/10000) + { + revld=j%10000; + if( revld==0000 || revld==000 || revld==00 || revld==0 ) + cout<<"0"; + else if (revld==0001 || revld==001 || revld==01 || revld==1) + cout<<"1"; + else if (revld==0010 || revld==010 || revld==10) + cout<<"2"; + else if (revld==0011 || revld==11) + cout<<"3"; + else if (revld==0100 || revld==100) + cout<<"4"; + else if (revld==0101 || revld==101) + cout<<"5"; + else if (revld==0110 || revld==110) + cout<<"6"; + else if (revld==0111 || revld==111) + cout<<"7"; + else if (revld==1000) + cout<<"8"; + else if (revld==1001) + cout<<"9"; + else if (revld==1010) + cout<<"A"; + else if (revld==1011) + cout<<"B"; + else if (revld==1100) + cout<<"C"; + else if (revld==1101) + cout<<"D"; + else if (revld==1110) + cout<<"E"; + else if (revld==1111) + cout<<"F"; + else + {cout<<"wrong input..."; + break;} + + } + } diff --git a/HarpreetSinghNagi/Milestone 7/one's complement of binary no..cpp b/HarpreetSinghNagi/Milestone 7/one's complement of binary no..cpp new file mode 100644 index 00000000..e96db67d --- /dev/null +++ b/HarpreetSinghNagi/Milestone 7/one's complement of binary no..cpp @@ -0,0 +1,50 @@ +/* +Ones complement of a binary number is defined as value obtained by inverting all binary bits. +It is the result of swapping all 1s to 0s and all 0s to 1s. +for eg : 10010011 changes to 01101100 +*/ +#include +using namespace std; +int main () +{ + int num, i, j, ld=0, rev=0, revld, ct=0, extra=0, tz=0; + cout<<"enter a binary number : "<>num; + cout<<"one's complement of "<0; i=i/10) + { + ld=i%10; + rev=rev*10+ld; + if(ld==0) //for counting total no. of zeros. + { + ct++; + } + } + for(j=rev; j>0; j=j/10) + { + revld=j%10; + if (revld!=1 && revld!=0) + { + cout<<"wrong input....."< +using namespace std; +int main() +{ + int rows, coef=1, space, i, j; + cout<<"Enter number of rows: "; + cin>>rows; + for (i=0; i +using namespace std; +int main() +{ + int SIZE=8; + char binary[SIZE + 1], onesComp[SIZE + 1], twosComp[SIZE + 1]; // SIZE+1 is done for null character. + int i, carry=1; + + cout<<"Enter "<>binary; + + /* Find ones complement of the binary number */ + for(i=0; i=0; i--) //i is decremented so that 1 is carried over from right side. no need to reverse. + { + if(onesComp[i] == '1' && carry == 1) + { + twosComp[i] = '0'; + } + else if(onesComp[i] == '0' && carry == 1) + { + twosComp[i] = '1'; + carry = 0; //At this point carry becomes zero and condition becomes false. + } + else + { + twosComp[i] = onesComp[i]; + } + } + twosComp[SIZE] = '\0'; + + cout<<"Original binary = "<>a; + + if(a>0) + cout<<"The absolute value of number is:"< + +using namespace std; + +int main() +{ + int a,b,c; + + cout<<"Enter the age of all the 3"; + cin>>a>>b>>c; + + cout<<"You entered a="<b && a>c) + { + + cout<<"oldest is a"; + if( b>c) + cout<<"youngest is b"; + else + cout<<"youngest is c"; + + } + + + else if(b>a && b>c) + { + + cout<<"oldest is b"; + if(a>c) + cout<<"youngest is c"; + else + cout<<"youngest is a"; + + } + + else if(c>a && c>>b); + { + cout<<"The oldest is c"; + if(a>b) + cout<<"youngest is b"; + else + cout<<"youngest is a"; + } + + + + return 0; +} \ No newline at end of file diff --git a/HarpreetSinghNagi/Mlestone2/age.exe b/HarpreetSinghNagi/Mlestone2/age.exe new file mode 100644 index 00000000..759b716f Binary files /dev/null and b/HarpreetSinghNagi/Mlestone2/age.exe differ diff --git a/HarpreetSinghNagi/Mlestone2/allu.cpp b/HarpreetSinghNagi/Mlestone2/allu.cpp new file mode 100644 index 00000000..ce59e58e --- /dev/null +++ b/HarpreetSinghNagi/Mlestone2/allu.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; + + +int main() +{ + int a; + cout<<"Enter any number:"; + cin>>a; + + + cout<<"The absolute value of number is:"< +int main() +{ + using namespace std; + int b,a; + bool c; + cin >> a; + cin >> b; + c = (a < 50 || a < b) ; + cout< + +using namespace std; + +int main() + +{ + int held, attend , a; + char med; + + cout<<"Enter the total number of class that held "; + cin>>held; + cout<<"Enter the munber for which for which u attend the class "; + cin>>attend; + cout<<"Enter Y if u have any medical history and N for not"; + cin>>med; + + a= (attend/held)*100; + + + if(a>75) + { + cout<<"You can sit in exam"; + } + + else if (a<75 && (med=='Y' || med=='y')) + { + cout<<"You can sit in exam"; + } + + else + cout<<"You can't sit in exam"; + + return 0; + + + + + + +} \ No newline at end of file diff --git a/HarpreetSinghNagi/Mlestone2/attendence.exe b/HarpreetSinghNagi/Mlestone2/attendence.exe new file mode 100644 index 00000000..9389b0c3 Binary files /dev/null and b/HarpreetSinghNagi/Mlestone2/attendence.exe differ diff --git a/HarpreetSinghNagi/Mlestone2/bet.cpp b/HarpreetSinghNagi/Mlestone2/bet.cpp new file mode 100644 index 00000000..69ee1d85 --- /dev/null +++ b/HarpreetSinghNagi/Mlestone2/bet.cpp @@ -0,0 +1,18 @@ +#include +#include +using namespace std; + +int main() { + + int a; + long b; + char c; + float d; + double e; + cin >> a >> b >> c >> d >> e; + cout<< a << '\n' << b << '\n' << c << '\n'; + cout << std::fixed << std::setprecision(3) << d << '\n'; + cout << std::fixed << std::setprecision(9) << e << '\n'; + + return 0; +} \ No newline at end of file diff --git a/HarpreetSinghNagi/Mlestone2/bool.cpp b/HarpreetSinghNagi/Mlestone2/bool.cpp new file mode 100644 index 00000000..59d97cd2 --- /dev/null +++ b/HarpreetSinghNagi/Mlestone2/bool.cpp @@ -0,0 +1,27 @@ +#include + +using namespace std; + +int main() + +{ + bool result1 {false}; + bool result {true}; + + int x{2},y{5},z{0}; + cout<< result1< + +using namespace std; + +int main() +{ + +char a; + +cout<<"Enter any character "; +cin>>a; + +if(a>=97 && a<=122) +{ +cout<<"The entered input is in lower case"; +} + +else if (a>=65 && a<=90) +{ +cout<<"The entered input is in upper case"; +} + +else +{ +cout<<"YOou entered a wrong akshar"; +} +return 0; + +} diff --git a/HarpreetSinghNagi/Mlestone2/case.exe b/HarpreetSinghNagi/Mlestone2/case.exe new file mode 100644 index 00000000..563bbe8d Binary files /dev/null and b/HarpreetSinghNagi/Mlestone2/case.exe differ diff --git a/HarpreetSinghNagi/Mlestone2/complex.cpp b/HarpreetSinghNagi/Mlestone2/complex.cpp new file mode 100644 index 00000000..a389dd7e --- /dev/null +++ b/HarpreetSinghNagi/Mlestone2/complex.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; + +int main() +{ + int a,b,sum,c; + + + cout<<"Enter number"; + cin>>a; + + + + + for(int i=0;i<2;i++) + { + b=a%10; + a=a/10; + } + + + a=a/100; + + cout<<"second last digit is "< + +using namespace std; + +int main() +{ + int units{0}, cost{0} , total_cost{0} , dis{0}; + + + cout<<"Enter the quantity of units u purchased"; + cin>>units; + + cost=100* units; + + if(cost>1000) + { + dis= ((10*cost)/100); + total_cost= cost-dis; + } + else + { + total_cost= cost; + } + + cout<<"Total cost of your products are"<< total_cost; + + return 0; +} diff --git a/HarpreetSinghNagi/Mlestone2/cost.exe b/HarpreetSinghNagi/Mlestone2/cost.exe new file mode 100644 index 00000000..3cd587ad Binary files /dev/null and b/HarpreetSinghNagi/Mlestone2/cost.exe differ diff --git a/HarpreetSinghNagi/Mlestone2/example.cpp b/HarpreetSinghNagi/Mlestone2/example.cpp new file mode 100644 index 00000000..d24c65f2 --- /dev/null +++ b/HarpreetSinghNagi/Mlestone2/example.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; + +int main() +{ + int n; + + cout << "Enter a positive integer: "; + cin >> n; + + for (int i = 1; i <= 10; ++i) { + cout << n << " * " << i << " = " << n * i << endl; + } + + return 0; +} \ No newline at end of file diff --git a/HarpreetSinghNagi/Mlestone2/example.exe b/HarpreetSinghNagi/Mlestone2/example.exe new file mode 100644 index 00000000..6601c770 Binary files /dev/null and b/HarpreetSinghNagi/Mlestone2/example.exe differ diff --git a/HarpreetSinghNagi/Mlestone2/fun.cpp b/HarpreetSinghNagi/Mlestone2/fun.cpp new file mode 100644 index 00000000..0dbccbfb --- /dev/null +++ b/HarpreetSinghNagi/Mlestone2/fun.cpp @@ -0,0 +1,11 @@ +#include +int main() +{ + using namespace std; + int b,a; + bool c; + cin >> a; + cin >> b; + c= (a < 50 || a < b) ; + return 0; +} diff --git a/HarpreetSinghNagi/Mlestone2/fun.exe b/HarpreetSinghNagi/Mlestone2/fun.exe new file mode 100644 index 00000000..ced1ac9d Binary files /dev/null and b/HarpreetSinghNagi/Mlestone2/fun.exe differ diff --git a/HarpreetSinghNagi/Mlestone2/grade.cpp b/HarpreetSinghNagi/Mlestone2/grade.cpp new file mode 100644 index 00000000..21966429 --- /dev/null +++ b/HarpreetSinghNagi/Mlestone2/grade.cpp @@ -0,0 +1,50 @@ +/*A school has following rules for grading system: +a. Below 25 - F +b. 25 to 45 - E +c. 45 to 50 - D +d. 50 to 60 - C +e. 60 to 80 - B +f. Above 80 - A +Ask user to enter marks and print the corresponding grade.*/ + +#include + +using namespace std; + +int main() +{ + int marks; + + cout<<"Enter your marks percentage"; + cin>>marks; + + if(marks<25) + + cout<<"F"; + + else if(marks<25 && marks>45) + + cout<<"E"; + + else if(marks<45 && marks>50) + + cout<<"D"; + + else if(marks<50 && marks>60) + + cout<<"C"; + + else if(marks<60 && marks>80) + + cout<<"B"; + + else if(marks>80) + + cout<<"A"; + + else + + cout<<"invalid output"; + + return 0; +} \ No newline at end of file diff --git a/HarpreetSinghNagi/Mlestone2/grade.exe b/HarpreetSinghNagi/Mlestone2/grade.exe new file mode 100644 index 00000000..7da4bcb6 Binary files /dev/null and b/HarpreetSinghNagi/Mlestone2/grade.exe differ diff --git a/HarpreetSinghNagi/Mlestone2/greater.cpp b/HarpreetSinghNagi/Mlestone2/greater.cpp new file mode 100644 index 00000000..4dfd4de5 --- /dev/null +++ b/HarpreetSinghNagi/Mlestone2/greater.cpp @@ -0,0 +1,27 @@ +//Take two int values from user and print greatest among them. + + +#include + +using namespace std; + +int main () +{ + int a{0} , b{0}; + + cout<<"Enter value for ist number"; + cin>>a; + cout<<"Enter value for 2nd number"; + cin>>b; + + if(a>b) + { + cout<<"ist number is greater i.e = "<>year; + + if (year % 4 == 0) + { + if (year % 100 == 0) + { + if (year % 400 == 0) + cout << year << " is a leap year."; + else + cout << year << " is not a leap year."; + } + else + cout << year << " is a leap year."; + } + else + cout << year << " is not a leap year."; + return 0; + +} diff --git a/HarpreetSinghNagi/Mlestone2/leap.exe b/HarpreetSinghNagi/Mlestone2/leap.exe new file mode 100644 index 00000000..92ffe34e Binary files /dev/null and b/HarpreetSinghNagi/Mlestone2/leap.exe differ diff --git a/HarpreetSinghNagi/Mlestone2/output.cpp b/HarpreetSinghNagi/Mlestone2/output.cpp new file mode 100644 index 00000000..78ee30c4 --- /dev/null +++ b/HarpreetSinghNagi/Mlestone2/output.cpp @@ -0,0 +1,39 @@ +/*If +x = 2 +y = 5 +z = 0 +then find values of the following expressions: +a. x == 2 +b. x != 5 +c. x != 5 && y >= 5 +d. z != 0 || x == 2 +e. !(y < 10) */ + + +#include + +using namespace std; + +int main() + +{ + bool result1 {false}; + bool result {true}; + + int x{2},y{5},z{0}; + cout<< result1< + +using namespace std; + +int main() +{ + int number,count{0}; + cout<<"enter number"; + cin>>number; + + for(int i = 0; i <= number; i++) + { + if(number == i*i) + { + cout<<"perfect square"; + count++; + break; + } + + + } + + + if(count!=1) + { + cout<<"not"; + } + + + return 0; +} \ No newline at end of file diff --git a/HarpreetSinghNagi/Mlestone2/perfect.exe b/HarpreetSinghNagi/Mlestone2/perfect.exe new file mode 100644 index 00000000..87ab296d Binary files /dev/null and b/HarpreetSinghNagi/Mlestone2/perfect.exe differ diff --git a/HarpreetSinghNagi/Mlestone2/pet.cpp b/HarpreetSinghNagi/Mlestone2/pet.cpp new file mode 100644 index 00000000..f2b5b94d --- /dev/null +++ b/HarpreetSinghNagi/Mlestone2/pet.cpp @@ -0,0 +1,18 @@ +#include +#include +using namespace std; + +int main() { + + int a; + long b; + char c; + float d; + double e; + cin >> a >> b >> c >> d >> e; + cout<< a << '\n' << b << '\n' << c << '\n'; + cout << fixed << setprecision(3) << d << '\n'; + cout << fixed << setprecision(9) << e << '\n'; + + return 0; +} \ No newline at end of file diff --git a/HarpreetSinghNagi/Mlestone2/pet.exe b/HarpreetSinghNagi/Mlestone2/pet.exe new file mode 100644 index 00000000..02ceaff9 Binary files /dev/null and b/HarpreetSinghNagi/Mlestone2/pet.exe differ diff --git a/HarpreetSinghNagi/Mlestone2/practice.cpp b/HarpreetSinghNagi/Mlestone2/practice.cpp new file mode 100644 index 00000000..1ff1fd32 --- /dev/null +++ b/HarpreetSinghNagi/Mlestone2/practice.cpp @@ -0,0 +1,17 @@ +#include + +using namespace std; + +int main() +{ + int i,n; + cout<<"enter a nos"; + cin>>n; + while (i<=n) + { + cout< + +using namespace std; + +int main() +{ + int n,count{0},rem{0},sum{0}; + cout<<"enter n"; + cin>>n; + + while(n!=0) + { + rem=n%10; + n=n/10; + sum=sum+rem; + count++; + + } + + cout< +#include +#include + +int main() +{ + int i=0,play,s,player_point=0,Comp_point=0; + char name[20]; + printf("Enter Player name\n"); + gets(name); + printf("Enter 0 for rock\n"); + printf("Enter 1 for paper\n"); + printf("Enter 2 for scissor\n\n"); + + srand(time(NULL)); + while(i<3) + { + printf("%s turn\nEnter No. : ",name); + scanf("%d",&play); + printf("Computer turn\nEnter No. : "); + s=rand()%3; + printf("%d",s); + if(play==0&&s==1) + Comp_point++; + else if(play==0&&s==2) + player_point++; + else if(play==1&&s==0) + player_point++; + else if(play==1&&s==2) + Comp_point++; + else if(play==2&&s==0) + Comp_point++; + else if(play==2&&s==1) + player_point++; + i++; + printf("\n"); + } + if(player_point>Comp_point) + printf("%s wins",name); + else if(player_point==Comp_point) + printf("Match draw"); + else + printf("%s loses",name); + + return 0; +} \ No newline at end of file diff --git a/HarpreetSinghNagi/Mlestone2/pro.exe b/HarpreetSinghNagi/Mlestone2/pro.exe new file mode 100644 index 00000000..0f8d76c4 Binary files /dev/null and b/HarpreetSinghNagi/Mlestone2/pro.exe differ diff --git a/HarpreetSinghNagi/Mlestone2/prog1.cpp b/HarpreetSinghNagi/Mlestone2/prog1.cpp new file mode 100644 index 00000000..fb6ea813 --- /dev/null +++ b/HarpreetSinghNagi/Mlestone2/prog1.cpp @@ -0,0 +1,20 @@ +//Write a program to check whether a number is even or odd + +#include +using namespace std; + +int main () +{ + int n; + + cout << "Please Enter the number : "; + cin >> n; + + if (n%2 == 0) + cout< +using namespace std; + +int main() +{ + int n, reversedNumber = 0, remainder; + + cout << "Enter an integer: "; + cin >> n; + + while(n != 0) + { + remainder = n%10; + reversedNumber = reversedNumber*10 + remainder; + n = n/10; + } + + cout << "Reversed Number = " << reversedNumber; + + return 0; +} + diff --git a/HarpreetSinghNagi/Mlestone2/reverse.exe b/HarpreetSinghNagi/Mlestone2/reverse.exe new file mode 100644 index 00000000..da12212e Binary files /dev/null and b/HarpreetSinghNagi/Mlestone2/reverse.exe differ diff --git a/HarpreetSinghNagi/Mlestone2/salary.cpp b/HarpreetSinghNagi/Mlestone2/salary.cpp new file mode 100644 index 00000000..4b63aca0 --- /dev/null +++ b/HarpreetSinghNagi/Mlestone2/salary.cpp @@ -0,0 +1,28 @@ +/*A company decided to give bonus of 5% to employee if his/her year of service is more than 5 years. +Ask user for their salary and year of service and print the net bonus amount.*/ + +#include + +using namespace std; +int main() +{ + + + +int salary,service, bonus, total_salary; + +cout<<"Enter your slary and your time for how long u r serving this company"; +cin>>salary>>service; + +if(service > 5) +{ + bonus = 5*salary/100; + total_salary = bonus+salary; +} +else +{ + total_salary = salary; +} +cout<<"Your salary by adding bonus is"< +#include +using namespace std; + +int main() { + + int a; + long b; + char c; + float d; + double e; + cin >> a >> b >> c >> d >> e; + cout<< a << '\n' << b << '\n' << c << '\n'; + cout << std::fixed << std::setprecision(3) << d << '\n'; + cout << std::fixed << std::setprecision(9) << e << '\n'; + + return 0; +} \ No newline at end of file diff --git a/HarpreetSinghNagi/Mlestone2/set.exe b/HarpreetSinghNagi/Mlestone2/set.exe new file mode 100644 index 00000000..1f71c0de Binary files /dev/null and b/HarpreetSinghNagi/Mlestone2/set.exe differ diff --git a/HarpreetSinghNagi/Mlestone2/squareornot.cpp b/HarpreetSinghNagi/Mlestone2/squareornot.cpp new file mode 100644 index 00000000..1da9ccc8 --- /dev/null +++ b/HarpreetSinghNagi/Mlestone2/squareornot.cpp @@ -0,0 +1,28 @@ +// WAP Take values of length and breadth of a rectangle from user and check if it is square or not. + +#include + +using namespace std; + +int main() +{ + +int len{0} , brth{0}; + +cout<<"Enter the length of rectangle"; +cin>> len; +cout<<"Enter the breadth of rectangle "; +cin>> brth; + +if(len == brth) +{ + cout<<"Your rectangle is square"; +} +else +{ + cout<<"It is not square"; +} + +return 0; + +} diff --git a/HarpreetSinghNagi/Mlestone2/squareornot.exe b/HarpreetSinghNagi/Mlestone2/squareornot.exe new file mode 100644 index 00000000..43bf2fd2 Binary files /dev/null and b/HarpreetSinghNagi/Mlestone2/squareornot.exe differ diff --git a/HarpreetSinghNagi/milestone1/1. Welcome to GCI.cpp b/HarpreetSinghNagi/milestone1/1. Welcome to GCI.cpp deleted file mode 100644 index 976bf4eb..00000000 --- a/HarpreetSinghNagi/milestone1/1. Welcome to GCI.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// Created by Utkarsh Thakur on 13/05/20. -// Copyright © 2020 Utkarsh Thakur. All rights reserved. -// - -#include -using namespace std; - -int main() -{ - cout << "Welcome to Girl Code IT...\n"; - return 0; -} diff --git a/HarpreetSinghNagi/milestone1/2. Greater number among 2 entered.cpp b/HarpreetSinghNagi/milestone1/2. Greater number among 2 entered.cpp deleted file mode 100644 index 609d6b61..00000000 --- a/HarpreetSinghNagi/milestone1/2. Greater number among 2 entered.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// Created by Utkarsh Thakur on 13/05/20. -// Copyright © 2020 Utkarsh Thakur. All rights reserved. -// - -#include -using namespace std; - -int main() -{ -// Taking 2 variables to store the 2 numbers that user will enter. - int n1, n2; - -// I/O regarding the numbers for the user friendly interface. - cout<<"Enter the first number: "; - cin>>n1; - cout<<"Enter the second number: "; - cin>>n2; - -// IF & ELSE statement for the compiler system to compare the numbers entered. - if (n1>n2) - { - cout<<"First number is the largest one among the 2 entered \n\n"; - } - else if (n1 -using namespace std; - -int main() -{ -// Taking variables to store the number that user will enter and for the in-program calculation. - int n1; - -// I/O statments regarding the number for user friendly interface. - cout<<"Enter the first number: "; - cin>>n1; - -// IF & ELSE statement for compiler system to check which no. is even or odd by simple math. - if(n1 % 2 ==0) - { - cout<<"Entered number is even...\n\n"; - } - - else - { - cout<<"Entered number is odd...\n\n"; - } - return 0; -} diff --git a/HarpreetSinghNagi/milestone1/4. Negative, Zero or Positive.cpp b/HarpreetSinghNagi/milestone1/4. Negative, Zero or Positive.cpp deleted file mode 100644 index fc7fc711..00000000 --- a/HarpreetSinghNagi/milestone1/4. Negative, Zero or Positive.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Created by Utkarsh Thakur on 13/05/20. -// Copyright © 2020 Utkarsh Thakur. All rights reserved. - -#include -using namespace std; - -int main() -{ -// Taking variable to store the number which user will enter. - int n1; - -// I/O Statements regarding the number for a user friendly interface. - cout<<"Check wheather the number is positive, negative or zero...!\n\n"; - cout<<"Enter the number: "; - cin>>n1; - -// IF/ELSE statement to compare the entered number is +ve, -ve or 0. - if(n1>0) - { - cout<<"Number is Positive.\n\n"; - } - else if(n1<0) - { - cout<<"Number is Negative.\n\n"; - } - else - { - cout<<"Number is Zero.\n\n"; - } - return 0; -} diff --git a/HarpreetSinghNagi/milestone1/multiplication.cpp b/HarpreetSinghNagi/milestone1/multiplication.cpp deleted file mode 100644 index e3e6681a..00000000 --- a/HarpreetSinghNagi/milestone1/multiplication.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// Created by Utkarsh Thakur on 13/05/20. -// Copyright © 2020 Utkarsh Thakur. All rights reserved. - -#include -using namespace std; - -int main() -{ -// Taking variable to store the numbers which user will enter and for in-program calculations. - int n1,n2; - -// I/O Statements regarding the number for a user friendly interface. - cout<<"MULTIPLICATION\n\n"; - cout<<"Enter the first number: "; - cin>>n1; - cout<<"Enter the second number: "; - cin>>n2; - -// Calculation and result part. - cout<<"\n\nMultiplication is: "<