1.1 Programs in The Class Sequential

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Practice all programs in your local machine or through online C compilers.

C Code Examples: https://www.programiz.com/c-programming/examples


Online C Compiler: https://www.programiz.com/c-programming/online-compiler/

SEQUENTIAL
Q1 Sum of 2 nos.
#include <stdio.h>
int main()
{
int a=10,b=20,c=0;
c=a+b;
printf("Sum of %d and %d is = %d",a,b,c); // %d is placeholder (int)
return 0;
}
Q.2 WAP to convert AED in INR where 1 AED = 22.54 INR
#include <stdio.h>
int main()
{
float aed, inr; //variable declaration
printf("\n Enter amount in AED:");
scanf("%f",&aed); // User input, %f placeholder (float)
inr=aed*22.74; // calculation
printf("\n Amount in INR = %f",inr); // output
return 0;
}
Q.3 WAP to convert AED into dollar
#include <stdio.h> // standarad input output header file
int main() // function
{
// body of main
float aed,dollar; // variable declaration
printf("\n Enter amount in AED");
scanf("%f",&aed); // input, %f placeholder, &aed = address of aed
dollar=aed/3.67;

printf("\n Dollar = %f", dollar); // printing result style 1


printf("\n %f / 3.67 = %f" , aed, dollar); // printing result style
printf("\n %f " , aed/3.67); // printing result style
return 0;
}

Or
#include <stdio.h> // standard input output header file
int main() // function
{ // body of main
float aed; // variable declaration
printf("\n Enter amount in AED");
scanf("%f",&aed); // input, %f placeholder, &aed = address of aed
printf("\n Dollar = %f", aed/3.67); // printing result style 1
printf("\n %f / 3.67 = %f" , aed, aed/3.67); // printing result style
return 0;
}
Q.4 WAP to print SI where principle,rate of interest and time are user input
#include <stdio.h>
int main()
{
float p,r,t,si; //variable declaration
printf("\n Enter principle, rate, time :");
scanf("%f %f %f",&p,&r, &t);// User input, %f placeholder (float)
si=(p*r*t)/100; // calculation
printf("\n Simple Interest = %f",si); // output
return 0;
}

Q.5 WAP to find your height in cm

#include <stdio.h> // pre porocessor directive


#define inch_to_cm 2.54
int main()
{
int feet,inch,cm; //variable declaration
printf("\n Enter height in feet and inches =");
scanf("%d %d",&feet,&inch);// User input, %f placeholder (float)
cm=(feet*12+inch)*inch_to_cm; // calculation
printf("\n Your height is = %d cm",cm); // output
return 0;
}

Q.6 WAP to find your age


#include <stdio.h> // pre processor directive
#define current 2023
int main()
{
int year,age; //variable declaration
printf("\n Enter year of birth =");
scanf("%d",&year);// User input, %f placeholder (float)
age=current-year; // calculation
printf("\n Your age is = %d years",age); // output
return 0;
}
Q.7 program to convert celcius to farenhite using (C × 9/5) + 32 = F
#include <stdio.h> // standarad input output header file
int main() // function
{ // body of main
float c,f; // variable declaration
printf("\n Enter temp in celcius");
scanf("%f",&c); // input, %f placeholder, &c = address of c
f=(c*9/5)+32;
printf("\n Temp in F = %f", f); // printing result style 1
printf("\n Temp in C= %f and in F= %f" , c, f); // printing result style
return 0;
}
Q.8 program to which takes min and hours as input, gives total minutes as output
#include <stdio.h> // standarad input output header file
int main() // function
{ // body of main
int m,h,t; // variable declaration
printf("\n Enter hours and minutes");
scanf("%d %d",&h, &m); // input, %d placeholder (int), & = address
t=h*60+m;
printf("\n Total min= %d", t); // printing result
return 0;
}
Q.9 WAP to print the third angel of a triangle if user inputs the remaining 2 angels.
/* program find the third angel of a triangle given remaining 2 angels */
#include <stdio.h> // standarad input output header file
#define triangle 180
int main() // function
{ // body of main
int a1,a2,a3; // variable declaration
printf("\n Enter angle 1 and 2 :");
scanf("%d %d",&a1, &a2); // input, %d placeholder (int), & = address
a3=triangle-(a1+a2);
printf("\n Angle 3= %d", a3); // printing result
return 0;
}
Q. 10 Swap two numbers using third variable
#include <stdio.h>
int main()
{
int a,b,c;
printf("\n Enter 2 num");
scanf("%d %d",&a, &b);
printf("\n Before swapping a= %d and b= %d",a,b);
c=a;
a=b;
b=c;
printf("\n After swapping a= %d and b= %d",a,b);
return 0;
}
Q.11 Swapping two numbers without using third variable
#include <stdio.h>

int main()
{
int a,b,c;
printf("\n Enter 2 num");
scanf("%d %d",&a, &b);
printf("\n Before swapping a= %d and b= %d",a,b); // a=5 b=10
a=a+b; // a=15 b=10
b=a-b; // a=15 b=5
a=a-b; // a=10 b=5
printf("\n After swapping a= %d and b= %d",a,b);

return 0;
}
Q.12 ASCII of any character
#include <stdio.h>

int main()
{
char a;
printf("\n Enter a character");
scanf("%c",&a);
printf("\n %d",a);
return 0;
}
Q.13 Pre increment
#include <stdio.h>
int main()
{
int a=5, b;
b=++a; //a=a+1 and then b=a (updated)
printf("\n The value of a : %d and b : %d",a,b); // a=6, b=6
return 0;
}
Q.14 Post Increment
#include <stdio.h>
int main()
{
int a=5, b;
b=a++; // b=a (old) and then a=a+1
printf("\n The value of a : %d and b : %d",a,b); // a=6, b=5
return 0;
}
Q.15 sizeof()
#include <stdio.h>
int main()
{
printf("\n char : %d", sizeof(char)); //1
printf("\n int :%d", sizeof(int)); //4
printf("\n long: %d", sizeof(long)); //8
printf("\n float :%d", sizeof(float)); //4
printf("\n double :%d", sizeof(double)); //8

return 0;
}
Q.16 Circumference and area of circle
#include <stdio.h>
#define pi 3.14 // constant
int main()
{
//float pi=3.14;
float r,c,a;
printf("\n Enter radius of circle ");
scanf("%f",&r);
a=pi*r*r;
c=2*pi*r;
printf("\n Area of circle = %f and Circumference=%f",a,c);
return 0;
}

All over programming in C


https://www.programiz.com/c-programming/examples

You might also like