34) Sample C Program to print prime numbers between 1 to 100.
# include <stdio.h>
# include <conio.h>
main( )
{
int n, i, check;
clrscr();
for(i = 1; i <= 100; i++)
{
check = 1;
for(n = 2; n <= i / 2; n++)
if(i % n == 0)
{
check = 0;
break;
}
if(check == 1)
printf("\n %d is a prime", i);
else
printf("\n %d is not a prime", i);
}
getch( );
}
35) Sample C Program to accept two numbers and print sum of two numbers by using functions.
# include <stdio.h>
# include <conio.h>
main( )
{
int a, b, c;
clrscr();
printf("Enter the value for a:")
scanf("%d",&a);
printf("Enter the value for b:")
scanf("%d",&b);
c = add(a, b);
printf("Sum of two numbers is %d",c);
getch( );
}
int add(int x, int y)
{
int z;
z = x + y;
return z;
}
36) Sample C Program to accept a number and find factorial of given number.
# include <stdio.h>
# include <conio.h>
main( )
{
int n, f;
clrscr( );
printf("Enter a number:")
scanf("%d",&n);
f = fact(n);
printf("Factorial value is %d",f);
getch();
}
int fact(int n)
{
int i, fa = 1;
for(i = n; i >= 1; i--)
fa = fa * i;
return fa;
}
Comments
Post a Comment
Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...
Experienced guys can share their resumes at admin@interview-made-easy.com