1.1 Programs in The Class Sequential
1.1 Programs in The Class Sequential
1.1 Programs in The Class Sequential
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;
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;
}
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;
}