Ca some one please help me with aC code to allow user enter
numbers from 1 to 20 without repeating and prnt the sum of
those numbers
thnx
Answers were Sorted based on User's Feedback
Answer / asadhsheriff
int main()
{
int a[20],i,j,count=0;
memset(a,0,20);
for(;count<=20;)
{
scanf("%d",&j);
if(a[j]==0)
{
count++;
a[j]=j;
}
}
i=20(10)/2;
printf("The sum is %d",i);
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / sanjay bhosale
/ Duplicate.cpp : main project file.
// Program : To find duplicate no in array by traversing it only once.
#include "stdafx.h"
#include<stdio.h>
#include<malloc.h>
using namespace System;
int main(array<System::String ^> ^args)
{
int *arr;
int val = 0;
int size = 0;
printf(" \n Enter the no of elements in array :");
scanf_s("%d",&size);
arr = (int *)malloc(sizeof(int)*size);
printf("\n Enter elements in the range 1 to %d:",size);
for(int i=0;i<size;i++)
{
scanf_s("%d",&val);
if(val<1 && val>=size)
{
printf("\n enter element again :\t");
i--;
}
else
*(arr+i) = val;
}
int sum = 0;
getchar();
printf("Array is :\n");
for(int i=0;i<size;i++)
{
printf("\t %d",arr[i]);
sum+= arr[i];
}
getchar();
printf("\n sum : %d",sum);
int diff = sum-(size*(size-1)/2.0);
printf(" Duplicate element is :%d\n",diff);
getchar();
return 0;
}
Might this help you........
| Is This Answer Correct ? | 0 Yes | 0 No |
printf("%d",(printf("Hello")); What it returns?
What is output of the following program ? main() { i = 1; printf("%d %d %d\n",i,i++,i++); }
Identify the correct argument for the function call fflush () in ANSI C: A)stdout B)stdin C)stderr D)All the above
Write a program to print the prime numbers from 1 to 100?
What is the difference function call by value & function call by reference?
What is structure data type in c?
How can we see the Expanded source code and compiled code for our source program in C?
please send me the code for multiplying sparse matrix using c
pgm to find number of words starting with capital letters in a file(additional memory usage not allowed)(if a word starting with capital also next letter in word is capital cann't be counted twice)
what is the difference between auto and static keywords
1 Answers cDot, College School Exams Tests, TCS,
What is difference between constant pointer and constant variable?
What are types of structure?