C Programming Tutorial

Advertisements

Write a program to double the even values and decrements odd values by 7 in C



       #include<stdio.h>
       #include<conio.h>
       void main()
       {
              int arr[5]; 
              int i;
              clrscr();

              for(i=0;i<5;i++)
              {
                 printf("Enter any number : "); 
                 scanf("%d",&arr[i]); 
              }
              
              printf("\nValues before modify : "); 
              for(i=0;i<5;i++)
              printf("%d, ",arr[i]); 

              for(i=0;i<5;i++)
              {
                     if(arr[i]%2 == 0)
                        arr[i] = arr[i] * 2;
                     else   
                        arr[i] = arr[i]  - 7;
              }
                            
              printf("\nValues after modify  : "); 
              for(i=0;i<5;i++)
              printf("%d, ",arr[i]); 

              getch();              
       }

   Output : 

              Enter any number : 78 
              Enter any number : 45 
              Enter any number : 63 
              Enter any number : 82 
              Enter any number : 56 

              Values before modify : 78, 45, 63, 82, 56,
              Values after modify  : 156, 38, 56, 164, 112,




Advertisement