Week 1: Basic syntax, variables and data types


Today's topics:

  1. Input Output
  2. Data Types
  3. If Else
  4. If Else Ladder
  5. Nested If Else

Problem 1:

You need to print the lines given below in the same format as it is - “Recently I heard that you’ve achieved 95% marks in your exam. This is brilliant! I wish you’ll shine in your life! Good luck with all the barriers(/\) in your life.”

Solution:
  #include< stdio.h>

    int main()
    {
        printf("Recently I heard that you’ve achieved 95%% marks
          in your exam.\nThis is brilliant!\nI wish you’ll shine in
          your life!\n	Good luck with all the barriers(/\\) in your life.");

        return 0;
    }
                    

Probelm: 2

You need to take two integer values as input and show the summation, subtraction, multiplication and division in the given format below.

  For example:
  Inputs are 5 and 2
  Then you’ll give output as:
  5 + 2 = 7
  5 - 2 = 3
  5 * 2 = 10
  5 / 2 = 2.50
  Sample Input Sample Output
  5 2           5 + 2 = 7
                5 - 2 = 3
                5 * 2 = 10
                5 / 2 = 2.50
  10 3          10 + 3 = 13
                10 - 3 = 7
                10 * 3 = 30
                10 / 3 = 3.33

Solution:
  #include< stdio.h>

    int main()
    {
        int a,b,sum,sub,mul;
        scanf("%d",&a);
        scanf("%d",&b);
        sum = a+b;
        sub = a-b;
        mul = a*b;
        float div = a*1.0/b;
        printf("%d %d %d %.2f", sum,sub,mul,div);
        return 0;
    }
                    

Probelm: 3

You need to take one non-negative integer (0 or greater than 0) value as input and tell if it is even or odd. See the sample input and output for more clarification.

  Sample Input Sample Output
  10            even
  3             odd

Solution:
  #include< stdio.h>

  int main()
  {
      int a;
      scanf("%d",&a);
      if(a>=0)
      {
          if(a%2==0)
          {
              printf("even");
          }
          else
          {
              {
              printf("odd");
          }
          }
      }
      else
      {
          printf("Please enter a non-negative number!\nThank you.");
      }
      
      return 0;
  }
                    

Probelm: 4

You need to take one integer value as input and tell if the value is positive or negative or zero. See the sample input and output for more clarification.

  Sample Input Sample Output
  10            positive
  -50           negative
  0             zero

Solution:
  #include< stdio.h>

  int main()
  {
      int a;
      scanf("%d",&a);
      if(a>0)
      {
          printf("positive");
      }
      else if(a<0)
      {
          printf("negative");
      }
      else
      {
          printf("zero");
      }
      
      return 0;
  }
                    

Probelm: 5

Suppose your friend has told you that she will buy a Gucci Bag if she has 10 thousand taka or more. Otherwise if she has 5 thousand taka or more, she will buy a Levis Bag. Otherwise she will buy Something from New Market. She also told you that, if she could buy the Gucci bag and she has more than 20 thousand taka she will also buy a Gucci Belt. Now, if you know the amount of money she has, can you tell which item/items she will buy? See the sample input and output for more clarification.

  Input   Output
  20000   Gucci Bag
  6500    Levis Bag
  200     Something
  25400   Gucci Bag
          Gucci Belt

Solution:
  #include< stdio.h>

  int main()
  {
      int a;
      scanf("%d",&a);
      if(a>0)
      {
          printf("positive");
      }
      else if(a<0)
      {
          printf("negative");
      }
      else
      {
          printf("zero");
      }
      
      return 0;
  }
                    

Github link here

Click here to go the practice contest.


Problem: 1

  Problem Statement

  I know that you're loving practice days! So this task is for you. You need to print "I Love Practice" without the quotation marks. I know that you can do it!
  
  Input Format
  
  There is no input in this problem
  Output Format
  
  Output "I Love Practice"

  Sample Output 0
  
  I Love Practice

Solution:
  #include< stdio.h>

  int main()
  {
      printf("I Love Practice");

      return 0;
  }
                    

Problem: 2

  Problem Statement

  Take two integers A and B as input and output their summation.
  
  Input Format
  
  You will be given A and B separated by a space.
  Constraints
  
  -10^9 <= A,B <= 10^9
  Output Format
  
  Output their summation
  Sample Input 0
  
  2 3
  Sample Output 0
  
  5
  Sample Input 1
  
  -10 5
  Sample Output 1
  
  -5

Solution:
  #include< stdio.h>

  int main()
  {
      int a,b;
      scanf("%d %d",&a,&b);
      int ans;
      ans = a+b;
      printf("%d", ans);
  
      return 0;
  }
                    

Problem: 3

  Problem Statement

  I know and you also know that you love practice
  day so much. So this task is for you. You will
  be given a positive integer N, you need to print
  "I Love Practice" N times.
  
  Here positive integer means those integers that are greater than 0.
  
  Input Format
  
  You will be given a positive integer N.
  Constraints
  
  1 <= N <= 1000
  Output Format
  
  Output "I Love Practice" N times. Don't forget to put a new line after every line.
  Sample Input 0
  
  5
  Sample Output 0
  
  I Love Practice
  I Love Practice
  I Love Practice
  I Love Practice
  I Love Practice
  Sample Input 1
  
  2
  Sample Output 1
  
  I Love Practice
  I Love Practice

Solution:
  #include< stdio.h>

  int main()
  {
      int n;
      scanf("%d", &n);
      for (int i = 0; i 
                  
                

Problem: 4

  Problem Statement

  You've learned about variables, right?
  Now its time to practice them. You
  need to take an integer A, a very big
  integer B, a floating value C and a 
  character D as input and output them serially.
  
  Input Format
  
  First line will contain A
  Second line will contain B
  Third line will contain C
  Fourth line will contain D
  Constraints
  
  -10^9 <= A <= 10^9
  -10^18 <= B <= 10^18
  -10^9 <= C <= 10^9
  Output Format
  
  Output them serially and put a new line after
   each value. Output the floating value 2 points after decimal.
  Sample Input 0
  
  100
  1234567891234567
  23.5675
  A
  Sample Output 0
  
  100
  1234567891234567
  23.57
  A

Solution:
  #include< stdio.h>

  int main()
  {
      int n;
      long long b;
      float c;
      char d;
      scanf("%d %lld %f %c", &n, &b, &c, &d);
      
      printf("%d\n", n);
      printf("%lld\n", b);
      printf("%.2f\n", c);
      printf("%c\n", d);
      
  
      return 0;
  }
                    

Problem: 5

  Problem Statement

  You will be given a positive integer N, you
  need to print from 1 to N and besides the
  value, print Yes or No. Print Yes if the
  value is divisible by 5 and print No otherwise.
  
  Input Format
  
  Input will contain a positive integer N.
  Constraints
  
  1 <= N <= 1000
  Output Format
  
  Output as mentioned in the question. See
  the sample input output for more clarifications.
   Put a new line after every line.
  Sample Input 0
  
  10
  Sample Output 0
  
  1 No
  2 No
  3 No
  4 No
  5 Yes
  6 No
  7 No
  8 No
  9 No
  10 Yes


  Sample Input 1
  5

  Sample Output 1
  1 No
  2 No
  3 No
  4 No
  5 Yes

Solution:
  #include< stdio.h>

  int main()
  {
      int n;
      scanf("%d", &n);
      for (int i = 1; i <= n; i++)
      {
          if(i%5==0)
          {
              printf("%d Yes\n", i);
          }
          else
          {
              printf("%d No\n",i);
          }
      }
      
  
      return 0;
  }
                    

Github link here

Click to the below link and complete the assignment. Don't see the solution before!

Click here to go the assignment


Problem: 1

  Problem Statement

  Welcome to the "Panta Vat" assignment.
  In this task you just need to print
  the following lines as it is.
  
  Hello, world! I am learning C programming language. ^_^
  
  Programming is fun and challenging. /\/\/\
  
  I want to give my 100% dedication to learn!	
  I will succeed one day.
  Note: Here you will see 4 spaces in the last 
  line which is a tab, you need to print a tab there.
  
  Input Format
  
  There is no input
  Output Format
  
  Output the lines.
  Sample Output 0
  
  Hello, world! I am learning C programming language. ^_^
  Programming is fun and challenging. /\/\/\
  I want to give my 100% dedication to learn!    I will succeed one day.

Solution:
  #include< stdio.h>

    int main()
    {
        printf("Hello, world! I am learning C programming
         language. ^_^\nProgramming is fun and
          challenging. /\\/\\/\\\nI want to give
           my 100%% dedication to learn!\tI will
            succeed one day.");
    
        return 0;
    }
                    

Problem: 2

  Problem Statement

  You will be given two integers A and B.
   You need to give output their multiplication.
  
  Input Format
  
  Input will contain A and B
  Constraints
  
  -10^9 <= A,B <= 10^9
  Output Format
  
  Output the multiplication
  Sample Input 0
  10 50

  Sample Output 0
  500

  Sample Input 1
  10000000 10000000

  Sample Output 1
  100000000000000

  Sample Input 2
  -100 62

  Sample Output 2
  -6200

Solution:
  #include< stdio.h>

  int main()
  {
      long long a,b;
      scanf("%lld %lld",&a,&b);
      long long sum = a*b;
      printf("%lld", sum);
  
      return 0;
  }
                    

Problem: 3

  Problem Statement

  You will be given a non-negative integer N,
  you need to tell if this number is divisible
  by 3 or not. If it is divisible by 3 output
  "YES" otherwise output "NO" without the quotation mark.
  
  Input Format
  
  Input will contain N.
  Constraints
  
  0 <= N <= 10^9
  Output Format
  
  Output "YES" or "NO" without the quotation mark according to the question.

  Sample Input 0
  33

  Sample Output 0
  YES

  Sample Input 1
  29

  Sample Output 1
  NO

  Sample Input 2
  0

  Sample Output 2
  YES

Solution:
  #include< stdio.h>

  int main()
  {
      int a;
      scanf("%d",&a);
      if(a%3==0)
      {
          printf("YES");
      }
      else
      {
          printf("NO");
      }
      

      return 0;
  }
                    

Problem: 4

  Problem Statement

  You will be given a non-negative integer
   N, you need to print all numbers from 1
    to N that are divisible by both 3 and 7.
  
  Input Format
  
  Input will contain N.
  Constraints
  
  21 <= N <= 10000
  Output Format
  
  Output all numbers from 1 to N that are
  divisible by both 3 and 7. Don't forget
  to print a new line after every number.

  Sample Input 0
  30

  Sample Output 0
  21

  Sample Input 1
  50

  Sample Output 1
  21
  42

  Sample Input 2
  100

  Sample Output 2
  21
  42
  63
  84

Solution:
  #include< stdio.h>

  int main()
  {
      int a;
      scanf("%d",&a);
      for (int i = 1; i <= a; i++)
      {
          if(i%3==0 && i%7==0)
          {
              printf("%d\n",i);
          }
      }
  
      return 0;
  }
                    

Problem: 5

  Problem Statement

  Alisa and you have gone out for shopping, 
  and Alisa wants to buy a new pair of shoes 
  for Eid. She has enough money to buy 
  anything. However, Alisa will only buy 
  shoes if you also buy a pair. And you 
  will buy a pair of shoes if you can buy 
  a Punjabi. That means, everything is 
  depending on the Punjabi.
  
  You have decided that you will buy a 
  Punjabi only if you have more than 
  1000 Taka. After purchasing the Punjabi 
  the amount of your money will be 
  reduced by 1000. Suppose you have 
  1600 taka with you, after buying the 
  Punjabi you will have 600 taka left with you.
  
  Then you will only buy shoes if you have 
  500 Taka or more left with you. That 
  means, if you can't buy your Punjabi 
  you can't buy shoes.
  
  Now if I inform you the amount N Taka 
  that your mother will give you, can 
  you tell me what will happen next?
  
  If you buy a punjabi print "I will buy Punjabi".
  
  If you buy a pair of shoes print "I will buy new shoes"
  
  If Alisa buy a pair of shoes print "Alisa will buy new shoes"
  
  If no one can buy anything print "Bad luck!"
  
  Note: Don't forget to print new line after every line you print.
  
  Input Format
  
  Input will contain a non-negative integer N.
  Constraints
  
  1 <= N <= 2^31
  Output Format
  
  Output the events that will happen as asked in the question.
  Sample Input 0
  
  1000
  Sample Output 0
  
  Bad luck!
  Sample Input 1
  
  1450
  Sample Output 1
  
  I will buy Punjabi
  Sample Input 2
  
  1500
  Sample Output 2
  
  I will buy Punjabi
  I will buy new shoes
  Alisa will buy new shoes

Solution:
  #include< stdio.h>

  int main()
  {
    int a;
    scanf("%d",&a);
    
    if(a<1001)
    {
        printf("Bad luck!");
    }
    else if(a>=1500)
    {
        printf("I will buy Punjabi\nI will buy new shoes\nAlisa will buy new shoes\n");
    }
    else
    {
        printf("I will buy Punjabi");
    }
    
    return 0;
  }
                    

Github link here