1.Addition of two
numbers without using +
#include<stdio.h>
int main() {
int num1 = 10, num2 = 5;
num1 =
num1 - (-num2);
printf("Sum is : %d",num1);
return (0);
}
2.Max of three numbers using ternary
operator
Void main()
{
Int a=5,b=6,c=10,max;
Max=((a>b)&&(a>c)?a:((b>c)?b:c));
Printf(“Max is %d”,max);
Getch();
}
3.print the average of n numbers in the
array and pass array to function
#include<stdio.h>
void print(int a[10],int);
int main()
{
int
a[10],n=5;
print(a,n);
return
0;
}
void print(int a[10],int n)
{
int
i,sum=0;
for(i=0;i<n;i++)
{
printf("Enter
element into array");
scanf("%d",&a[i]);
sum=sum+a[i];
}
printf("Average
of array is %d",sum/n);
}
No comments:
Post a Comment