*** To Solve 1+2+3+.......+n write C prog code using different Loop.
USING FOR LOOP---------
#include
main()
{
int n,k,sum=0;
printf("Enter your number ");
scanf("%d",&n);
for(k=1;k<=n;k=k+1)
{
sum=sum+k;
}
printf("The result is %d",sum);
}
*** To Solve 1+2+3+.......+100 write C prog code using different Loop.
#include
main()
{
int k=1,sum=0;
for(k=1;k<=100;k=k+1)
{
sum=sum+k;
}
printf("the result is %d",sum);
}
*** Write C Prog Code To Find the LCM of two Integers.
#include
main()
{
int a,b,x;
printf("Enter the 1st number ");
scanf("%d",&a);
printf("Enter the 2nd number ");
scanf("%d",&b);
x=(a>b)?a:b;
tt:if(x%a==0&&x%b==0)
printf("The lcm is %d",x);
else
{
x=x+1;
goto tt;
}
}
*** Write C Prog Code To Find the LEAP YEAR.
#include
main()
{
int year;
printf("Enter year ");
scanf("%d",&year);
if(year%400==0||(year%100!=0&&year%4==0))
printf("%d is the leap year",year);
else
printf("%d is not the leap year",year);
}