C Program to Perform Arithmetic Operations on Arrays

C Program to Perform Arithmetic Operations on Arrays

C program to perform arithmetic operations on arrays; Through this tutorial, we will learn how to perform arithmetic operations on arrays in c programs.

C Program to Perform Arithmetic Operations on Arrays

#include<stdio.h>
int main(){
   int size, i, A[50], B[50];
   int add[10], sub[10], mul[10], mod[10];
   float div[10];
   printf("enter array size:\n");
   scanf("%d", &size);
   printf("enter elements of 1st array:\n");
   for(i = 0; i < size; i++){
      scanf("%d", &A[i]);
   }
   printf("enter the elements of 2nd array:\n");
   for(i = 0; i < size; i ++){
      scanf("%d", &B[i]);
   }
   for(i = 0; i < size; i ++){
      add [i]= A[i] + B[i];
      sub [i]= A[i] - B[i];
      mul [i]= A[i] * B[i];
      div [i] = A[i] / B[i];
      mod [i] = A[i] % B[i];
   }
   printf("\n add\t sub\t Mul\t Div\t Mod\n");
   printf("------------------------------------\n");
   for(i = 0; i <size; i++){
      printf("\n%d\t ", add[i]);
      printf("%d \t ", sub[i]);
      printf("%d \t ", mul[i]);
      printf("%.2f\t ", div[i]);
      printf("%d \t ", mod[i]);
   }
   return 0;
}

The Output of the above c program; as follows:

enter array size:
5
enter elements of 1st array:
1 2 3 4 5
enter the elements of 2nd array:
1 2 3 4 5
add	 sub	 Mul	 Div	 Mod
------------------------------------

2	 0 	 1 	 1.00	 0 	 
4	 0 	 4 	 1.00	 0 	 
6	 0 	 9 	 1.00	 0 	 
8	 0 	 16 	 1.00	 0 	 
10	 0 	 25 	 1.00	 0 	 

Recommended C Programs

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *