Tuesday, August 28, 2018

INTERMEDIATE LEVEL PROGRAMS FOR C


PROGRAM TO PRINT ALTERNATE POSITION OF LETTERS IN UPPERCASE:

STATEMENT:

A str‌ing S (only alphabets) is passed as input. The printed output should contain alphabets in odd positions in each word in uppercase and alphabets in even positions in each word in lowercase.

PROGRAM:

#include <stdio.h>

int main()

{
   char input[100];

   fgets(input,100,stdin);


  char *ptr = input;

  int offset;

  char word[100];

     while(sscanf(ptr,"%s%n",word,&offset) == 1){

      int index=1;

      int wordLength=strlen(word);

      while(index <= wordLength){

          char charToPrint;

          if(index%2 != 0){

              charToPrint = toupper(word[index-1]);

          }else{

              charToPrint = tolower(word[index-1]);

          }

          printf("%c",charToPrint);

          index++;

      }

   
      printf(" "); //Space after each word.

      ptr+=offset;

  }
   
}

Input:
FLoweR iS beauTIFUL

Output:
FlOwEr Is BeAuTiFuL



PROGRAM TO ARRANGE THE ALPHABETS IN THE STRING IN DESCENDING ORDER:

STATEMENT:

A string (with only alphabets) S is passed as input. The program should print the alphabets in the string in descending order. Assume all alphabets will be in lower case.



PROGRAM;

#include<stdio.h>

#include<stdlib.h>

int main()
{
 
    char input[100];

    fgets(input,100,stdin);

    char *ptr = input;

    int present['z'];

    char ch='a';

    while(ch <= 'z')

    {

        present[ch] = 0;

        ch++;

    }

    //Now mark alphabets which are present.

    while(*ptr != '\0' && *ptr != '\n' && *ptr != '\r')
    {

        if(*ptr >= 'a' && *ptr <= 'z')
        {

            present[*ptr]=1;
        }


        ptr++;
    }

    //Now print in reverse order

    ch = 'z';

    while(ch >= 'a')
    {
        if(present[ch])

        {
            printf("%c",ch);
        }

        ch--;
    }


}

INPUT/OUTPUT:

If the input is "cake", the output should be "keca"
If the input is "innovation", the output should be "vtonia" (n or o or i should not be repeated)

Sunday, August 26, 2018

FEW MORE PYTHON SAMPLE PROGRAMS

PROGRAM TO PRINT THE PATTERN OF THE INPUT GIVEN:

STATEMENT:

The number of rows N is passed as the input. The program must print the half pyramid using the numbers from 1 to N.

PROGRAM:

N = int(input())
for ctr in range(1,N+1):
    for printnum in range (1, ctr+1):
        print (printnum, end=" ")
    print ("")


Input:
5

Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

PROGRAM TO COUNT THE COMMON CHARACTERS IN TWO STRINGS:

STATEMENT:

Two string values S1 and S2 are passed as input. The program must print the count of common characters in the strings S1 and S2. Assume the alphabets in S1 and S2 will be in lower case.

PROGRAM;

str1 = input().strip()
str2 = input().strip()
uniquechars = set(str1)
commoncount = 0
for ch in uniquechars:
    if ch in str2:
        commoncount+=1

print (commoncount)

Input:
energy
every

Output:
3

Explanation:
The common characters are e,r,y

Friday, August 24, 2018

SAMPLE PYTHON PROGRAMS FOR BEGINNERS

PROGRAM TO PRINT THE DIFFERENCE BETWEEN THE LENGTH OF THE RECTANGLES:

STATEMENT:

Alen and Tim both own a tennis grass court and they decide to mow the lawn in and around the court which will cost them Rs.5 per square feet. Given the amount they spent to mow the lawn and the width of the court, find the difference between the length of the courts.


PROGRAM:

amounts = input().strip().split(" ")
widths = input().strip().split(" ")
amountAlen = int(amounts[0])
amountTim = int(amounts[1])
widthAlen = int(widths[0])
widthTim = int(widths[1])
lengthAlen = amountAlen/(5*widthAlen)
lengthTim = amountTim/(5*widthTim)
diff = abs(lengthAlen-lengthTim)
print ("%.2f" %diff)

Input:
17500 40000
50 80

Output:
30.00

Explanation:
Area of Alen's court = 17500/5 = 3500 sq.ft. Length = 3500/50 = 70
Area of Tim's court = 40000/5 = 8000 sq.ft. Length = 8000/80 = 100
Hence the difference = 100-70 = 30.00


PROGRAM TO CONCATENATE STRING ALPHABETICALLY:

STATEMENT:

Two string values S1 and S2 are passed as the input. The program must concatenate them depending on which string comes first in the alphabetical order.

PROGRAM:

s1 = input().strip()
s2 = input().strip()
values = [s1,s2]
values.sort()
for s in values:
    print (s, end="")

Input:
zoo
tiger

Output:
tigerzoo



Wednesday, August 22, 2018

VERY SIMPLE PYTHON PROGRAMS FOR BEGINNERS


PROGRAM TO PRINT THE NUMBER OF CHOCOLATES REMAINING:

STATEMENT:

Drek distributes C chocolates to school N students every Friday. The C chocolates are distributed among N students equally and the remaining chocolates R are given back to Drek.

As an example if C=100 and N=40, each student receives 2 chocolates and the balance 100-40*2 = 20 is given back.
If C=205 and N=20, then each student receives 10 chocolates and the balance 205-20*10 = 5 is given back.

Help the school to calculate the chocolates to be given back when C and N are passed as input.


PROGRAM:

C = int(input())
N = int(input())
print (C%N)

Input:
300
45

Output:
30

PROGRAM TO PRINT SUM OF EVEN NUMBERS FROM M TO N:

STATEMENT:

Two numbers M and N are passed as the input. The program must print the sum of even numbers from M to N (inclusive of M and N).


PROGRAM;

M = int(input())
N = int(input())
evensum = 0
for num in range(M,N+1):
    if num%2 ==  0:
        evensum+=num

print (evensum)

Input:
2
11

Output:
30

Explanation:
The even numbers from 2 to 11 are 2 4 6 8 10
Their sum is 30.



Saturday, August 18, 2018

INTERMEDIATE JAVA PROGRAMS FOR LEARNERS


PROGRAM TO PRINT THE DAY OF A GIVEN DATE:

STATEMENT:

The day corresponding to the first date of a given month is provided as input to the program. Then a specific date D of the month is provided. The program must  print the day (one among MON,TUE, WED, THU, FRI, SAT, SUN) of the date D.

PROGRAM;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Hello {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String DAYS[] = new String[]{"SUN","MON","TUE","WED","THU","FRI","SAT"};
        List<String> DAYSLIST = Arrays.asList(DAYS);
        String dayone = sc.nextLine().trim();
        int date = sc.nextInt();
        int dayIndex = DAYSLIST.indexOf(dayone);
        for(int dateCounter=2; dateCounter <= date; dateCounter++){
            dayIndex++;
            if(dayIndex == 7){
                dayIndex=0;
            }
        }
     
        System.out.println(DAYS[dayIndex]);

    }

}

Input:
FRI
24

Output:
SUN

Explanation:
If it is Friday on 1st of the month, then 22nd will also be a Friday. Hence 24th of the month will be a Sunday. Hence SUN is printed.

REVERSE PATTERN PRINTING IN JAVA:

STATEMENT:

Based on the input value of N, the program must print the pattern described below.

Input Format:
First line will contain the value of N.

Output Format:
N lines will contain the number pattern as described below with each value separated by a single space.

PROGRAM::

import java.util.*;

public class Hello {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        for (int row = 1; row <= N; row++) {
            int printValue = N * (N + 1) / 2 - (row - 1);
            for (int col = 0; col < (N - row + 1); col++) {
                System.out.print(printValue+" ");
                printValue -= (N-col);
            }
            System.out.println("");
        }
    }

}

