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

Program 1

Uploaded by

abc696124
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)
36 views

Program 1

Uploaded by

abc696124
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/ 15

PROGRAM 1: To find the sum of two numbers.

#include<stdio.h>
int main()
{
int a,b,c;
printf("enter first number:\n");
scanf("%d",&a);
printf("enter second number:\n");
scanf("%d",&b);
c=a+b;
printf("c=%d",c);
return 0;
}

OUTPUT:
PROGRAM 2: To find the area of rectangle.
#include<stdio.h>
int main()
{
float l,b,a;
printf("enter length \n");
scanf("%f",&l);
printf("enter breadth \n");
scanf("%f",&b);
a=l*b;
printf("area is=%f", a);
}
OUTPUT:
PROGRAM 3: To find simple interest.
#include<stdio.h>
int main()
{
float p,t,r,si;
printf("enter principle \n");
scanf("%f",&p);
printf("enter time \n");
scanf("%f",&t);
printf("enter rate \n");
scanf("%f", &r);
si =(p*t*r)/100;
printf("simple interest is=%f", si);

OUTPUT:
PROGRAM 4: To find square of a number.
#include<stdio.h>
#include<math.h>
int main()
{
int a,b;
printf("enter a number:");
scanf("%d", &a);
b=sqrt(a);
printf(" square root is=%d", b);

OUTPUT
PROGRAM 5: To check pass or fail.

#include<stdio.h>
int main()
{
int m;
printf("enter any marks= \n");
scanf("%d", &m);
if(m>32)
{
printf("pass");
}
else
{
printf("fail");
}
return 0;
}

OUTPUT:
PROGRAM 6: To print the greatest number among 3.
#include <stdio.h>
int main()
{
int a,b,c;
printf("enter three numbers =\n");
scanf("%d %d %d", &a, &b, &c);
if (a>b&&a>c)
{
printf("greatest number is=%d", a);
}
else if(b>a&&b>c)
{
printf("greatest number is=%d", b);
}
else
printf("greatest number is=%d", c);
return 0;
}

OUTPUT:
PROGRAM 7: To enter full name and print it on screen.
#include<stdio.h>
int main()
{
char name[45];
puts("enter your name");
gets(name);
puts("your full name is \n");
puts(name);
}

OUTPUT:
PROGRAM 8: To input name age and salary and print it on the screen.
#include<stdio.h>
int main()
{
char name[50];
int age;
float salary;
printf("enter name");
gets(name);
printf("enter age:");
scanf("%d", &age);
printf("enter salary:");
scanf("%f", &salary);
printf("\n name =%s", name);
printf("\n age= %d \n salary=%.2f", age , salary);
return 0;
}

OUTPUT
PROGRAM 9: To calculate remainder and quotient and print it on the
screen.

#include <stdio.h>
int main()
{
int a, b, c, d;
printf("enter any two numbers: ");
scanf("%d %d", &a, &b);
c= a/b;
d=a%b;
printf("quotient is= %d", c);
printf("\nremainder is= %d", d);
return 0;
}

OUTPUT
PROGRAM 10: Write a program which reads time in seconds and convert it
into hour, minutes and seconds.

#include<stdio.h>
int main()
{
int ts, h, r, m, s;
printf("enter time in seconds");
scanf("%d", &ts);
h= ts/3600;
r=ts%3600;
m= r/60;
s= r%60;
printf("\n%d seconds, %d hours, %d minutes and %d seconds", ts, h, m, s);
return 0;
}

OUTPUT
PROGRAM 11: To calculate area of the circle.

#include <stdio.h>
int main()
{
float r,a;
printf("enter radius");
scanf("%f", &r);
a= 3.14*r*r;
printf("\narea=%.2f",a);
return 0;
}

OUTPUT
PROGRAM 12: To print positive number.

#include<stdio.h>
int main()
{
int a;
printf("\n enter a number:");
scanf("%d",&a);
if(a>=1)

printf("\n number is positive");


}

OUTPUT:
PROGRAM 13: To read marks of six subjects and calculate total marks and
percentage. Also award division based on following criteria.

#include<stdio.h>
int main()
{
int eng, comp, maths, phy, chem, nep, total;
float per;
printf("enter maarks for english, nepali, physics, chemistry, maths, computer:");
scanf("%d %d %d %d %d %d", &eng,&nep,&phy,&chem,&maths,&comp);
total= eng+comp+maths+phy+chem+nep;
printf("\ total marks= %d", total);
per= (float)total/5;
if(eng>=35 && nep>=35 && phy>=35 && chem>=35 && maths>=35 &&
comp>=35)
{
printf("\n percentage=%.2f", per);
if(per>=75)
printf("\n First Division");
else if(per>=45)
printf("\n Second Division");
else
printf("\n Third Division");
}
else
printf("\nyou failed");
}

OUTPUT:
PROGRAM 14: Write a program which reads any two integer values from
user and calculates difference and product using switch statements.
#include<stdio.h>
int main()
{
int a,b,c,ch;
printf("enter any two numbers:");
scanf("%d %d", &a, &b);
printf("\n1 sum");
printf("\n2 difference");
printf("\n3 product");
ab:
printf("\nenter your choice[1-3]=");
scanf("%d", &ch);
switch(ch)
{
case 1:c=a+b;
printf("sum of two numbers is= %d", c);
break;
case 2:c=a-b;
printf("difference of two numbers is= %d", c);
break;
case 3:c=a*b;
printf("product of two numbers is= %d", c);
break;
default:
printf("wrong choice. please enter again");
goto ab;
}
}
OUTPUT

You might also like