Home Blog Page 14

Leap Year in C, C for beginners

0

According to the definition, a year that is divisible by 4, 100 and 400 is known as a leap year. Also if a year is exactly divisible by 4 but not by 100 then it is also a leap year. Another important thing you must note is, if a year is exactly divisible by 4 and 100 but not by 400 then it is not a leap year. Based on this general understanding, we’ll build a programming logic to determine if a year entered by the user is leap year or not. We’ll also discuss how to print leap years between some range in this article.

1. Program to check whether a year entered by the user is leap year or not in C.

#include<stdio.h>
void main()
{
    int yr;
    printf("Enter year: ");
    scanf("%d",&yr);
    if(yr % 4 == 0)
    {
        if( yr % 100 == 0)
        {
            if ( yr % 400 == 0)
                printf("%d is a Leap Year", yr);
            else
                printf("%d is not a Leap Year", yr);
        }
        else
            printf("%d is a Leap Year", yr );
    }
    else
        printf("%d is not a Leap Year", yr);
 getch(); // for MS DOS based compilers like Turbo C
}

2. To print leap years in-between range of years provided by the user in C.

#include <stdio.h>
int main()
{
	int year1, year2, i;
	printf("Enter the Starting year: ");
   	scanf("%d", &year1);
	printf("Enter the Ending Year: ");
   	scanf("%d", &year2);
	printf("Leap Year between %d and %d are as below:\n",year1,year2);	
	for(i=Year1; i <= year2; i++){
		if( (0 == i % 4) && (0 != i % 100) || (0 == i % 400) ){
		    printf("%d\n", i);
		}
	}
    getch(); // for MS-DOS based compilers like Turbo C
}

Here, in the code portion

for(i=Year1; i <= year2; i++){
         if( (0 == i % 4) && (0 != i % 100) || (0 == i % 400) ){
             printf("%d\n", i);
         }
     }

for each ith year starting from starting year entered by user(i.e. initial value of i) as year1, we need to check if the year i is leap year or not? If yes, print it and if not keep iterating around loop until and unless value of i become ending year.

Thank You!

You may also check my previous articles

Everything about ASCII in C
Setup eCommerce website for your startup | Guidelines
Replacing Characters within string in Python

Everything about ASCII in C

American Standard Code for Information Interchange(ASCII) is a standard of character encoding for electronic communication. ASCII codes are universally used as a way to represent text in computers, networking equipment, and other various types of devices like IoTs and HHDs, etc. 

Usually, ASCII codes are written in 8 bits binary notations in case of binary arithmetics to represent different characters including upper case and lowercase alphabets as well as special symbols.

To print the ASCII Code in C Programming language, you can use different ways.

  • Take a character from the user and print ASCII of it.
  • Print all ASCII values
  • Print ASCII values between some range.

1. Get Character from the user and print ASCII Value of that character

#include<stdio.h>
void main()
{
    int e;
    char character;
    clrscr();
    printf("\n Enter a character of your choice: ");
    scanf("%c",&character);
    e=character;
    printf("\n The ASCII value of the character you've entered is : %d",e);
    getch();
}

One thing you should always consider while playing with ASCII is that the ASCII values of all the characters will be between 0 and 255. That’s why we need to use a loop starting at 0 and iterating up to 255 to print all characters in range 0 to 255.

For example, the following is the ASCII Table that shows ASCII of different characters and their equivalent values in a different number systems.

Image Source: https://www.kindpng.com/

Below is a table for non-printable ASCII Characters.

Image Source: https://www.fpds.gov/

2. To print ASCII of all characters and symbols

#include <stdio.h>
void main()
{
  int e;
  for(e = 0; e <= 255; i++){
    printf("The ASCII value of %c = %d\n", e, e);
   }
  getch();	
}


At the point when value of e is 65, it will print
The ASCII value of A = 65

3. To Print ASCII of characters in the range, one shall go with the following idea.

#include <stdio.h>
void main()
{
  int e;
  for(e = 65; e <= 90; i++){
    printf("The ASCII value of %c = %d\n", e, e);
   }
  getch();	
}

