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

C Program-1

The document contains 16 code snippets showing C programs for various tasks like: 1) Finding if a number is positive, negative or zero. 2) Finding if a number is even or odd. 3) Checking if a year is a leap year. 4) Finding grade based on entered marks. 5) Creating a simple calculator. 6) Drawing a pattern of increasing number of asterisks per row. 7) Adding numbers until the user enters zero.

Uploaded by

bhaveshvpatel81
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)
19 views

C Program-1

The document contains 16 code snippets showing C programs for various tasks like: 1) Finding if a number is positive, negative or zero. 2) Finding if a number is even or odd. 3) Checking if a year is a leap year. 4) Finding grade based on entered marks. 5) Creating a simple calculator. 6) Drawing a pattern of increasing number of asterisks per row. 7) Adding numbers until the user enters zero.

Uploaded by

bhaveshvpatel81
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
You are on page 1/ 4

10.

Wr i t e a p ro g r a m t o f i n d l a r g e s t n u m b e r f ro m t h r e e
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("Enter the number A: ");
scanf("%d", &A);
if (A > 0)
printf("%d is positive.", A);
else if (A < 0)
p r i n t f ( " % d i s n e ga t i v e . " , A ) ;
else if (A == 0)
p r i n t f ( " % d i s z e ro . " , A ) ;
getch();
}
11. Wr i t e a p ro g r a m t o f i n d o d d o r e v e n n u m b e r s
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("Enter the number: ");
scanf("%d", &a);
if (a % 2 == 0)
{
printf("The given number is EVEN");
}
else
{
printf("The given number is ODD");
}
getch();
}

12. Wr i t e a p ro g r a m t o f i n d l e a p y e a r
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
printf("Enter a year to check if it is a leap year \n");
scanf("%d", &year);
if ( year%400 == 0)
p r i n t f ( " % d i s a l e a p y e a r. \ n " , y e a r ) ;
else if ( year%100 == 0)
p r i n t f ( " % d i s n o t a l e a p y e a r. \ n " , y e a r ) ;
else if ( year%4 == 0 )
printf("%d is a leap year.\n", year);
else
printf("%d is not a leap year. \n", year);
getch();
}
13. Wr i t e a p r o g r a m t o s h o w g ra d e a c c o r d i n g t o m a r k s e n t e r e d
#include<stdio.h>
#include<conio.h>
void main()
{
int marks;
printf("Enter your marks ");
scanf("%d",&marks);
if(marks<0 || marks>100)
{
printf("Wrong Entry");
}
else if(marks<50)
{
printf("Grade F");
}
else if(marks>=50 && marks<60)
{
printf("Grade D");
}
else if(marks>=60 && marks<70)
{
printf("Grade C");
}
else if(marks>=70 && marks<80)
{
printf("Grade B");
}
else if(marks>=80 && marks<90)
{
printf("Grade A");
}
else
{
printf("Grade A+");
}
getch();
}
14. Wr i t e a P ro g r a m t o c r e a t e a s i m p l e c a l c u l a t o r
#include<stdio.h>
#include<conio.h>
void main()
{
c h a r o p e ra t i o n ;
double n1, n2;
p r i n t f ( " E n t e r a n o p e ra t o r ( + , - , * , / ) : " ) ;
scanf("%c", &operation);
p r i n t f ( " E n t e r t w o o p e ra n d s : " ) ;
scanf("%lf %lf",&n1, &n2);
s w i t c h ( o p e ra t i o n )
{
case '+':
printf("%.1lf + %.1lf = %.1lf",n1, n2, n1+n2);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf",n1, n2, n1-n2);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf",n1, n2, n1*n2);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf",n1, n2, n1/n2);
break;
default:
p r i n t f ( " E r ro r ! o p e ra t o r i s n o t c o r r e c t " ) ;
}
getch();
}
15. Draw this pattern
*
* *
* * *
* * * *
* * * * *
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i)
{
for (j = 1; j <= i; ++j)
{
printf("* ");
}
printf("\n");
}
getch();
}
16. Write a Program to add numbers until the user enters zero
#include<stdio.h>
#include<conio.h>
void main()
{
double number, sum = 0;
do
{
printf("Enter a number: ");
scanf("%lf", &number);
sum += number;
}
while(number != 0.0);
printf("Sum = %.2lf",sum);
getch();
}

You might also like