- ARRAY OPERATION :WHICH INCLUDES SUM OF ARRAY ,AVERAGE OF ARRAY, TOTAL EVEN NUMBER ,TOTAL ODD NUMBER OF ARRAY ,NEW VALUE TO ENTER IN ARRAY AND DISPLAY
*EXAMPLE*- Following is a code of array operation in c:-
INPUT:
//code written by www.techsayright.blogspot.com// #include<stdio.h> #include<conio.h> int a[10]; int sumc() { int sum=0; int i; for(i=0;i<=9;i++) { sum=sum+a[i]; } return sum; } void avg() { int sum=sumc(); printf("average value is %f",(float)sum/10); } void total_even() { int count=0; int i; for(i=0;i<=9;i++) { if(a[i]%2==0) count++; } printf("total even number=%d",count); } void total_odd() { int count=0; int i; for(i=0;i<=9;i++) { if(a[i]%2==1) count++; } printf("total odd number=%d",count); } void new_value() { int i; for(i=0;i<=9;i++) { printf("enter new value a[%d]",i); scanf("%d",&a[i]); } } void display() { int i; for(i=0;i<=9;i++) { printf("value at a[%d]=%d\n",i,a[i]); } } void main() { int choice,i,sum; clrscr(); for(i=0;i<=9;i++) { printf(" enter the value of =",i); scanf("%d",&a[i]); } do { printf("\n select from \n1-sum \n2-average \n3-total even \n4-total odd \n5-new value \n6-dispay \n7-exit \nenter your choice:"); scanf("%d",&choice); switch(choice) { case 1: int sum=sumc(); printf("sum of array=%d",sum); break; case 2: avg(); break; case 3: total_even(); break; case 4: total_odd(); break; case 5: new_value(); break; case 6: display(); break; case 7: break; default: printf("enter a valid choice"); } }while(choice!=7); getch(); } |
OUTPUT:
*happy coding*☺
Post a Comment
Hii