To print UPPER CASE english alphabets.
#include <stdio.h>
void main()
{
  int e;
  for(e = 97; e <= 122; i++){
    printf("The ASCII value of %c = %d\n", e, e);
   }
  getch();	
}



To print lower case english alphabets.

Thanks for being with me up to this point. Please share if you’ve found this article interesting.

COVID-19 | Serious Lesson for Humanity

African countries are now imposing restrictions on visitors from European countries in a row as the majority of #COVID19 confirmed cases were found to be transported by travelers from Italy, Germany & other European countries.

Let’s not play blame game between nations and uplift conspiracy theories spread all around the world. There seems to be a race of powerful nations like the United States and China to adjust them in the new world order and probably be its leader which is very bad for the entire humanity and our existence on this planet.

There is no doubt that #Corona has flipped out the situation led by #Ebola epidemic in 2014 and is teaching us a powerful lesson that pandemics have nothing to do with ethnicity, geography or nationality. We are one!

Hello World! Thanks for saving us from Corona Virus.

Thinking of a difficult time that people have been experiencing in lockdown cities and countries around the world. The rest of the world needs to thank people of places like Wuhan, Hubei, Rome, Venice, Milan, Barcelona, Israel and some other cities for their role in saving the rest of the world from this outbreak.

It’s not that easy to be isolated in the home watching everything including regular job, business, commodities, stock market going down and counting a number of positive cases growing every day. It needs a lot of courage for the whole city to handle the scarcity of household products, health workers, medicines and test-kits at the same time. We’re just following some news updates or realizing pitfalls in our economy.

At the same time, they’re fighting a war against #coronavirus pandemic and are going through extraordinarily difficult situation created by it. Even funeral ceremonies are banned in Italy. Researchers, Health workers, and volunteers from around the globe fighting against #COVID19 are worth saluting. The whole world is behind them.

#WarAgainstCorona #LockNepalDown #LockDownNepal #SAARCFightsCorona #Wuhan #Hubei #China #Italy #Spain #Israel

Yoga, the science of discovering your true self since generations – Vedic Science

[I’m not a spiritual fellow. This is a random topic that I’m writing this article to improve my English in accordance with some of the learning from my late grandfather along with the help of internet-based self-learning.]

Chakras in Hinduism are like energy centers in the living organism. Chakras are like foam-lipped eddies of energy that reside in seven different areas traversing the spinal column. Mainly there are seven different chakras according to the spiritual science of Vedic culture. All these chakras are meeting points for different nearest and dearest organs and glands around them. These chakras are the main causes behind the praana function. Harm in chakra may distract you from your goal spiritually, mentally or from sound health. Below are the seven chakras.

Along with some meditations and following healthy daily nutrition and routines, Various Gems Stones and Special Rudraksha Garland are used in Vedic mythology.

In the image alongside, the outer side is a list of main chakras in the body. Inner is a list of some practices for your inner as well as outer wellbeing like knowing your self and loving your body. Yoga is a common practice among them around countries like Nepal and India since the yugas. With the ancient knowledge transferred from generation-to-generation since the inception of Pashupatinath in Nepal, we know what rudraksha’s significance is in the Hindu religion. Yoga is a pure science of your body that teaches you to know your ultimate self which we call as aatman. There are 8 limbs of yoga namely;

There are 8 limbs of yoga listed below:

  1. Yama (related to moral discipline)
  2. Niyama (related to observances)
  3. Asana (defines different postures and physical fitness)
  4. Pranayama (absolute science of breathing techniques)
  5. Pratyahara (sense mining not data mining somehow)
  6. Dharana (related to intense concentration)
  7. Dhyana (meditation practices)
  8. Samadhi (self-enlightenment)

Some spiritual gurus do say that MOKSHA is for aatma (i.e. soul) going above the sattva. Here sattva indicates pure knowledge of your self.

The 10 Yamas

  • Ahimsa or Non-injury
  • Satya or Truthfulness
  • Asteya or Nonstealing
  • Brahmacharya or Sexual Purity
  • Kshama or Patience
  • Dhriti or Steadfastness
  • Daya or Compassion
  • Arjava or Honesty
  • Mitahara or Moderate Diet
  • Saucha or Purity

