This document discusses decision and loop control in C programming. It covers if, if-else, conditional operators, relational operators, logical operators, the conditional operator (? :) and various loops including while, do-while and for loops. Examples are provided to demonstrate the use of if/else, logical operators, conditional operators and while, do-while loops. Flowcharts are also included to illustrate program flow. The document is presented by Vinay Arora and covers basic conditional and loop control structures in C.
This page contains examples and source code on decision making in C programming (to choose a particular statement among many statements) and loops ( to perform repeated task ). To understand all the examples on this page, you should have knowledge of following topics:
if...else Statement
for Loop
while Loop
break and Continue Statement
switch...case
This page contains examples and source code on decision making in C programming (to choose a particular statement among many statements) and loops ( to perform repeated task ). To understand all the examples on this page, you should have knowledge of following topics:
if...else Statement
for Loop
while Loop
break and Continue Statement
switch...case
Programming is an essential skill if you seek a career in software development, or in other fields of Coding. This fundamental of programming course is the first in the specialization for Introduction to Programming in C, but its lessons extend to any language you might want to study. This is because programming is primarily about solving a set of problems and writing the algorithm.
This will explain different type of for loop, their syntax and working.
It is very small side to quickly demonstrate for loop.
It was developed to present in class as an Semester activity.
C program language tutorial for loop while loop do while loopSourav Ganguly
Hello friends I am Sourav Ganguly. This c programme (program) or programming (programing) language tutorial contain basic or basics and advance knowledge for beginner (beginer) or beginners (beginers) with examples including input with output and different types of question or questions and answer or answers. We may call this tutorial or tutorials as complete online youtube video or videos with software and power point or ppt presentation. In this series of tutorials you will learn about keyword, different rules for constructing variables, integer, real, character constant, data types, character set, normal and nested if else statement, if else or else if ladder, different types of for, while and do while loop, switch case statement, break, continue, goto, function declaration and calling with values and address or reference, scope, recursion, union, static, extern, one, two and three or multi dimensional array, pointer, string, library, structure, file opening and closing with copy then paste and write function.
Programming is an essential skill if you seek a career in software development, or in other fields of Coding. This fundamental of programming course is the first in the specialization for Introduction to Programming in C, but its lessons extend to any language you might want to study. This is because programming is primarily about solving a set of problems and writing the algorithm.
This will explain different type of for loop, their syntax and working.
It is very small side to quickly demonstrate for loop.
It was developed to present in class as an Semester activity.
C program language tutorial for loop while loop do while loopSourav Ganguly
Hello friends I am Sourav Ganguly. This c programme (program) or programming (programing) language tutorial contain basic or basics and advance knowledge for beginner (beginer) or beginners (beginers) with examples including input with output and different types of question or questions and answer or answers. We may call this tutorial or tutorials as complete online youtube video or videos with software and power point or ppt presentation. In this series of tutorials you will learn about keyword, different rules for constructing variables, integer, real, character constant, data types, character set, normal and nested if else statement, if else or else if ladder, different types of for, while and do while loop, switch case statement, break, continue, goto, function declaration and calling with values and address or reference, scope, recursion, union, static, extern, one, two and three or multi dimensional array, pointer, string, library, structure, file opening and closing with copy then paste and write function.
Logical Expressions in C/C++. Mistakes Made by ProfessionalsPVS-Studio
In programming, a logical expression is a language construct that is evaluated as true or false. Many books that teach programming "from scratch" discuss possible operations on logical expressions familiar to every beginner. In this article, I won't be talking about the AND operator having higher precedence than OR. Instead, I will talk about common mistakes that programmers make in simple conditional expressions consisting of no more than three operators, and show how you can check your code using truth tables. Mistakes described here are the ones made by the developers of such well-known projects as FreeBSD, Microsoft ChakraCore, Mozilla Thunderbird, LibreOffice, and many others.
Programing for problem solving ( airline reservation system)Home
The software we used for this project is Dev C++.
Dev-C++ is a free IDE for Windows that uses either MinGW or TDM-GCC as the underlying compiler.
Also, this software is quite handy as compared with others as a result used by beginners.
C lecture 3 control statements slideshareGagan Deep
Control Statement in C, Looping in C, Conditional and Unconditional Statements, For Loop, While Loop, Do-While Loop, C Programming, Examples : Visit us at www.rozyph.com
A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always need to include the header that // defines cin and cout; the header is called iostream.h #include <iostream.h>
int main() {
//variable declaration //read values input from user //computation and print output to user return 0; }
After you write a C++ program you compile it; that is, you run a program called compiler that checks whether the program follows the C++ syntax – if it finds errors, it lists them – If there are no errors, it translates the C++ program into a program in machine language which you can execute.
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docxeugeniadean34240
20145-5SumII_CSC407_assign1.html
CSC 407: Computer Systems II: 2015 Summer II, Assignment #1
Last Modified 2015 July 21Purpose:
To go over issues related to how the compiler and the linker
serve you, the programmer.
Computing
Please ssh into ctilinux1.cstcis.cti.depaul.edu, or use your own Linux machine.
Compiler optimization (45 Points)
Consider the following program.
/* q1.c
*/
#include <stdlib.h>
#include <stdio.h>
#define unsigned int uint
#define LENGTH ((uint) 512*64)
int initializeArray (uint len,
int* intArray
)
{
uint i;
for (i = 0; i < len; i++)
intArray[i] = (rand() % 64);
}
uint countAdjacent (int maxIndex,
int* intArray,
int direction
)
{
uint i;
uint sum = 0;
for (i = 0; i < maxIndex; i++)
if ( ( intArray[i] == (intArray[i+1] + direction) ) &&
( intArray[i] == (intArray[i+2] + 2*direction) )
)
sum++;
return(sum);
}
uint funkyFunction (uint len,
int* intArray
)
{
uint i;
uint sum = 0;
for (i = 0; i < len-1; i++)
if ( (i % 8) == 0x3 )
sum += 7*countAdjacent(len-2,intArray,+1);
else
sum += 17*countAdjacent(len-2,intArray,-1);
return(sum);
}
int main ()
{
int* intArray = (int*)calloc(LENGTH,sizeof(int));
initializeArray(LENGTH,intArray);
printf("funkyFunction() == %d\n",funkyFunction(LENGTH,intArray));
free(intArray);
return(EXIT_SUCCESS);
}
(8 Points) Compile it for profiling but with no extra optimization with:
$ gcc -o q1None -pg q1.c # Compiles q1.c to write q1None to make profile info
$ ./q1None # Runs q1None
$ gprof q1None # Gives profile info on q1None
Be sure to scroll all the way to the top of gprof output!
What are the number of self seconds taken by:
FunctionSelf secondsinitializeBigArray()__________countAdjaceent()__________funkyFunction()__________
(8 Points)
How did it do the operation (i % 8) == 0x3?
Was it done as a modulus (the same as an expensive division, but returns the remainder instead of the quotient) or something else?
Show the assembly language for this C code
using gdb to dissassemble
funkyFunction() of q1None.
Hint: do:
$ gdb q1None
. . .
(gdb) disass funkyFunction
Dump of assembler code for function funkyFunction:
. . .
and then look for the code that sets up the calls to countAdjacent().
The (i % 8) == 0x3 test is done before either countAdjacent() call.
(8 Points) Compile it for profiling but with optimization with:
$ gcc -o q1Compiler -O1 -pg q1.c # Compiles q1.c to write q1Compiler to make profile info
$ ./q1Compiler # Runs q1Compiler
$ gprof q1Compiler # Gives profile info on q1Compiler
What are the number of self seconds taken by:
FunctionSelf secondsinitializeBigArray()__________countAdjacent()__________funkyFunction()__________(8 Points) Use gdb to dissassemble countAdjacent() of both q1None and q1.
Detailing about basics of C language and its control structure for learning C Language for beginners. It covers looping statement , control statement etc.
Similar to C Prog. - Decision & Loop Controls (20)
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Dr. Vinod Kumar Kanvaria
Exploiting Artificial Intelligence for Empowering Researchers and Faculty,
International FDP on Fundamentals of Research in Social Sciences
at Integral University, Lucknow, 06.06.2024
By Dr. Vinod Kumar Kanvaria
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
Normal Labour/ Stages of Labour/ Mechanism of LabourWasim Ak
Normal labor is also termed spontaneous labor, defined as the natural physiological process through which the fetus, placenta, and membranes are expelled from the uterus through the birth canal at term (37 to 42 weeks
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
22. && - Logical AND
C allows usage of three logical operators, namely, &&, || and !
These are to be read as ‘AND’ ‘OR’ and ‘NOT’ respectively.
Don’t use the single symbol | and &. These single symbols also have a
meaning.
The first two operators, && and ||, allow two or more conditions to be
combined in an if statement.
Vinay Arora
CSED
29. ! - Logical NOT
This operator reverses the result of the expression it operates on.
For example, if the expression evaluates to a non-zero value, then
applying ! operator to it results into a 0.
Vice versa, if the expression evaluates to zero then on applying !
operator to it makes it 1, a non-zero value.
Vinay Arora
CSED
34. ? : - Conditional Operator
The conditional operators ? and : are sometimes called Ternary
Operators since they take three arguments.
They form a kind of foreshortened if-then-else.
Their general form is, expression 1 ? expression 2 : expression 3
If expression 1 is true (that is, if its value is non-zero), then the value
returned will be expression 2, otherwise the value returned will be
expression 3.
Vinay Arora
CSED
38. goto Statement
goto is used to switch the control flow.
In a difficult programming situation it seems so easy to use a goto to
take the control.
In most of the scenarios use of goto is depreciated.
goto can be replaced by if-else, switch, for.
Vinay Arora
CSED
42. switch Statement
The control statement that allows us to make a decision from the number
of choices is called a switch.
The integer expression following the keyword switch is any C expression that
will yield an integer value.
Vinay Arora
CSED
47. Loops
Repetitive instructions is done through a Loop control instruction.
This involves repeating some portion of the program either a
specified number of times or until a particular condition is being
satisfied.
There are three methods by way of which we can repeat a part of a
program. They are:
(a) Using a while statement
(b) Using a do-while statement
(c) Using a for statement
Vinay Arora
CSED
55. While Loop – Program 2
//Program to demonstrate simple while loop with decrement operator
#include<stdio.h>
#include<conio.h>
void main()
{
int i=5;
clrscr();
while (i>=1)
{
printf("%dn",i);
i=i-1;
}
getch();
}
Vinay Arora
CSED
57. While Loop – Program 3
/* Program to demonstrate simple while loop taking incremental value
as float */
#include<stdio.h>
#include<conio.h>
void main()
{
float i=10.0;
clrscr();
while (i<=10.5)
{
printf("nCivil Engineering at Thapar");
i=i+.1;
}
getch();
}
Vinay Arora
CSED
59. While Loop – Program 4
//Demonstrating simple while loop with integer value out of range
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
while (i<=32767)
{
printf("%dn",i);
i=i+1;
}
getch();
}
Vinay Arora
CSED
63. While Loop – Program 6
//Program to demonstrate post increment operator in while loop
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
while (i<=10)
{
printf("%dn",i);
i=i++;
}
getch();
}
Vinay Arora
CSED
65. While Loop – Program 7
//Program to demonstrate compound assignment operator within while loop
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
while (i<=5)
{
printf("%dn",i);
i+=1;
}
getch();
}
Vinay Arora
CSED
67. While Loop – Program 8
//Program to demonstrate post increment operator with while loop
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0;
clrscr();
while (i++ < 5)
{
printf("%dn",i);
}
getch();
}
Vinay Arora
CSED
69. While Loop – Program 9
//Program to find out even numbers between 1-10
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
while (i<=10)
{
if (i%2==0)
printf("%dn",i);
i=i+1;
}
getch();
}
Vinay Arora
CSED
72. Do-while Loop – Program 10
//Program to demonstrate DO-WHILE loop
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
/*
while(i<1)
{
printf("hello i am at Thapar");
}
*/
do
{
printf("hello i am at Thapar");
}
while(i<1);
getch();
}
Vinay Arora
CSED
81. For Loop (Program-3)
//Program to demonstrate simple For loop
//Print numbers from 1 to 5
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
for (;i<=5;i=i+1)
{
printf("%dn",i);
}
getch();
}
Vinay Arora
CSED