0% found this document useful (0 votes)
3 views

Loop Programs

Uploaded by

lodhit567
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Loop Programs

Uploaded by

lodhit567
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

write a C program to display the number from 1 to 10

#include<stdio.h>
int main()
{
int i=1;
while(i<=10)
{
printf("%d \n",i);
}
return 0;
}

write a C program to display the sum of the number from 1 to 10

#include<stdio.h>
int main()
{
int i=1;
int sum=0;
while(i<=10)
{
sum=sum+i;
i++;
}
printf("the sum of number from 1 to 10 is %d",sum);

return 0;
}
write a C program to display the multiplication table entered by the user

#include<stdio.h>
int main()
{
int num;
int i=1;

printf("enter the table you want to display");


scanf("%d",&num);
while(i<=10)
{
printf("%d *%d=%d \n",num,i,num*i);
i++;
}
return 0;
}

write a C program to print the square of the number which take input by the user ?
#include<stdio.h>
int main()
{
int num;
int i=0;
int squ ;
printf("enter the number");
scanf("%d",&num);
while(i<=num)
{
squ=num*num;
i++;
}
printf(" the square of a number is =%d",squ);
return 0;
}

write a C program to print the factorial of a number which take input by the
user ?

#include<stdio.h>
int main()
{
int fact=1;
int i=1;
int num;
printf("enter the number for find factorial");
scanf("%d",&num);
while(i<=num)
{
fact =fact*i;
i++;
}
printf("the factorial of the number is %d",fact);
return 0;
}
-----------------------------------------------------------------------------------
----------------------------
Write a C program to Print the reverse of a number which is entered by the user?

#include<stdio.h>
void main()
{
int n,reverse = 0, remainder;
printf("Enter an integer: ");
scanf("%d", &n);
while (n>0)
{

remainder = n % 10;
reverse = reverse * 10 + remainder;
n /= 10;
}
printf("Reversed number = %d", reverse);

getch();
}

-----------------------------------------------------------------------------------
-----------------------------------
Write a C program to check whether a number is prime or not?

#include<stdio.h>
void main()
{
int n,i;
int count=0;
printf("enter the number");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
{
count++;
}
}
if (count==2)
{
printf("prime number");
}
else
{
printf("not prime number");
}
getch();
}
-----------------------------------------------------------------------------------
----------------------
Write a C program to print the Fibonacci series

Note - 0112358 is fibonocci series i.e number add and result is also add in
series

#include<stdio.h>
int main()
{
int n;
int a=0,b=1,c;
printf("enter the limit of the series");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
printf("%d \n",a);
c=a+b;
a=b;
b=c;

}
return 0;
}
-----------------------------------------------------------------------------------
-------------------------------
Write a C program to check a number is palindrome or not?

note-Ex-5225 reverse is also same 5225 is palindrome number

#include<stdio.h>

int main()
{
int n,temp,sum=0
printf("Enter an integer: ");
scanf("%d", &n);
temp=n;
while (n>0)
{
remainder = n % 10;
sum= sum * 10 + remainder;
n=n/ 10;
}
n=temp;
if(n==sum)
printf("pallindrome number");
else
printf("not pallindreome number");
}
return 0;
}
-----------------------------------------------------------------------------------
-------------------------------------
write a c program to check a number is armstrong or not?

#include<stdio.h>

int main()
{
int n,temp,sum=0
int cube;
printf("Enter an integer: ");

scanf("%d", &n);

temp=n;
while(n>0)
{
r=n%10;
cube=r*r*r;
sum=sum+cube;
n=n/10;
}
n=temp;
if(n==sum)
{
printf("given number is a Armstrong number");
}
else
{
printf("given number is a not a Armstrong number");

}
-----------------------------------------------------------------------------------
----------------------------

You might also like