#include <stdio.h> #include <stdlib.h> int main() { /* // question 1 int arr[10]; int i; for(i=0;i<=9;i++) { printf("Element %d: ",i+1); scanf("%d",&arr[i]); } for(i=0;i<=9;i++) { printf("Element %d: %d\n",i+1,arr[i]); }*/ /* // question 2 int arr[10]; int i; for(i=0;i<=9;i++) { printf("Element %d: ",i+1); scanf("%d",&arr[i]); } printf("Even numbers: "); for(i=0;i<=9;i++) { if(arr[i]%2==0) printf("%d ",arr[i]); } printf("\nOdd numbers: "); for(i=0;i<=9;i++) { if(arr[i]%2==1) printf("%d ",arr[i]); } */ // q3 int arr[10]; int i; for(i=0;i<=9;i++) { printf("Element %d: ",i+1); scanf("%d",&arr[i]); } int sum=0; for(i=0;i<=9;i++) { sum=sum+arr[i]; } printf("The sum of all elements is %d \n",sum); */ // Question 4 /* int arr[10]; int i; int evenCount=0, oddCount=0; for(i=0;i<=9;i++) { printf("Element %d: ",i+1); scanf("%d",&arr[i]); } for(i=0;i<=9;i++) { if(arr[i]%2==0) evenCount++; else oddCount++; } printf("The number of even elements is %d \n",evenCount); printf("The number of odd elements is %d \n",oddCount); */ return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter