0% found this document useful (0 votes)
91 views11 pages

Another One

The document contains 10 programming problems to solve in C language. Each problem is numbered and includes the problem statement and sample code to solve the problem. The problems cover a range of concepts in C including data types, operators, functions, loops, arrays, patterns, strings and more.

Uploaded by

Soumen Pathak
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)
91 views11 pages

Another One

The document contains 10 programming problems to solve in C language. Each problem is numbered and includes the problem statement and sample code to solve the problem. The problems cover a range of concepts in C including data types, operators, functions, loops, arrays, patterns, strings and more.

Uploaded by

Soumen Pathak
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/ 11

ASSIGNMENT-2

1 Write a C program to convert specificity days into days, weeks , years.


#include <stdio.h>

int main()

int days, years, weeks;

printf (“enter the number of days=\n”);

scanf(“%d”,&days);

years = days/365;

weeks = (days % 365)/7;

days = days- ((years*365) + (weeks*7));

printf(“years: %d\n”, years);

printf(“weeks: %d\n”, weeks);

printf(“days: %d \n”, days);

return 0;

2 Write a C program to calculate the distance between 2 points.

#include <stdio.h>

#include <math.h>

int main() {

int x1,x2,y1,y2 ;

printf(“enter the value of x1:\n”);


scanf (“%d”,&x1);

printf(“enter the value ofx2:\n”);

scanf (“%d”,&x2);

printf (“enter the value of y1:\n”);

scanf (“%d”,&y1);

printf (“enter the value of y2:\n”);

scanf (“%d”,&y2);

float d= sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));

printf (“distance between 2 points is %f\n”,d);

return 0;

3. Write a C program that reads 2 integer and checks they are multiplied or
not.
#include <stdio.h>

int main() {

int x,y;

printf (“enter the value of x:\n”);

scanf (“%d”,&x);

printf (“enter the value of y:\n”);

scanf (“%d”,&y);

if (x%y==0)

{ printf (“multiplied”);
}

else

{ printf (“not multiplied “);

return 0;

4 Write a c program that read 5 no. And count the no. Of positive no and
negative no.
#include <stdio.h>

int main() {

float numbers[5];

int j, p=0, n=0;

printf(“\ninput the first number: “);

scanf(“%f”, &numbers[0]);

printf(“\ninput the second number: “);

scanf(“%f”, &numbers[1]);

printf(“\ninput the third number: “);

scanf(“%f”, &numbers[2]);

printf(“\ninput the fourth number: “);

scanf(“%f”, &numbers[3]);

printf(“\ninput the fifth number: “);

scanf(“%f”, &numbers[4]);
for(j = 0; j < 5; j++) {

if(numbers[j] >0)

p++;

else if(numbers[j] < 0)

n++;

printf(“\nnumber of positive numbers: %d”, p);

printf(“\nnumber of negative numbers: %d”, n);

printf(“\n”);

return 0;

5 Write the program in C for following pattern

A] Pyramid of numbers of 4 rows


#include <stdio.h>

int main()

int i,j,spc,k,t=1;

spc=7;
for(i=1;i<=4;i++)

for(k=spc;k>=1;k--)

printf(“ “);

for(j=1;j<=i;j++)

printf(“%d “,t++);

printf(“\n”);

spc--;

return 0;

B] Code for binary Triangle


#include<stdio.h>

int main()

int i, j, rows; int count = 1;

printf(“enter the number of rows\n”); scanf(“%d”, &rows);

for (i = 0; i < rows; i++)

for (j = 0; j <= i; j++)

printf(“%d “, count); count = !count;

}
count = i % 2;

printf(“\n”);

return 0;

6 Write a c program to find a perfect no. Within the given no.

#include <stdio.h>

void main(){

int n,i,sum;

int mn,mx;

printf(“input the starting range or number : “);

scanf(“%d”,&mn);

printf(“input the ending range of number : “);

scanf(“%d”,&mx);

printf(“the perfect numbers within the given range : “);

for(n=mn;n<=mx;n++){

i=1;

sum = 0;

while(i<n){

if(n%i==0)

sum=sum+i;
i++;

if(sum==n)

printf(“%d “,n);

printf(“\n”);

7 Write a c program to find the amstrong no. For the given range of no.
#include <stdio.h>

void main(){

int num,r,sum,k;

int s,e;

printf(“input starting number of range: “);

scanf(“%d”,&s);

printf(“input ending number of range : “);

scanf(“%d”,&e);

printf(“armstrong numbers in given range are: “);

for(num=s;num<=e;num++){

k=num;

sum = 0;
while(k!=0){

r=k % 10;

k=k/10;

sum=sum+(r*r*r);

if(sum==num)

printf(“%d “,num);

printf(“\n”);

8 Write a program in c to display first n terms of Fibonacci series


#include<stdio.h>

void main()

int a=0,b=1,c,i,n;

printf(“input number of terms to display : “);

scanf(“%d”,&n);

printf(“here is the fibonacci series upto to %d terms : \n”,n);

printf(“% d % d”, a,b);

for(i=3;i<=n;i++)

c=a+b;

printf(“% d”,c);

a=b;
b=c;

printf(“\n”);

9 Write a program in c to cheak wether a no. Is palindrome or not


#include <stdio.h>

void main(){

int num,r,sum=0,t;

printf(“input a number: “);

scanf(“%d”,&num);

for(t=num;num!=0;num=num/10){

r=num % 10;

sum=sum*10+r;

if(t==sum)

printf(“%d is a palindrome number.\n”,t);

else

printf(“%d is not a palindrome number.\n”,t);

}
10 Write a program in c to display following pattern

BC

DEF

GHIJ
#include<stdio.h>

void main()

int i,j,k=1,n;

printf(“enter the no of lines\n”);

scanf(“%d”,&n);

for(i=1;i<=n;i++)

for(j=1;j<=i;j++,k++)

printf(“% c”,(char)(k+64));

printf(“\n”);

You might also like