Showing posts with label if. Show all posts
Showing posts with label if. Show all posts

Descending an array using c programming

ARRANGE THE ELEMENTS IN ARRAY IN DESCENDING ORDER

main()
{
int a[100],i,n,j,search,temp;
printf("\n how many no's in array");
scanf("%d",&n);
printf("\n enter %d elements in array",n);
for(i=0;i
scanf("%d",&a[i]);
for(i=0;i
{
for(j=i+1;j
{
if(a[i]
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
printf("%4d",a[i]);
}
getch();
}

Add numbers using command line arguments (CLA)

Add numbers using command line arguments (CLA)

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

void main(int argc,char *argv[])
{
int sum=0,i;
//Compare if proper number of arguments have been entered
if(argc<3)

{
printf("Insufficient number of arguments:\n");
getch();
return 0;
}

//Add all the numbers entered using atoi function
for(i=1;i<argc;i++)
{
sum+=atoi(argv[i]);
}

//print the sum
printf("Ans=%d",sum);
getch();
}