Input:
3

Output:
6 3 1
5 2
4

Monday, August 13, 2018

AVERAGE LEVEL JAVA PROGRAMS

PROGRAM TO ADD THE REVERSED NUMBER OF THE DATA:

STATEMENT:

A pair of numbers (X and Y) will be passed as input. The program must reverse the numbers and find the sum S. Then the sum S must be reversed and printed as output.

- If any leading zeroes are obtained while reversing any of the numerical values they should be discarded.


PROGRAM:

import java.util.*;

public class Hello {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int sum = reverse(x) + reverse(y);
        System.out.println(reverse(sum));

    }

    private static int reverse(int x) {
        StringBuilder sb = new StringBuilder(String.valueOf(x));
        return Integer.parseInt(sb.reverse().toString());
    }
}

Input:
305
794

Output:
1

Explanation:
305 and 794 when reversed are 503 and 497.
503+497 = 1000.
1000 when reversed is 1 which is printed as output.


PROGRAM TO PRINT THE NUMBER OF STEPS NEEDED TO FILL A CAN WITH WATER;

STATEMENT:

Two cans are with capacity X and Y liters. The program must determine the number of steps required to obtain exactly Z litres of liquid in one of the cans.
At the beginning both cans are empty. The following operations are counted as "steps".

- emptying a vessel,
- filling a vessel,
- pouring liquid from larger can to the smaller, without spilling, until one of the cans is either full or empty.

If it is not possible to obtain Z liters exactly then the output must be -1.

PROGRAM:

import java.util.*;

public class Hello {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        //Larger can is made as x
        if (x < y) {
            int temp = y;
            y = x;
            x = temp;
        }
        int fillCount = -1, currCount = 1; //currCount is made 1 to fill x
        boolean isSmallerCanFilled = false; //y will be the smaller can

        for (; x >= z; x -= y) {
            if (x == z) {
                fillCount = currCount;
                break;
            } else {
                if (isSmallerCanFilled) {
                    //We need to empty smaller can in step 1 and fill from larger can as step 2
                    currCount += 2;
                } else {
                    isSmallerCanFilled = true;
                    //Only filling from larger to smaller can as step 1. This happens only one time.
                    currCount += 1;
                }

            }
        }
        System.out.print(fillCount);
    }
}

Input:
5
2
3

Output:
2

Explanation:
Here X=5, Y=2
Step 1: Pour 5 liters of liquid into 5 liter can
Step 2: Pour 2 liters from 5 liter can into 2 liter can.
Now the 5 liter can will have 3 liters which is Z. Hence 2 steps are required.



Friday, August 10, 2018

JAVA PROGRAMS PART 3 FOR BEGINNERS

PROGRAM TO PRINT THE MONTH OF THE GIVEN DATA:

STATEMENT:


A date in DD-MM-YYYY format is passed as the input. The program must print the calendar month.
01 - January, 02 - February and so on till 12 - December.

PROGRAM;

import java.util.*;

public class Hello {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String months[] = {"January", "February", "March", "April", "May", "June", "July", "August",

"September", "October", "November", "December"};

        String dateInput = sc.nextLine();

        String DDMMYYYArray[] = dateInput.split("[-]");

        int month = Integer.parseInt(DDMMYYYArray[1]); //Second string is the month


        /* Subtract 1 as array index starts from zero */

        System.out.println(months[month - 1]);

    }
}

Input:
23-12-2016

Output:
December

 PROGRAM TO PRINT THE ODD INTEGERS IN A GIVEN NUMBER:

STATEMENT:

The program must accept two integers X and Y and print the odd integers between them.


STATEMENT:

import java.util.*;

public class Hello {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();

        int Y = sc.nextInt();

        int from = X, to = Y;

        while (++from < to) {

            if (from % 2 != 0) {

                System.out.print(from);

                System.out.print(" ");
            }
        }
    }
}

Input:
24
30

Output:
25 27 29

