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

C PROGRAMMING LAB EXERCISE

The document contains a series of C programming exercises that demonstrate various programming concepts. Each exercise includes a code snippet that performs a specific task, such as calculating the sum of natural numbers, generating prime numbers, printing the Fibonacci series, creating a multiplication table, checking for Armstrong numbers, and printing patterns with stars and numbers. The exercises are designed to help learners practice and understand fundamental programming techniques.

Uploaded by

srinidhi.k2022
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

C PROGRAMMING LAB EXERCISE

The document contains a series of C programming exercises that demonstrate various programming concepts. Each exercise includes a code snippet that performs a specific task, such as calculating the sum of natural numbers, generating prime numbers, printing the Fibonacci series, creating a multiplication table, checking for Armstrong numbers, and printing patterns with stars and numbers. The exercises are designed to help learners practice and understand fundamental programming techniques.

Uploaded by

srinidhi.k2022
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

C PROGRAMMING LAB EXERCISE

Q1.
int main() {
int i,n,sum=0;
printf("Enter the range for sum of n natural numbers:\n");
scanf("%d",&n);
for (i=1;i<=n;i++){
sum+=i;
}
printf("the sum of first %d natural numbers is %d.",n,sum);

return 0;
}

Q2.
int main(){
int i,n,j;
printf("Enter the range for prime numbers:\n");
scanf("%d",&n);
for (i=2;i<=n;i++){
int c=0;
for (j=2;j<i;j++){
if(i%j==0){
c+=1;

}
}
if (c==0){
printf("%d\n",i);
}
}
}

Q3.
int main(){
int n,i,c,t1=0,t2=1;
printf("Enter the range for fibonacci series:\n");
scanf("%d",&n);
printf("%d\t%d\t",t1,t2);
for (i=1;i<=n-2;i++){
c=t1+t2;
t1=t2;
t2=c;
printf("%d\t",c);

}
}
Q4.
int main(){
int i,n;
printf("Enter the number for which u want multiplication table:");
scanf("%d",&n);
for (i=1;i<=10;i++){
printf("%dx%d=%d\n",i,n,i*n);
}
}

Q5.
int main(){
int i=0,n,sum=0;
printf("Enter the number:");
scanf("%d",&n);
int a=n;
while(a>0){
i=a%10;
sum=sum+i*i*i;
a=a/10;
}
if (n==sum){
printf("%d is an armstrong number.",n);
}
}

Q6.
int main(){
int i,j;
char k='*';
for (i=5;i>0;i--){
for (j=0;j<i;j++){
printf("%c",k);
}
printf("\n");
}
}
Q7.
int main(){
int i,j;
char k='*';
for (i=1;i<6;i++){
for (j=0;j<i;j++){
printf("%c",k);
}
printf("\n");
}
}

Q8.
int main(){
int i,j;
for (i=1;i<6;i++){
for (j=1;j<=i;j++){
printf("%d",j);
}
printf("\n");
}
}

Q9.
int main(){
int i,j,k,l,m;
for (i=1;i<=5;i++){
for (l=5;l>=i;l--){
printf(" ");
}
for (j=1;j<=i;j++){
printf("%d",j);
m=j;
}
for (k=m-1;k>=1;k--){
printf("%d",k);
}
printf("\n");
}
}

You might also like