Professional Documents
Culture Documents
• C&S helps for making the correct decisions among the many
available choices. It also helps to model prototypes and
simulators. C&S has been approved as a powerful tool for
scientific research. Due to very attractive benefits, the
computational and simulation has been technically accepted
across the globe. It has not only increased the efficiency of
scientific research but also made it faster and cheaper.
printf(“%d", z);
getchar();
return 0;
}
printf(“%d", z);
getchar();
return 0;
}
12
Dr. Muhammad Yousaf Hamza
#include <stdio.h>
int main( )
{
int x, y, z;
x = 5;
y = 7;
z = x + y;
getchar();
return 0;
}
Sum is 12Difference is -2
Dr. Muhammad Yousaf Hamza
#include <stdio.h>
int main( )
{
int x, y, z, m;
x = 5;
y = 7;
z = x + y;
m = x - y;
getchar();
return 0;
}
Sum is 12
Difference is -2
Dr. Muhammad Yousaf Hamza
#include <stdio.h>
int main( )
{
int x = 5, y = 7, z; // initialization with declaration
z = x + y;
printf(“%d", z);
getchar();
return 0;
}
x = x + 3;
printf(“%d\n", x); // 8
printf(“%d\n", x*6); // 48
printf(“%d\n", x); // 8
getchar();
return 0;
}
Dr. Muhammad Yousaf Hamza
Names of C Variables
• A good name for your variables is important
• Variables in C can be given any name made from numbers,
letters and underscores which is not a keyword and does
not begin with a number.
• Names may contain letters, digits and underscores
• The first character must be a letter or an underscore.
• First 31 characters are significant
(too long name is as bad as too short).
• Are case sensitive:
– abc is different from ABC
• Must begin with a letter or underscore and the rest can be
letters, digits, and underscores.
z = x + y;
printf("Sum is %d", z);
getchar();
getchar(); return 0;
} Dr. Muhammad Yousaf Hamza
Example
#include <stdio.h>
int main ()
{
float radius, area;
printf ("Enter the value of radius ");
scanf ( "%f", &radius);
getchar();
return 0;
} Dr. Muhammad Yousaf Hamza
Dr. Muhammad Yousaf Hamza
Arithmetic Operators
Operator Symbol Action
• && AND
• || OR
• ! NOT
int main()
{
printf("*");
getchar();
return 0;
}
int main()
{
printf("*\n*");
getchar();
return 0;
}
int main()
{
printf("*\n*\n*\n*\n*\n*\n*\n*\n*\n*");
getchar();
return 0;
}
int main()
{
printf("1\n2\n3\n4\n5\n6\n7\n8\n9\n10");
getchar();
return 0;
}
• for loop
• while loop
• do-while loop
I/P OA OA OA OA OA O/P
DCF1 DCF2 DCF20
80 km 80 km 80 km
while Loop
int main()
{
printf("*");
getchar();
return 0;
}
#include<stdio.h>
int main()
{
int i;
for (i = 0; i<10; i++)
printf("*");
getchar();
return 0;
}
Dr. Yousaf, PIEAS
Write a program that prints 10 stars in 2 Rows as
Efficient Solution?
Efficient Solution?
NESTED Loops
ﺗﮑرار
0.8
0.6
0.4
0.2
sine θ
-0.2
-0.4
-0.6
-0.8
-1
0 90 180 270 360 450 540 630 720
θ (degress)
END
of the course