Month: September 2020

Coding Question 15

Write a C program to check a number  is prime or not. C C #include<stdio.h> int main(){int num,x,fl=0; printf(“n Enter the a Number: “);scanf(“%d”,&num); for(x=2;x<num;x++){if(num%x==0){fl=1;break;} }if(fl==0)printf(“n %d is Prime No.”,x);elseprintf(“n %d is not Prime No.”,x); }    

Coding Question 14

Write a program to print sum of three digits prime numbers. C C #include<stdio.h> int prime(int i){int x,fl=0; for(x=2;x<i;x++){if(i%x==0){fl=1;break;} }if(fl==0){printf(“n %d”,i);return i;}elsereturn 0;} int main(){int i,sum=0; for(i=100;i<1000;i++){sum=sum+prime(i);} printf(“n Sum of 3 digit Prime nos=%d”,sum);return 0; }  

Coding Question 13

Write a program to compute  e= 1+ 1/1! + 1/2! + 1/3! ….1/n! with accuracy of 0.001%. C C #include<stdio.h>int fact(int i){int fact=1,x;for(x=1;x<=i;x++){ fact=fact*x;}return fact;} int main(){int r,i,x;float sum=0.0; printf(“n Enter the range: “);scanf(“%d”,&r); for(i=0;i<=r;i++){x=fact(i);sum=sum + ((float)1/(float)x); } printf(“n Result=%.4f”,sum);return 0; }

Coding Question 12

Write a program to accept a number and find sum of its individual digits repeatedly till the result is a single digit. C C #include<stdio.h> int digit_sum(int sum){int temp,r,s=0;temp=sum; while(temp!=0){r=temp%10;s+=r;temp=temp/10;} return s;} int main(){int num,sum;printf(“n Enter a number: “);scanf(“%d”,&num); sum=digit_sum(num); while(sum%10!=sum){sum=digit_sum(sum);} printf(“n Sum=%d”,sum);return 0; }  

Coding Question 10

Write a program to check a number is palindrome or not.  C C #include<stdio.h> int main(){int num,temp,sum=0,r;printf(“n Enter a number: “);scanf(“%d”,&num); temp=num; while(num!=0){r=num%10;sum=sum*10+r;num=num/10; } printf(“n Reverse No. of %d= %d”,temp,sum); if(sum==temp)printf(“n %d is a pallindrome no.”,temp);elseprintf(“n %d is not a pallindrome no.”,temp); return 0; }

Coding Question 9

Write a program to find the sum of the digits of a number. C C #include<stdio.h> int main(){int num,temp,sum=0,r;printf(“n Enter a number: “);scanf(“%d”,&num); temp=num; while(num!=0){r=num%10;sum+=r;num=num/10; } printf(“n Sum of Digits of %d= %d”,temp,sum); return 0; }

Coding Question 7

Write a program in C to find the roots of a quardratic equation. Your program should print the imaginary roots in the form a+ib. C C #include<stdio.h>#include<math.h> int main(){int a,b,c; float x,root1,root2,real,img; printf(“n Enter the value of a: “);scanf(“%d”,&a);printf(“n Enter the value of b: “);scanf(“%d”,&b);printf(“n Enter the value of c: “);scanf(“%d”,&c); printf(“n The Equation is: …

Coding Question 7 Read More »

Coding Question 6

Write a program to generates all combinations of 1,2 and 3 using for loop. C C #include<stdio.h> int main(){int i,j,k,z=1; printf(“n All the combinations are as follows: “);for(i=1;i<=3;i++)for(j=1;j<=3;j++)for(k=1;k<=3;k++)printf(“n%02d. %d %d %d”,z++,i,j,k);return 0; }

Page 1 of 2
1 2