The 10 Niyamas

  • Hri or Modesty
  • Santosha or Contentment
  • Dana or Charity
  • Astikya or Faith
  • Ishvarapujana or Worship of the Lord
  • Siddhanta Sravana or Scriptural Listening
  • Mati or Cognition
  • Vrata or Sacred Vows
  • Japa or Incantation
  • Tapas or Austerity

I’m just a Vedic science enthusiast and my field of specialty is Information Technology. I’ll try to update my knowledge if you find some misleading guff in my article. I’ll always be expecting some feedbacks from experts which I assume you’re probably. At last, I want to thank Sandeep Manudhane Sir for your teaching from my conscience.

I was utilizing my time by learning some self-help meditations. I hope it helps me to get ready to fight against Corona Virus as well. Haha!

Corona Virus Nepal Updates| Is Nepal Safe to Travel?

According to WHO, Latest figures on coronavirus outbreak shows that the worldwide number of infections reaches 87,614 as of March 3 and death toll climbed to 2,994.

Following is the latest map covering all the affected countries, deaths and successful recovery worldwide. All data are from WHO.

Following the risk assessment by WHO, which indicated Nepal among the top nations with a high chance of virus spreads, Nepal Government has given a sign that a promotional campaign for Nepal Tourism Year 2020 will be focused more on domestic tourism more than foreign tourists as a strategic move to fight against the Novel Corona Virus outbreak that is spreading throughout the world. Talking about Nepal, the confirmed case is only one though being a neighbor nation of China. The majority of tourists planning to visit Nepal started to raise questions on the current status of this novel disaster and Is Nepal safe to travel during the Novel Corona Virus outbreak? and so on. Below is the live chart highlighting Nepal. Nepal’s Current Status on Corona Disaster Extracted from open data platform by @DataSagar

Nepal’s Infected Number Data Live extracted from open data platform by @DataSagar

Data Shows that Nepal is quite lucky in case of #CoronaDisaster though being nearer than the Countries like Japan, United States of America, Israel and France etc. from China.

Real time data of Japan seems like it’s indicating Nepal should get prepared for such unpredictable and unavoidable situation. IT’s high chance of virus spread as Nepal and India are Celebrating mass people gathering Festival of Colors – Holi in the next week. Image by illionSo may help you to understand this well.

So, my conclusion is, Better go for Precaution than painful Cure. Small and growing economies like Nepal mayn’t be able to handle epidemics like this disastrous flu. Answer in my conclusion should be a big NO unless it’s of optimal importance than your own precious life.

Regarding the Traveler’s safety, the World Health Organization (WHO) recommends following some safety tips for everyone to follow.

Dhanyawad and Stay safe everyone! I’ll be expecting some feedback and share from your end as I’m planning to post something new every week in this blog where I was inactive since long. @DataSagar

New COVID-19 Test Kit Developed in Singapore

According to CNA news agency, new test kit has been developed recently in Singapore that is supposed to be quick in tracking the virus backed up with world class technology right from Asia.

Below is the official video from CNA. We’ll be updating you with more. Keep tracking #nCOVData

Replacing Characters within string in Python

Characters in Python are treated as strings of length one and often considered as sub-string. One can use string literal in python either by using single quote or double quote. For example using value “DataSagar” can be used as ‘DataSagar’. In an example shown below, string1 and string2 both way is possible.

string1 = 'Zero To Hero in Python DataSagar'
string2 = "Zero To Hero in Python DataSagar"

In case of replacing specific character in Python can be done by .replace(character_to_replace, replace_by) method.

string = "Zero To Hero in Python DataSagar"
print(string.replace(e,A))

Output: ZAro To HAro in Python DataSagar

Main thing to understand over here is that .replace() method can be used while string manipulation on the way but doesn’t change the original string. Printing the string again using print() method will give the original value.

print(string)

Output: Zero To Hero in Python DataSagar

To remove a character from string use .replace() method with underscore ” _” value inreplace_byparameter.

.replace(Z,_)

output: ero To Hero in Python DataSagar

To get all the lessons on what can be done with String in Python, Keep tracking #StringInPython in our blog.