C Language

C Language programs


1) write a c program to add two numbers.

#include<stdio.h>
void main()
{
int a,b,c;
printf("Enter the vales of a,b");
scanf("%d%d",&a,&b);
c=a+b;
printf("the value of c is %d",c);

}

output:




2)Write a c program to add digits of a given number.

#include<stdio.h>
void main()
{
int n,remainder,sum=0;
printf("Enter the number");
scanf("%d",&n);
while(n!=0)
{
remainder=n%10;
sum=sum+remainder;
n=n/10;
}
printf("the sum of %d is %d",n,sum);
}

Output:



3)Write a program to reverse the elements in the array.

#include<stdio.h>
void main()
{
int n,i,j,a[10],b[10];
printf("Enter the number of elements in array\n");
scanf("%d",&n);
printf("Enter the array elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=n-1,j=0;i>=0;i--,j++)
b[j]=a[i];
for(i=0;i<n;i++)
a[i]=b[i];
printf("Reverse array is\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}

output:


No comments:

Post a Comment

Live Traffic

Popular Posts

Designed By RAJESH GOWRABATHUNI