Posts

Structured Programming Language C: LU Mid-Term Exam - 2010

Question no. 1 What is Programming? Define Compiler. Write a program to calculate the following: F = a*b-b*c-c 2 *(b-1)/3 Which of the following are valid/invalid names for variables? If invalid, explain why? _abc 9abc A098 abc Write the difference between WHILE and DO-WHILE loop. Question no. 2 Write a for loop to print all the odd numbers from 122 to 10000. Write the output of the following code: int main() { int n=5, i, j; for(i=5; i>=1; i--) { for(j=1; j Given N, write a program to output the following: 1234...(N-1)N 1234...(N-1) ...... 12 1 Question no. 3 What is an Array? Why do we need array? Write a program to take 1000 numbers as input. Print the numbers in reverse order. Write a program to find MAXIMUM between 100 numbers. Question no. 4 Write a program to find MINIMUM between 2 numbers. Write a program, which will take MARK as input and show grade as output. Grading system: 80 or above A+ 70 or above A 60 or above A- Be...

C Program To Calculate The Of N Numbers Using Array

♣ Try it Out :: #include<stdio.h> #include<conio.h> main() { int Num[101], Sum = 0, TotalNum, i; printf("How many numbers you wish to add: "); scanf("%d", &TotalNum); printf("Enter %d Integers: ", TotalNum); for(i=0; i<TotalNum; i++) scanf("%d", &Num[i]); for(i=0; i<TotalNum; i++) Sum = Sum + Num[i]; printf("\nSum of entered numbers is = %d\n", Sum); getch(); return(0); } ♣ Output :: How many numbers you wish to add: 5 Enter 5 Integers: 125 10 25 30 450 Sum of entered numbers is = 640 ♣ Downloads :: Download source code Download executable file

C Program To Reverse An Array Using For Loop

♣ Try it Out :: #include<stdio.h> #include<conio.h> main() { int Arr[101], Num, i; printf("How many numbers you wish to input in array: "); scanf("%d", &Num); printf("Enter %d Integers:\n", Num); for(i=0; i<Num; i++) scanf("%d", &Arr[i]); printf("\nReverse Array is:\n"); for(i=Num-1; i>=0; i--) printf("%d ", Arr[i]); getch(); return(0); } ♣ Output :: How many numbers you wish to input in array: 5 Enter 5 Integers: 8 4 2 0 3 Reverse Array is: 3 0 2 4 8 ♣ Downloads :: Download source code Download executable file

C Program To Search A Number In Array

♣ Try it Out :: #include<stdio.h> #include<conio.h> main() { int Array[] = {9, 5, 2, 10, 6, 1}; int Size = sizeof(Array) / sizeof(int); int Search, i; printf("Entered array is: \n"); for(i=0; i<Size; i++) printf("%d ", Array[i]); printf("\nEnter the number to search: "); scanf("%d", &Search); for(i=0; i<Size; i++) if(Array[i] == Search) break; if(i == Size) printf("%d is not present in array. \n", Search); else printf("%d is present at location %d. \n", Search, i+1); getch(); return(0); } ♣ Output :: Entered array is: 9 5 2 10 6 1 Enter the number to search: 6 6 is present at location 5. ♣ Downloads :: Download source code Download executable file

C Program To Find Maximum Number In Array

♣ Try it Out :: #include<stdio.h> #include<conio.h> main() { int Array[100], MaxNum, Size, pos = 1, i; printf("How many numbers you wish to input in array: "); scanf("%d", &Size); printf("Enter %d integers: ", Size); for(i=0; i<Size; i++) scanf("%d", &Array[i]); MaxNum = Array[0]; for(i=1; i<Size; i++) { if(Array[i] > MaxNum) { MaxNum = Array[i]; pos = i + 1; } } printf("\nMaximum number is %d and it's position is %d.\n", MaxNum, pos); getch(); return(0); } ♣ Output :: How many numbers you wish to input in array: 5 Enter 5 integers: 40 25 30 125 5 Maximum number is 125 and it's position is 4. ♣ Downloads :: Download source code Download executable file

C Program To Find Minimum Number In Array

♣ Try it Out :: #include<stdio.h> #include<conio.h> main() { int Array[100], MinNum, Size, pos = 1, i; printf("How many numbers you wish to input in array: "); scanf("%d", &Size); printf("Enter %d integers: ", Size); for(i=0; i<Size; i++) scanf("%d", &Array[i]); MinNum = Array[0]; for(i=1; i<Size; i++) { if(Array[i] < MinNum) { MinNum = Array[i]; pos = i + 1; } } printf("\nMinimum number is %d and it's position is %d.\n", MinNum, pos); getch(); return(0); } ♣ Output :: How many numbers you wish to input in array: 5 Enter 5 integers: 122 10 55 36 21 Minimum number is 10 and it's position is 2. ♣ Downloads :: Download source code Download executable file

C Program To Insert An Element In An Array

♣ Try it Out :: #include<stdio.h> #include<conio.h> main() { int Arr[101], Value, Size, i, pos; printf("How many numbers you wish to input in array: "); scanf("%d", &Size); printf("Enter %d integers: \n", Size); for(i=0; i<Size; i++) scanf("%d", &Arr[i]); printf("\nEnter position where you wish to insert an element: "); scanf("%d", &pos); printf("Enter the value to insert: "); scanf("%d", &Value); for(i=Size-1; i>=pos-1; i--) Arr[i+1] = Arr[i]; Arr[pos-1] = Value; printf("\nResultant array is:\n"); for(i=0; i<=Size; i++) printf("%d ", Arr[i]); getch(); return(0); } ♣ Output :: How many numbers you wish to input in array: 5 Enter 5 integers: 4 2 3 9 7 Enter position where you wish to insert an element: 3 Enter the value to insert: 6 Resultant array is: 4...