Menus

Thursday, 2 April 2020

C Program to find largest element in an array

#include<stdio.h>

void main()
{

int arr[100],size,i,max,location;

printf("Enter the number of elements in an array : ");
scanf("%d",&size);

for(i=0;i<size;i++)
{
printf("Enter array value ");
scanf("%d",&arr[i]);
}


max= arr[0];

for(i=1;i<size;i++)
{
if(arr[i]>max)
{
max=arr[i];
location=i+1;
}
}

printf("Maximum element in location %d and its value is %d \n",location,max);


}




Wednesday, 1 April 2020

C Program to reverse the number


#include<stdio.h>

int reversenum(int n)
{

int rev=0,a;

while(n>0)
{
a=n%10;
n=n/10;
rev=rev*10+a;
}

return rev;


}


void main()
{

int n,rev;
printf("Enter the number : ");
scanf("%d",&n);

rev = reversenum(n);

printf("The reverse of the number is %d \n",rev);


}





Check whether a Number is Palindrome or Not - C Program


#include<stdio.h>

void main()
{

int n,m,a,r=0;

printf("Enter the number : ");
scanf("%d",&n);

m=n;

while(n>0)
{
a=n%10;
n=n/10;
r=r*10+a;
}


if(m==r)
 printf("%d is palindrome \n",m);
else
 printf("%d is not palindrome \n",m);

}




Tuesday, 31 March 2020

To check given number is armstrong number or not



#include<stdio.h>

void main()
{

int n,m,b=0,a;

printf("Enter the number ");
scanf("%d",&n);

m=n;

while(n>0)
{

a=n%10;
n=n/10;
b=b+(a*a*a);

}

if(m==b)
  printf("%d is amstrong\n",m);
else
  printf("%d is not amstrong\n",m);


}






Friday, 27 March 2020

Write C program to find factorial of a number


#include<stdio.h>

void main()
{


int n,fact;

printf("Enter the number ");
scanf("%d",&n);

fact=1;

while(n!=0)
{
fact = fact * n;
n--;
}

printf("Factorial of the nmber is %d\n",fact);


}





Thursday, 6 February 2020

Printing Pattern in C



#include<stdio.h>

void main()
{

int l,i,j;

printf("Enter number of lines");
scanf("%d",&l);

for(i=1;i<=l;i++)
{
   for(j=1;j<=i;j++)
   { 
printf(" *");
   }  

   printf("\n");

}

}








Thursday, 30 January 2020

Write c program to print multiplication table of a number


#include<stdio.h>

void main()
{

int n,i;

printf("Enter number ");
scanf("%d",&n);


for(i=1;i<=10;i++)
{

printf("%d * %d = %d\n",i,n,i*n);

}


}