Square of odd numbers 1 Solution

Write a program to square each odd number in a list. The list is input by a sequence of comma-separated numbers. Suppose the following input is supplied to the program:

1,2,3,4,5,6,7,8,9

Then, the output should be:

1,9,25,49,81

Input Format

The input list is the sequence of comma-separated numbers

Constraints

No Constraints

Output Format

The output list is the sequence of comma separated numbers

Sample Input 0

1,2,3,4,5,6,7,8,9

Sample Output 0

1,9,25,49,81





Program :

 #include <stdio.h>

#include <string.h>

#include <math.h>

#include <stdlib.h>


int main() 

    {

        int a[100];

        int i;

        for(i=0;i<9;i++)

        {

            scanf("%d,",&a[i]);

            

        }

         for(i=0;i<9;i++)

         {

             if(a[i]%2==1&&a[i+1]%2==1)

                 printf("%d,",a[i]*a[i]);

             else if(a[i]%2==0&&a[i+1]%2==1)

                 printf(",");

             else if (a[i]%2==1)

                 printf("%d",a[i]*a[i]);

         }

}

Post a Comment

0 Comments