0% found this document useful (0 votes)
45 views5 pages

Lab Programs: To Find The Largest Among 2 No.S

The document contains C code for several basic programming exercises: finding the largest of two numbers, determining if a number is odd or even, finding the largest of three numbers, calculating the sum of natural numbers up to a given value N, calculating a student's percentage based on marks, printing natural numbers from 1 to N, determining a student's grade based on percentage, and printing a * pattern with a given number of rows. The programs demonstrate basic programming concepts like conditional statements, loops, functions, input/output operations.
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)
45 views5 pages

Lab Programs: To Find The Largest Among 2 No.S

The document contains C code for several basic programming exercises: finding the largest of two numbers, determining if a number is odd or even, finding the largest of three numbers, calculating the sum of natural numbers up to a given value N, calculating a student's percentage based on marks, printing natural numbers from 1 to N, determining a student's grade based on percentage, and printing a * pattern with a given number of rows. The programs demonstrate basic programming concepts like conditional statements, loops, functions, input/output operations.
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/ 5

INTRODUCTION TO PROGRAMMING LANGUAGE AND COMPUTER GRAPHICS

LAB PROGRAMS
• TO FIND THE LARGEST AMONG 2 NO.s

#include <stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf(“Enter a no. A);
scanf(“%d”,&a);
printf(“Enter a no. B);
scanf(“%d”,&b);

if(a>b)
printf(“A is greater than B”);

else
printf(“B is greater than A”);
get ch();
}
• TO FIND WHETHER THE NO. IS ODD OR EVEN

#include <stdio.h>
#include<conio.h>
void main()
{
int a;
printf(“Enter a no.);
scanf(“%d”,&a);

if(a%2==0);
printf(“Its an Even Number !”);
else
printf(“Its an Odd Number !”);
get ch();
}
• TO FIND LARGEST AMONG THREE NUMBERS

#include <stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf(“Enter a no. A);
scanf(“%d”,&a);
printf(“Enter a no. B);
scanf(“%d”,&b);

if(a>b)&& (a>c)
printf(“A is greater than B”);

else
if(b>a)&& (b>c)
printf(“B is greater than A & C”);
else
printf(“C is greater than A & B”);
get ch();
}
• TO FIND THE SUM OF N NATURAL No.s

#include <stdio.h>
#include<conio.h>
void main()
{
int n,i,sum=0;
printf(“Enter a no.);
scanf(“%d”,&n);
i=1;
while(i<=n);
{
sum+=i;
++i;
}
printf(“sum=%d”,sum);
get ch();
}
• TO FIND % OF A STUDENT OF GIVEN MARKS

#include <stdio.h>
#include<conio.h>
void main()
{
int gained,out,total;
printf(“Enter total marks gained in all subjects”);
scanf(“%d”,&gained);

printf(“Enter the total maximum marks”);


scanf(“%d”,&out);

total=gained/out*100;
printf(“Your percentage is %d”,total);

get ch();
}
• TO PRINT N NATURAL NUMBERS

#include <stdio.h>
#include<conio.h>
void main()
{
int i,n;
printf(“Enter a no.”);
scanf(“%d”,&i);
printf(“Natural No.s from 1 to %d : \n”,n);
for(i=1; i<=n; i++);
{
printf(“%d\n”,i);
}
get ch();
}
• TO FIND GRADE OF A STUDENT OF ITS GIVEN MARKS (USING NESTED IF ELSE METHOD)

#include <stdio.h>
#include<conio.h>
void main()
{
double p;
printf(“Enter your Percentage”);
scanf(“%f”,&p);

if(p<=100)
printf(“Your grade is A1”);
else
if(p<=90)
printf(“Your grade is A2”);
else
if(p<=80)
printf(“Your grade is B1”);
else
if(p<=70)
printf(“Your grade is B2”);

get ch();

}
• TO PRINT * 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 ”);
}
get ch();
}

You might also like