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

C Programs for Number Comparisons and Patterns

The document contains code snippets and explanations for 5 different C programming questions. Each question includes a flow chart, code sample, sample inputs, and sample outputs for programs that check the largest of 3 numbers, triangle type, triangle pattern printing, harmonic number series calculation, and palindrome checking.

Uploaded by

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

C Programs for Number Comparisons and Patterns

The document contains code snippets and explanations for 5 different C programming questions. Each question includes a flow chart, code sample, sample inputs, and sample outputs for programs that check the largest of 3 numbers, triangle type, triangle pattern printing, harmonic number series calculation, and palindrome checking.

Uploaded by

Jahid Mitul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Q1.

Flow chart:

Code:
#include<stdio.h>
int main()
{
int A, B, C;

printf("Enter the numbers A ");


scanf("%d", &A);
printf("Enter the numbers B");
scanf("%d",&B);
printf("Enter the numbers C");
scanf("%d",&C);

if (A >= B && A >= C)


printf("%d is the largest number.", A);

if (B >= A && B >= C)


printf("%d is the largest number.", B);

if (C >= A && C >= B)


printf("%d is the largest number.", C);

return 0;
}

Sample input:
A=8
B=10
C=5

Sample output:
Q2:
Flow chart:

Code:
#include <stdio.h>

int main()
{
float a, b, c, flag = 0;

printf("Enter values for a, b and c\n");


scanf("%f%f%f", &a, &b, &c);

if(a == b && b == c)
{
printf("It's an Equilateral Triangle\n");
}
else if(a == b || a == c || b == c)
{
printf("It's an Isosceles Triangle\n");
}
else
{
printf("It's a Scalene Triangle\n");
}

return 0;
}

Sample input:
A=10
B=30
C=20

Sample output:
Q3:
Flow chart:

Code:
#include <stdio.h>
void main()
{
int i,j,rows;
printf("Input number of rows : ");
scanf("%d",&rows);
for(i=1;i<=rows;i++)
{
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
}
}

Sample input:
4

Sample output:
Q4:
Flow chart:

Code:
#include <stdio.h>
void main()
{
int i,n;
float s=0.0;
printf("Input the number of terms : ");
scanf("%d",&n);
printf("\n\n");
for(i=1;i<=n;i++)
{
if(i<n)
{
printf("1/%d + ",i);
s+=1/(float)i;
}
if(i==n)
{
printf("1/%d ",i);
s+=1/(float)i;
}
}
printf("\nSum of Series upto %d terms : %f \n",n,s);
}

Sample input:
5

Sample output:
Q5:
Flow chart:

Code:
#include <stdio.h>

int main()
{
int n, num, rev = 0;

printf("Enter any number to check palindrome: ");


scanf("%d", &n);
num = n;
while(n != 0)
{
rev = (rev * 10) + (n % 10);
n /= 10;
}
if(rev == num)
{
printf("%d is palindrome.", num);
}
else
{
printf("%d is not palindrome.", num);
}

return 0;
}

Sample input:

Sample output:

You might also like