Posts

Showing posts with the label Array

Multidimensional array in c

A multinational company has hired 3 sales persons for marketing/selling its 3 different products in Kathmandu .Each sales person sells each of these products. Write a c program to read number of each product sold by all sales-persons. Calculate total sells of each item and the total sells of each sales-person . Use array C Program source code #include <stdio.h> #include <conio.h> #include <string.h> int main() { int pro[3][3],sum=0; int j ,i ; char per[3][10]={ "first","second","third"}; for (i=0 ; i<3 ; i++) { for(j=0 ; j<3 ; j++) { printf("enter number of selling of %s person %s product:" , per[i] ,per[j] ); scanf("%d", &pro[i][j]); printf("\n"); } } for (i=0 ; i<3 ; i++) { for(j=0 ; j<3 ; j++) { sum = sum + pro[j][i]; } printf("Total sell of %s item is:%d\n",per[i], sum); sum=0; } for (i=0 ; i<3 ; i++)

c program to sort element of one dimensional array in ascending or descending order

c program to sort element of one dimensional array in ascending or descending order Write a program  to sort element of one dimensional array in ascending or descending order Ascending #include<stdio.h> #include<conio.h> int main() { int i,j,n,temp,a[1000]; printf("Enter the number of elements in the array:"); scanf("%d",&n); for(i=0; i<n; i++){ printf("Enter the %d elements of array:",i); scanf("%d",&a[i]); } for(i=0; i<n; i++) { for(j = i+1 ; j<n ; j++) { if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } printf("The sorted list in ascending order is:"); for(i=0; i<n; i++) printf("%d\n",a[i]); getch(); return 0; } Descending #include<stdio.h> #include<conio.h> int main() { int i,j,n,temp,a[1000]; printf("Enter the number of elements in the array:"); scanf("%d",&n); for(i=0; i<n; i++){ printf("Enter the %d elements of array:&qu