SIMPLE JAVA PROGRAMS PART 2 FOR BEGINNERS

PROGRAM TO PRINT GCF/HCF FOR THE GIVEN NUMBERS:

STATEMENT:

The program must accept two numbers X and Y and then print their HCF/GCD.

PROGRAM:


import java.util.*;

public class Hello {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();

        int Y = sc.nextInt();

        while (X != Y) {

            if (X > Y) {

                X = X - Y;

            } else {

                Y = Y - X;

            }

        }

        System.out.print(X);
    }
}


Input:
15
10

Output:
5

PROGRAM FIBONACCI SERIES IN JAVA:

STATEMENT:

An integer value N is passed as the input. The program must print the first N terms in the Fibonacci sequence.


PROGRAM:

import java.util.Scanner;

public class Hello {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();

        long prevTerm = 0,currentTerm = 1;

        int counter = 3;

        System.out.print(prevTerm+" "+currentTerm+" ");

                while (counter <= N) {

            System.out.print((prevTerm+currentTerm)+" ");

            currentTerm = prevTerm + currentTerm;

            prevTerm = currentTerm - prevTerm;

            counter++;
        }

    }
}

Input:
5

Output:
0 1 1 2 3

Tuesday, August 7, 2018

SIMPLE JAVA PROGRAMS FOR BEGINNERS

PROGRAM TO CALCULATE AVERAGE SPEED OF THE GIVEN NUMBERS:

STATEMENT:


A single line L with a set of space separated values indicating distance travelled and time taken is passed as the input. The program must calculate the average speed S (with precision upto 2 decimal places) and print S as the output.


PROGRAM:

import java.util.*;

public class Hello {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String input = sc.nextLine().trim();
        String distanceTimeArr[] = input.split("[ ]");
        double totalDistance = 0;
        double totalTime = 0;
        for (String distanceTime : distanceTimeArr) {
            String currDistanceTime[] = distanceTime.split("[@]");
            totalDistance += Integer.parseInt(currDistanceTime[0]);
            totalTime += Integer.parseInt(currDistanceTime[1]);
        }

        double avgSpeed = totalDistance / totalTime;
        System.out.format("%.2f kmph", avgSpeed);
    }
}

Input:
60@2 120@3

Output:
36.00 kmph

Explanation:
Total distance = 60+120 = 180 km.
Total time taken = 2+3 = 5 hours.
Hence average speed = 180/5 = 36.00 kmph

A WORD COUNT PROGRAM IN JAVA FOR STRINGS:

STATEMENT:

A string value S is passed as the input. The program must print the number of words in S.

PROGRAM:

import java.util.*;

public class Hello {

       public static void main(String[] args) {
   
       Scanner sc = new Scanner(System.in);

        String input = sc.nextLine();

        String words[] = input.split("[ ]");

        System.out.println(words.length);     
    }
}

Input:
She went to movie yesterday.

Output:
5

Saturday, August 4, 2018

C PROGRAM TO CREATE A ENCRYPTED FORMAT FOR THE GIVEN MESSAGE

STATEMENT;

Kate wants to encrypt the message M which is to be sent to his business partner Bharat. So he shifts every alphabet by X positions in forward direction and he adds Y to every number in the message.
Given a string value M of the message and the values of X and Y, the program must print the encrypted message E.

- All the alphabets will be in lower case.
- Spaces and special characters in the message M should be reproduced as such in the encrypted message E.

PROGRAM:

#include <stdio.h>

int main()
{

   char msg[100];

    fgets(msg,100,stdin);

    char *ptr = msg;

    int X,Y;

    scanf("%d%d",&X,&Y);

    char current;

    while(*ptr != '\r' && *ptr != '\n' && *ptr != '\0')
    {

        current = *ptr;

        if(isalpha(current))
        {

            char modified = current+X;

            if(modified - 'z' > 0)
            {

                char toprint = 'a'+ (modified-'z')-1;

                printf("%c",toprint);
            }
            else
            {

                printf("%c",modified);
            }

        }

        else if(isdigit(current))
        {

            int currentdigit = current - '0';

            printf("%d",currentdigit+Y);
        }
        else
        {

            printf("%c",current);
        }

        ptr++;
    }
}


Input:
credit 1 lakh
3
0

Output:
fuhglw 1 odnk

Thursday, August 2, 2018

C PROGRAM TO PRINT THE NEXT PALINDROME OF A NUMBER

STATEMENT;

Given a number N, the program must print the next palindromic number P.

PROGRAM:

#include <stdio.h>

int isPalindrome(const char* ptr);

int main()

{

int number;

scanf("%d",&number);

int counter=number+1;

char numberstring[15];

sprintf(numberstring,"%d",counter);

while(!isPalindrome(numberstring)){

        counter++;

        sprintf(numberstring,"%d",counter);

}


puts(numberstring);

}

int isPalindrome(const char* ptr)
{

const char *revptr = ptr + strlen(ptr) - 1;

while (ptr < revptr)

if (*revptr-- != *ptr++)

return 0;

return 1;
}


Input:
909

Output:
919

Monday, July 30, 2018

C PROGRAM TO ARRANGE THE GIVEN NUMBERS IN ORDER


STATEMENT:

A set of numbers of size N which are separated by one or more spaces will be passed as input. The program should print the prime numbers first followed by odd numbers and finally even numbers.
Each of these categories, prime numbers, odd numbers and even numbers must be sorted in ascending order among themselves. The numbers which are prime must be excluded from the list of odd and even numbers (In the case of even numbers only 2 is prime as well as even)

PROGRAM:

#include <stdio.h>
#include <math.h>

struct NumberItem
{
    int val;
    int alreadyprinted;
};

int isPrime(int num);

int main()
{
    char input[200];
    fgets(input,200,stdin);
    char *ptr = input;
    int offset=0;
    int currentNumber;

    int  N=0;
    while(sscanf(ptr,"%d%n",&currentNumber,&offset) == 1)
    {
        N++;
        ptr+=offset;
    }

    struct NumberItem values[N];

    int index=0;
    ptr = input;
    while(sscanf(ptr,"%d%n",&currentNumber,&offset) == 1)
    {
        values[index].val = currentNumber;
        values[index].alreadyprinted = 0;
        ptr+=offset;
        index++;
    }

    //Sort the numbers
    index = 0;
    while(index < N-1)
    {
        int compareindex=index+1;
        while(compareindex < N)
        {
            if(values[index].val > values[compareindex].val)
            {
                int temp = values[index].val;
                values[index].val = values[compareindex].val;
                values[compareindex].val = temp;
            }
            compareindex++;
        }
        index++;
    }


    //Now print prime
    index = 0;
    while(index < N)
    {
        if(isPrime(values[index].val))
        {
            printf("%d ",values[index].val);
            values[index].alreadyprinted = 1;
        }
        index++;
    }

    //Now print odd
    index = 0;
    while(index < N)
    {
        if(!values[index].alreadyprinted)
        {
            if(values[index].val%2 == 1)
            {
                printf("%d ",values[index].val);
                values[index].alreadyprinted = 1;
            }

        }

        index++;
    }


    //Now print even
    index = 0;
    while(index < N)
    {
        if(!values[index].alreadyprinted)
        {
            if(values[index].val%2 ==  0)
            {
                printf("%d ",values[index].val);
                values[index].alreadyprinted = 1;
            }

        }

        index++;
    }

}

int isPrime(int num)
{
    if(num < 2)
    {
        return 0;
    }

    if(num == 2)
    {
        return 1;
    }

    int  square_root = (int) sqrt((double)num);
    int counter=2;
    while(counter <= square_root)
    {
        if(num%counter == 0)
        {
            return 0;
        }

        counter++;
    }

    return 1;

}



Input:
611953 494147 493137 493133 493138

Output:
493133 494147 611953 493137 493138

Explanation:
493133 494147 611953 are prime numbers.

Saturday, July 28, 2018

C PROGRAM TO CREATE A STRONG PASSWORD FOR SECURITY PURPOSE


PROGRAM TO CREATE A STRONG PASSWORD FOR EMPLOYEE SECURITY:

STATEMENT:

a security committee decided to enforce the following rules when an employee creates/changes his/her password.
- The password must contain atleast one special character among # ! _ $ @
- The password must contain atleast two numbers
- The password must contain atleast one upper case alphabet and one lower case alphabet.
- The password must have a minimum length of 8.
- The password must have a maximum length of 25.

The program must accept a given password string P as input and check for these rules and output VALID or INVALID.

PROGRAM;

#include <stdio.h>

#include <regex.h>

int isValid(char *regex, char *inputpassword);

int main()
{
 
 char input[50];

    scanf("%s",input);


    char REGEX_SPECIAL[20] = "[#!_$@]+";

    char REGEX_NUMBERS[20] = ".*[0-9]+.*[0-9]+";

    char REGEX_SMALLER[20] = "[a-z]+";

    char REGEX_UPPER[20] = "[A-Z]+";

    int len = strlen(input);

    int INVALID=0;

    if(len < 8 || len > 25)
    {

        INVALID=1;
    }

    if(isInvalid(REGEX_SPECIAL,input))
    {

        INVALID=1;
    }



    if(isInvalid(REGEX_NUMBERS,input))
    {

        INVALID=1;
    }

    if(isInvalid(REGEX_SMALLER,input))
    {

        INVALID=1;
    }


    if(isInvalid(REGEX_UPPER,input))
    {

        INVALID=1;
    }


    if(INVALID)
    {

        printf("INVALID");
    }
    else
    {

        printf("VALID");
    }


}

int isInvalid(char *REGEX, char *inputpassword)
{

    regex_t reg;

    int regexcompileerror = regcomp(&reg, REGEX,REG_EXTENDED);

    if(regexcompileerror)

    {

        printf("Error in regex.");

        return 1;
    }


    if (regexec(&reg, inputpassword, 0, NULL, 0) == REG_NOMATCH)
    {

        return 1;

    }

    else
    {

        //Valid as matching the criteria

        return 0;
    }
}


Input:
m@d31nindia

Output:
INVALID

Explanation:
No alphabet in uppercase.

CREATING A SIMPLE GAME USING C PROGRAM


PROGRAM TO CREATE A GAME IN WHICH A BETTING GAME IS DEVELOPED BY ROLLING A DICE:


STATEMENT:

In a betting game involving the roll of a dice, Rupesh gains Rs.X if an odd number turns up and he loses Rs.Y is an even number turns up. The numbers shown on the face of the dice in a certain number of games is passed as input. The values of X and Y are also passed as input. The program must print the net gain or loss as the output.


PROGRAM:

#include <stdio.h>

int main()

{

char input[1000];

int gainAmount,lossAmount;

fgets(input,1000,stdin);
   
scanf("%d%d",&gainAmount,&lossAmount);

char* ptr=input;

int offset=0;

int currentDiceNumber;

    int finalAmount=0;
     
        while(sscanf(ptr,"%d%n",&currentDiceNumber,&offset) == 1)

        if(currentDiceNumber%2 == 1){

            finalAmount+=gainAmount;

        }else{

            finalAmount-=lossAmount;

        }

        ptr+=offset;


 
    printf("%d",finalAmount);

}


Input:
1 4 3
10
30

Output:
-10

Explanation:
He gains 20 rupees for 1 and 3 and loses 30 rupees for 4. Hence there is a net loss of 20-30 = -10

Tuesday, July 24, 2018

SIMPLE C PROGRAMMING PART 2 FOR BEGINNERS


PROGRAM TO CHECK WHETHER THE INPUT YEAR GIVEN IS A LEAP YEAR OR NOT;

STATEMENT:

A year Y will be passed as input. The program must find if the given year is a leap year or not.
- If it is leap year, the program must print yes else it should print no

