#include<stdio.h>
int main()
{
//DECLARATION
int a;
int b;
int c;
//INITIALIZATION
a=10;
b=20;
c=30;
//PRINT RESULT
printf("%d\n",a+b+c);
return 0;
}
RESULT: 60
EXAMPLE 2: ASCII VALUES
#include<stdio.h>
int main()
{
printf("Ascii value of 'A' is: %d\n",'A');
printf("Ascii value of '@' is: %d\n",'@');
return 0;
}
RESULT:
Ascii value of ‘A’ is: 64
Ascii value of ‘@’ is: 65
EXAMPLE 3:AVERAGE
#include<stdio.h>
int main()
{
double x,y,z,avg;
x=10;
y=20;
z=30;
avg=(x+y+z)/3;
printf("Average of x, y and z is: %lf\n",avg);
return 0;
}
RESULT:
Average of x, y and z is:20
EXAMPLE 4: Print “NIGERIA” without quotation sign by using ascii values.
[Use the given ascii values- N=78, I=73, G=71, E=69, R=82, I=73, A=65.]
#include<stdio.h>
int main()
{
printf("%c%c%c%c%c%c%c%c%c%c\n",66,97,110,103,108,97,100,101,115,104);
return 0;
}
RESULT:NIGERIA
EXAMPLE 5: Precession
MUSA got 65.00 on physics, 83.50 on mathematics, 85.75 on C programming and 67.50 on English.
Now write a program to calculate the average of his marks on 4 subjects and print it up to 2 digit after the decimal point.
[The result should look like: XX.XX]
#include<stdio.h>
int main()
{
double marksInPhysics,marksInMath,marksInC,marksInEng,avarage;
marksInPhysics = 65.00;
marksInMath = 83.50;
marksInC = 85.50;
marksInEng = 67.50;
avarage=(marksInPhysics + marksInMath + marksInC + marksInEng)/4;
printf("%.2lf\n",avarage);
return 0;
}
RESULT:
75.38
No comments:
Post a Comment