PRACTICE EXAMPLE c
//write a program to check wheather the entered number is prime or not
#include<stdio.h>
int main(){
int n, flag=0, i;
printf("enter the number ");
scanf("%d", &n);
for(i=1; i<=n; i++) {
if(n%i==0){
flag++;
}
}
if(flag==2)
printf("prime number");
else
printf("not prime");
return 0;
}
//to find factorial
#include<stdio.h>
int main()
{
int n,i, fact=1;
printf(" enter the number :" );
scanf("%d", &n);
for(i=1; i<=n; i++) // matlab agar n humb]ne 3 dala tho n 1 se start ho ke 3 tak jaega fir niche fact mai jake faact jo 1 hai uske saath multiply hoga like fact= 1*1*2*3 = aise print hoga
{
fact= fact*i;
}
printf("factorial is %d", fact);
CASE WALA BAKI HAI programm 5th and 6th do
LAB 10A C PROGRAMMING NOTES .
#include<stdio.h>
int main(){
int n1, i, a=0,b=1, c;
printf("Enter the number :");
scanf("%d",&n1);
printf("%d ", a);
for(i=2; i<n1; i++)
{
c=a+b;
printf("%d \t",c);
a=b;
b=c;
}
return 0;
}
SUM OF FIRST N NATURAL NUMBERS IN FUNCTION
#include<stdio.h>
int sum(int n);
int main()
{
int n1;
printf("Enter a number");
scanf("%d",&n1);
sum(n1);
}
int sum(int n1 )
{
int i,x=0;
for(i=1; i<=n1; i++)
x=x+i;
printf("%d", x);
return 0;
}
No comments:
Post a Comment