PROGRAM:


#include<stdio.h>

#include <stdlib.h>

int main()

{

    int year;

    scanf("%d",&year);
 
    if(year%400 == 0){

        printf("yes");

    }

    else

    if(year%100 == 0){

        printf("no");

    }

    else

    if(year%4 == 0){

        printf("yes");

    }

    else

    {

        printf("no");

    }

}

 Input/Output:

If 2000 is the input, the program must print yes
If 2100 is the input, the program must print no
If 2013 is the input, the program must print no



PROGRAM TO CONVERT THE GIVEN RUPEE(INDIAN CURRENCY) TO PAISE:


STATEMENT:

A floating point value F indicating the amount in rupees is passed as input. The program must print the corresponding value in paise.

PROGRAM:


#include <stdio.h>

int main()

{
 
int rupee,paise;

    scanf("%d.%d",&rupee,&paise);

    int result = rupee*100 + paise;

    printf("%d",result);           

 
}

INPUT:

11.30

OUTPUT:

1130

Wednesday, July 18, 2018

CONTACT



CONTACT :


Feel free to contact us for any help and queries

Facebook

Instagram

Twitter

ABOUT



ABOUT

I am an engineering student along with  programming skills , I post various programs in different programming languages to get you skilled and solve different program and succeed in life.
MY HEARTY WISHES TO EVERYONE..
Feel free to contact me for any queries and information.:


PRIVACY POLICY


PRIVACY POLICY:
” We do not share personal information with third-parties nor do we store information we collect about your visit to this blog for use other than to analyze content performance through the use of cookies, which you can turn off at anytime by modifying your Internet browser’s settings. We are not responsible for the republishing of the content found on this blog on other Web sites or media without our permission. This privacy policy is subject to change without notice. “
Cookies : 
Cookies are files with small amount of data that is commonly used an anonymous unique identifier. These are sent to your browser from the website that you visit and are stored on your computer’s hard drive.
Our website uses these “cookies” to collection information and to improve our Service. You have the option to either accept or refuse these cookies, and know when a cookie is being sent to your computer. If you choose to refuse our cookies, you may not be able to use some portions of our Service.

Links to Other Sites
Our Service may contain links to other sites. If you click on a third-party link, you will be directed to that site. Note that these external sites are not operated by us. Therefore, we strongly advise you to review the Privacy Policy of these websites. We have no control over, and assume no responsibility for the content, privacy policies, or practices of any third-party sites or services.
Contact Us
If you have any questions or suggestions about our Privacy Policy, do not hesitate to contact us.

Tuesday, July 17, 2018

SIMPLE SAMPLE PROGRAMS FOR C BEGINNERS



SAMPLE PROGRAM -1

PROGRAM TO PRINT WHETHER THE INPUT GIVEN IS A SQUARE OR RECTANGLE:



STATEMENT:

The length L and breadth B of a rectangle is passed as input. If L is equal to B, the program must print SQUARE. Else the program must print RECTANGLE.

PROGRAM:

#include<stdio.h>

#include <stdlib.h>

int main()

{   

int length,breadth;   

scanf("%d%d",&length,&breadth);   

if(length == breadth)

{       

printf("SQUARE");   

}

else   

{       
printf("RECTANGLE"); 

  }

}

Input:
22
22

Output:

SQUARE



SAMPLE PROGRAM -2

PROGRAM TO PRINT THE REVERSE ORDER FROM 1 TO N:

STATEMENT:

A number N is passed as the input. The program must print the numbers from 1 to N with each number separated by a space.

PROGRAM;


#include <stdio.h>

int main()

{

    int X,Y;

    scanf("%d%d",&X,&Y);

    while(X!=Y)

    {

        if(X > Y)

        {

            X = X-Y;

        }

        else

        {

            Y = Y-X;

        }

    }

    /* You can also print Y as both X and Y will be equal at this step */
 
printf("%d",X);
}

Input:
10

Output:
1 2 3 4 5 6 7 8 9 10